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_weightsWhether to automatically scale case weights.
availability_anyA flag indicating whether availability should be inferred from the data.
availability_ca_varAn idca variable or expression indicating if alternatives are available.
availability_co_varsA mapping giving idco expressions that evaluate to availability indicators.
availability_varchoice_anychoice_ca_varAn idca variable giving the choices as indicator values.
choice_co_codeAn idco variable giving the choices as alternative id's.
choice_co_varsA mapping giving idco expressions that evaluate to indicator values.
class_membership_modelcompute_engineconstraintsdashboardA simple attribute descriptor.
datadata_as_loadeddataflowsA simple attribute descriptor.
datasetData arrays as loaded for model computation.
datatreeA source for data for the model.
float_dtypeA simple attribute descriptor.
graphgroupididentGetter method for the ident property.
is_mangledlog_nanslogsum_parametermixturesmost_recent_estimation_resultA copy of the result dict from most recent likelihood maximization.
n_paramsorderingA simple attribute descriptor.
parameterspboundsA copy of the current min-max bounds of the parameters.
pfA DataFrame of the model parameters.
pholdfastAn array indicating which parameters are marked as holdfast.
pinitvalsAn array of the initial parameter values.
pmaximumAn array of the current parameter maximum values.
pminimumAn array of the current parameter minimum values.
pnamesAn array of the current parameter names.
pnullvalsAn array of the current parameter null values.
possible_overspecificationPossible overspecification of the model.
pstderrAn array of the current parameter standard errors.
pvalsAn array of the current parameter values.
quantity_caThe portion of the quantity function computed from idca data.
quantity_scalerename_parametersA simple attribute descriptor.
titleA simple attribute descriptor.
use_streamingutility_caThe portion of the utility function computed from idca data.
utility_coThe portion of the utility function computed from idco data.
weight_co_var