Model
Model module.
This module provides the class definition of the Model class, a dictionary-like collection of distributions to form a model.
Model
dataclass
Bases: dict
Dictionary-like collection of distributions to form a model.
self.keys() indexes the responses of the distributions in the collection; self.values() contain the individual distribution objects in the model, of type Distribution.
Attributes:
Name | Type | Description |
---|---|---|
response |
dict
|
dictionary with keys corresponding to the data values within state, and values corresponding to the desired predictor values within the data distributions (for storing fitted values). |
Source code in src/openmcmc/model.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|
conditional(param)
Return sub-model which consists of the subset of distributions dependent on the supplied parameter.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
param |
str
|
parameter to find within the model distributions. |
required |
Returns:
Type | Description |
---|---|
Model
|
model object containing only distributions which have a dependence on param. |
Source code in src/openmcmc/model.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
log_p(state)
Compute the log-probability density for the full model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
dict
|
dictionary with current state information. |
required |
Returns:
Type | Description |
---|---|
Union[float, ndarray]
|
POSITIVE log-probability density evaluated using the information in state. |
Source code in src/openmcmc/model.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
|
grad_log_p(state, param, hessian_required=True)
Generate vector of derivatives of the log-pdf with respect to a given parameter, as the sum of the derivatives of all the individual components of the model. If required, also generate the Hessian.
Function only defined for scalar- and vector-valued parameters param. If hessian_required=True, this function returns a tuple of (gradient, Hessian). If hessian_required=False, this function returns a np.ndarray (just the gradient of the log-density).
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
dict
|
current state information. |
required |
param |
str
|
name of the parameter for which we compute derivatives. |
required |
hessian_required |
bool
|
flag for whether the Hessian should be calculated and supplied as an output. |
True
|
Returns:
Type | Description |
---|---|
Union[ndarray, Tuple[ndarray, ndarray]]
|
if hessian_required=True, then a tuple of (gradient, hessian) is returned. If hessian_required=False, then just a gradient vector is returned. The returned values are as follows: grad (np.ndarray): vector gradients of the POSITIVE log-pdf with respect to param. shape=(d, 1), where d is the dimensionality of param. hessian (np.ndarray): array of NEGATIVE second derivatives of the log-pdf with respect to param. shape=(d, d), where d is the dimensionality of param. |
Source code in src/openmcmc/model.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
|