models/basic.py¶
pycmtensor.models.basic
¶
BaseModel(**kwargs)
¶
Bases: object
Basic model class object
Attributes:
Name | Type | Description |
---|---|---|
name |
str
|
name of the model |
config |
Config
|
pycmtensor config object |
rng |
Generator
|
random number generator |
params |
list
|
list of model parameters ( |
betas |
list
|
list of model scalar betas |
sigmas |
list
|
list of model scalar sigmas |
weights |
list
|
list of model weight matrices |
biases |
list
|
list of model vector biases |
updates |
list
|
list of (param, update) tuples |
learning_rate |
TensorVariable
|
symbolic reference to the learning rate |
results |
Results
|
stores the results of the model estimation |
get_weights()
¶
returns the values of the weights
Returns:
Type | Description |
---|---|
dict
|
weight values |
get_biases()
¶
returns the values of the biases
Returns:
Type | Description |
---|---|
dict
|
biases values |
get_betas()
¶
returns the values of the betas
Returns:
Type | Description |
---|---|
dict
|
beta values |
reset_values()
¶
resets the values of all parameters
include_params_for_convergence(*args, **kwargs)
¶
dummy method for additional parameter objects for calculating convergence
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
None
|
overloaded arguments |
()
|
**kwargs |
dict
|
overloaded keyword arguments |
{}
|
Returns:
Type | Description |
---|---|
OrderedDict
|
a dictonary of addition parameters to include |
include_regularization_terms(*regularizers)
¶
dummy method for additional regularizers into the cost function
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
None
|
overloaded arguments |
required |
Returns:
Type | Description |
---|---|
list[TensorVariable]
|
a list of symbolic variables that specify additional regualrizers to minimize against |
build_cost_updates_fn(updates)
¶
Builds a function that calculates the cost updates for a model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
updates |
dict
|
A dictionary of updates for the model. |
required |
Returns:
Type | Description |
---|---|
None |
predict(dataset)
¶
Make predictions on a given dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
The dataset on which predictions are to be made. |
required |
Returns:
Type | Description |
---|---|
dict
|
A dictionary containing the predicted choices, true choices, and choice probabilities |
dict
|
for each data point in the dataset. |
elasticities(dataset, wrt_choice)
¶
Calculate the elasticities of the model based on the given dataset and choice.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
dataset |
The dataset used to calculate the elasticities. |
required | |
wrt_choice |
The choice with respect to which the elasticities are calculated. |
required |
Returns:
Type | Description |
---|---|
The elasticities of the model based on the given dataset and choice. |
extract_params(cost, variables)
staticmethod
¶
Extracts Param objects from variables
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cost |
TensorVariable
|
function to evaluate |
required |
variables |
Union[dict, list]
|
list of variables from the current program |
required |
drop_unused_variables(cost, params, variables)
staticmethod
¶
Internal method to remove ununsed tensors
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cost |
TensorVariable
|
function to evaluate |
required |
params |
Param
|
param objects |
required |
variables |
dict
|
list of array variables from the dataset |
required |
Returns:
Type | Description |
---|---|
list
|
a list of param names which are not used in the model |
compute(model, ds, update=False, **params)
¶
Function for manual computation of model by specifying parameters as arguments
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
BaseModel
|
model to train |
required |
ds |
Dataset
|
dataset to use for training |
required |
update |
bool
|
if True, run |
False
|
**params |
dict
|
keyword arguments for model coefficients ( |
{}
|
Returns:
Name | Type | Description |
---|---|---|
dict |
model likelihood and error for training and validation datasets |
Example:
compute(model, ds, b_time=-5.009, b_purpose=0.307, asc_pt=-1.398, asc_drive=4.178,
asc_cycle=-3.996, b_car_own=1.4034)
train(model, ds, **kwargs)
¶
Main training loop
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model |
BaseModel
|
model to train |
required |
ds |
Dataset
|
dataset to use for training |
required |
**kwargs |
dict
|
overloaded keyword arguments. See configuration in the user guide for details on possible options |
{}
|