Toy (Quark) Model#
|
This module provides functionality to create and test very basic toy models for debugging, performance evaluation, etc.
- class ToyQuarkConfigs(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', model_name='Toy-Quark', screen_output_iter=1, file_output_iter=1, x_grid=<factory>, Nq=2)[source]#
Bases:
TimeIndependentModelConfigs
Configuration class for the ToyQuark model
- Parameters:
verbose (bool) – a boolean flag to control verbosity of the object.
debug (bool) – a boolean flag that enables adding extra functionlity in a debug mode
output_dir (str | Path) – the base directory where the output files will be saved.
screen_output_iter (int) – iteration interval for screen output. Default is 1. Note that this should be a positive integer to enforce proper effect.
file_out_iter – iteration interval for file output. Default is 1. Note that this should be a positive integer to enforce proper effect.
x_grid (ndarray) – discretization of the state space. Default is
np.linspace(0, 1, 10)
. Must be a 1D numpy array.Nq (int) – number of quarks. Default is 2. Must be a postiive integer.
model_name (str) – name of the model. Default is “Toy-Quark”
- x_grid: ndarray#
- Nq: int#
- __init__(*, debug=False, verbose=False, output_dir='./_PYOED_RESULTS_', model_name='Toy-Quark', screen_output_iter=1, file_output_iter=1, x_grid=<factory>, Nq=2)#
- class ToyQuark(configs=None)[source]#
Bases:
TimeIndependentModel
Implementation of a toy quark model, from the paper [1]. It is given by the expression
\[\begin{align*} \sigma(x) &= \sum_{i=1}^{N_q} q_i(x) \ q_i(x) &= N_i x^{\alpha_i} (1-x)^{\beta_i} \end{align*}\]where \(N_i, \alpha_i, \beta_i\) are parameters to be estimated. Hence, this is a toy model with 3*N_q parameters. The model is defined on the interval \(x \in [0, 1]\) and the discretization of the state is left variable (i.e., the user can choose the number of discretization points).
- __init__(configs=None)[source]#
Create an instance of the toy quark model.
- Parameters:
configs (ToyQuarkConfigs | dict | None) – configurations of the model. See
ToyQuarkConfigs
for the possible configurations. If None, default configurations are used.
- validate_configurations(configs, raise_for_invalid=True)[source]#
Check the passed configuratios and make sure they are conformable with each other, and with current configurations once combined. This guarantees that any key-value pair passed in configs can be properly used
Note
Here only the locally-defined configurations in
ToyQuarkConfigs
are validated. Finally, super classes validators are called.- Parameters:
configs (dict | ToyQuarkConfigs) – full or partial (subset) configurations to be validated
raise_for_invalid (bool) – if True raise
TypeError
for invalid configrations type/key. Default True
- Returns:
flag indicating whether passed configurations dictionary is valid or not
- Raises:
AttributeError – if any (or a group) of the configurations does not exist in the model configurations
ToyQuarkConfigs
.PyOEDConfigsValidationError – if the configurations are invalid and raise_for_invalid is set to True.
- Return type:
bool
- parameter_vector(init_val=0)[source]#
Create an instance of model parameter vector. This is a vector of size \(3N_q\), and corresponds to parameters in the order \([N_1, \alpha_1, \beta_1, \dots, N_{N_q}, \alpha_{N_q}, \beta_{N_q}]\).
- Parameters:
init_val (float) – (optional) value assigned to entries of the state vector upon initialization
- state_vector(init_val=0)[source]#
Create an instance of model state vector
- Parameters:
init_val (float) – (optional) value assigned to entries of the state vector upon initialization
- q_i(parameter, i)[source]#
Helper function to retrieve the i-th quark distribution function from the parameter vector. The parameter is assumed to be a vector of size \(3N_q\), and corresponds to parameters in the order \([N_1, \alpha_1, \beta_1, \dots, N_{N_q}, \alpha_{N_q}, \beta_{N_q}]\).
- Parameters:
parameter – parameter from which the i-th quark distribution function is retrieved.
i (int) – index of the quark distribution function to retrieve. Note, this is 1-based indexing.
- Returns:
\(q_i(x; p)\) where \(p\) is the parameter vector. This is of size
len(self.x_grid)
.
- solve_forward(parameter, verbose=False)[source]#
Apply (solve the forward model) to the given parameter, and return the resulting state. The parameter is assumed to be a vector of size \(3N_q\), and corresponds to parameters in the order \([N_1, \alpha_1, \beta_1, \dots, N_{N_q}, \alpha_{N_q}, \beta_{N_q}]\).
- Parameters:
parameter – parameter to which the forward model is applied.
- Returns:
\(\sigma(x; p)\) where \(p\) is the parameter vector. This is of size
len(self.x_grid)
.
- Jacobian_T_matvec(state, eval_at=None, verbose=False)[source]#
Multiply the Jacobian of the model (derivative of model equation w.r.t parameter) by the passed state
- Parameters:
state – state to which the forward sensitivities are applied to.
- Returns:
result resulting from applying the forward sensitivities to model to the passed state. This is of size \(3N_q\).
- property x_grid#
retrieve the model grid
- property Nq#
retrieve the number of quarks