larch.LatentClass#
- class LatentClass(classmodel: ~larch.model.basemodel.BaseModel, choicemodels: dict[int, ~larch.model.basemodel.BaseModel], datatree: ~larch.dataset.DataTree | None = None, float_dtype: type = <class 'numpy.float32'>, **kwargs)[source]#
Bases:
BaseModel
,OptimizeMixin
,PanelMixin
- __init__(classmodel: ~larch.model.basemodel.BaseModel, choicemodels: dict[int, ~larch.model.basemodel.BaseModel], datatree: ~larch.dataset.DataTree | None = None, float_dtype: type = <class 'numpy.float32'>, **kwargs)[source]#
Initialize the latent class model structure.
This structure is used to connect two or more discrete classes, as well as a class membership model that determines the probability of each decision maker being a member of each class.
The estimation of latent class models cannot be done with the numba compute engine, and must be done with the jax compute engine.
- Parameters:
classmodel (BaseModel) – The class membership model.
choicemodels (dict) – A dictionary of choice models. The keys of this dictionary will be the altids of the choice models used in the class membership model.
datatree (DataTree, optional) – A DataTree to use for all submodels. For the choice models, this will override any existing datatree set on those models. For the class membership model, this will be used to set the datatree only if it is not already set, as it may be desirable in some situations to have the class membership model use a different datatree than the choice models.
float_dtype (type, optional) – The float type to use for the model. Defaults to np.float32.
Methods
__init__
(classmodel, choicemodels[, ...])Initialize the latent class model structure.
add_parameter_array
(name, values)availability_def
([new_def])Get or set the definition of the availability variable.
calculate_parameter_covariance
([pvals, robust])choice_def
([new_def])Get or set the definition of the choice variable.
clear_cache
()Remove all cached log likelihood values and estimation results.
d_loglike
([x, start_case, stop_case, ...])d_logloss
([x, start_case, stop_case, step_case])distribution_on_idca_variable
(x[, xlabel, ...])Generate a figure of observed and modeled choices over a range of variable values.
distribution_on_idco_variable
(x[, xlabel, ...])Generate a figure of variables over a range of variable values.
doctor
(**kwargs)Run diagnostics, checking for common problems and inconsistencies.
estimation_statistics
([compute_loglike_null])Create an XHTML summary of estimation statistics.
estimation_statistics_raw
([compute_loglike_null])Compile estimation statistics as a pandas Series.
from_dict
(content)get_param_loc
(name)Get the position of a named parameter.
get_value
(name, *[, default, kind])initialize_graph
([alternative_codes, ...])Write a nesting tree graph for a MNL model.
jax_maximize_loglike
([method, stderr, ...])jax_neg_d_loglike
(*args, **kwargs)jax_neg_loglike
(params)jax_param_cov
(params)load_data
(*args, **kwargs)No-op.
lock_value
([name, value])Set a fixed value for a model parameter.
loglike
([x, start_case, stop_case, ...])logloss
([x, start_case, stop_case, ...])mangle
([data, structure])maximize_loglike
(*args, **kwargs)Maximize the log likelihood.
neg_d_loglike
([x, start_case, stop_case, ...])neg_loglike
([x, start_case, stop_case, ...])parameter_summary
()Create a tabular summary of parameter values.
plock
([values])Lock the values of one or more parameters.
pretty_table
()reflow_data_arrays
()Reload the internal data_arrays so they are consistent with the datatree.
required_data
()Report what data is required in DataFrames for this model to be used.
robust_covariance
()save
(filename[, format, overwrite])set_cap
([cap])Set limiting values for one or more parameters.
set_value
(name[, value, initvalue, ...])Set the value one or more attributes of a single parameter.
set_values
([values])Set the parameter values for one or more parameters.
simple_fit_bhhh
(*args, **kwargs)swap_datatree
(tree[, should_mangle])Swap the current datatree with a new datatree.
total_weight
()Compute the total weight of cases in the loaded data.
unmangle
([force, structure_only])update_parameters
(x)utility_functions
([subset, resolve_parameters])Generate an XHTML output of the utility function(s).
Attributes
autoscale_weights
Whether to automatically scale case weights.
availability_any
A flag indicating whether availability should be inferred from the data.
availability_ca_var
An idca variable or expression indicating if alternatives are available.
availability_co_vars
A mapping giving idco expressions that evaluate to availability indicators.
availability_var
choice_any
choice_ca_var
An idca variable giving the choices as indicator values.
choice_co_code
An idco variable giving the choices as alternative id's.
choice_co_vars
A mapping giving idco expressions that evaluate to indicator values.
class_membership_model
compute_engine
constraints
dashboard
A simple attribute descriptor.
data
data_as_loaded
dataflows
A simple attribute descriptor.
dataset
Data arrays as loaded for model computation.
datatree
A source for data for the model.
float_dtype
A simple attribute descriptor.
graph
groupid
ident
Getter method for the ident property.
is_mangled
log_nans
logsum_parameter
mixtures
most_recent_estimation_result
A copy of the result dict from most recent likelihood maximization.
n_params
ordering
A simple attribute descriptor.
parameters
pbounds
A copy of the current min-max bounds of the parameters.
pf
A DataFrame of the model parameters.
pholdfast
An array indicating which parameters are marked as holdfast.
pinitvals
An array of the initial parameter values.
pmaximum
An array of the current parameter maximum values.
pminimum
An array of the current parameter minimum values.
pnames
An array of the current parameter names.
pnullvals
An array of the current parameter null values.
possible_overspecification
Possible overspecification of the model.
pstderr
An array of the current parameter standard errors.
pvals
An array of the current parameter values.
quantity_ca
The portion of the quantity function computed from idca data.
quantity_scale
rename_parameters
A simple attribute descriptor.
title
A simple attribute descriptor.
use_streaming
utility_ca
The portion of the utility function computed from idca data.
utility_co
The portion of the utility function computed from idco data.
weight_co_var