ode_utils
Utilities used throughout the package.
-
class
pygom.model.ode_utils.
shapeAdjust
(numState, numParam, numTarget=None) A class that change vector into matrix and vice versa for vectors used in
DeterministicOde
Parameters: - numState: int
number of states
- numParam: int
number of parameters
- numTarget: int, optional
number of targeted states, default assumes that this is the same as numState
-
kronParam
(A, pre=False) A sparse multiplication with an identity matrix of size equal to the number of parameters as initialized
Parameters: - A: array like
a 2d array
- pre: bool, optional
If True, then returns \(I \otimes A\). If False then \(A \otimes I\), where \(A\) is the input matrix, \(I\) is the identity matrix and \(\otimes\) is the kron operator
-
kronState
(A, pre=False) A sparse multiplication with an identity matrix of size equal to the number of state as initialized
Parameters: - A: array like
a 2d array
- pre: bool, optional
If True, then returns \(I \otimes A\). If False then \(A \otimes I\), where \(A\) is the input matrix, \(I\) is the identity matrix and \(\otimes\) is the kron operator
-
matToVecFF
(FF) Transforms the forward forward sensitivity matrix to a vector
-
matToVecSens
(S) Transforms the sensitivity matrix to a vector
-
vecToMatFF
(ff) Transforms the forward forward sensitivity vector to a matrix
-
vecToMatSens
(s) Transforms the sensitivity vector to a matrix
-
pygom.model.ode_utils.
integrate
(ode, x0, t, full_output=False) A wrapper on top of
odeint
usingDeterministicOde
.Parameters: - ode: object
of type
DeterministicOde
- t: array like
the time points including initial time
- full_output: bool, optional
If the additional information from the integration is required
-
pygom.model.ode_utils.
integrateFuncJac
(func, jac, x0, t0, t, args=(), includeOrigin=False, full_output=False, method=None, nsteps=10000) A replacement for
scipy.integrate.odeint
which performs integration usingscipy.integrate.ode
, tries to pick the correct integration method at the start through eigenvalue analysisParameters: - func: callable
the ode \(f(x)\)
- jac: callable
jacobian of the ode, \(J_{i,j} = \nabla_{x_{j}} f_{i}(x)\)
- x0: `numpy.ndarray` or list of numeric
initial value of the states
- t0: float
initial time
- args: tuple, optional
additional arguments to be passed on
- includeOrigin: bool, optional
if the output should include the initial states x0
- full_output: bool, optional
if additional output is required
- method: str, optional
the integration method. All those availble in
ode
are allowed with ‘vode’ and ‘ivode’ representing the non-stiff and stiff version respectively. Defaults to None, which tries to choose the integration method via eigenvalue analysis (only one) using the initial conditions- nstep: int, optional
number of steps allowed between each time point of the integration
Returns: - solution: array like
a
np.ndarray
of shape (len(t), len(x0)) if includeOrigin is False, else an extra row with x0 being the first.- output : dict, only returned if full_output=True
Dictionary containing additional output information
key meaning ‘ev’ vector of eigenvalues at each t ‘maxev’ maximum eigenvalue at each t ‘minev’ minimum eigenvalue at each t ‘suc’ list whether integration is successful ‘in’ name of integrator
-
class
pygom.model.ode_utils.
compileCode
(backend=None) A class that compiles an algebraic expression in sympy to a faster numerical file using the appropriate backend.
-
compileExpr
(inputSymb, inputExpr, backend=None, compileType=False) Compiles the expression given the symbols. Determines the backend if required.
Parameters: - inputSymb: list
the set of symbols for the input expression
- inputExpr: expr
expression in sympy
- backend: optional
the backend we want to use to compile
- compileType: optional
defaults to False. If True, return an extra output that informs the end user of the method used to compile the equation, can be one of (np, mpmath, sympy)
Returns: - Compiled function taking arguments of the input symbols
-
compileExprAndFormat
(inputSymb, inputExpr, backend=None, modules=None, outType=None) Compiles the expression given the symbols and determine which type of output is it. Transforms the output appropriately into numpy
Parameters: - inputSymb: list
the set of symbols for the input expression
- inputExpr: expr
expression in sympy
- backend: optional
the backend we want to use to compile
- modules: optional
in the event that f2py and Cython fails, which modules do we want to try and compile against
Returns: - Function determined from the input using closures.
-
-
class
pygom.model.ode_utils.
CompileCanary
Hold the need for (re-)compilation for various functions
A subclass of this should specify the states to watch
They may all be tripped to True using the trip() method An individual may be reset with the reset() method or with a direct assignment (they may not be tripped in this way).
-
reset
(name) Reset a canary
Parameters: - name: string
the name of the canary to reset
Returns: - None
-
trip
() Trip all the canaries Returns ——- None
-
-
pygom.model.ode_utils.
plot_det
(solution, t, stateList=None, y=None, yStateList=None) Plot the results of the integration
Parameters: - solution: :class:`numpy.ndarray`
solution from the integration
- t: array like
the vector of time where the integration output correspond to
- stateList: list
name of the states, if available
Notes
If we have 5 states or more, it will always be arrange such that it has 3 columns.
-
pygom.model.ode_utils.
plot_stoc
(solution, t, stochastic_model) Plot the results of a stocastic simulation
Parameters: - solution: :class: list
results of the stochastic simulation
- t: array like
the vector of time where the integration output correspond to
- stochastic_model: :class: `pygom.SimulateOde`
the model from which this simulation was generated
Notes
If we have 5 states or more, it will always be arrange such that it has 3 columns.
-
pygom.model.ode_utils.
check_array_type
(x) Check to see if the type of input is suitable. Only operate on one or two dimension arrays
Parameters: - x: array like
which can be either a
numpy.ndarray
or list or tuple
Returns: - x:
numpy.ndarray
checked and converted array
-
pygom.model.ode_utils.
check_dimension
(x, y) Compare the length of two array like objects. Converting both to a numpy array in the process if they are not already one.
Parameters: - x: array like
first array
- y: array like
second array
Returns: - x:
numpy.array
checked and converted first array
- y:
numpy.array
checked and converted second array
-
pygom.model.ode_utils.
is_list_like
(x) Test whether the input is a type that behaves like a list, such as (list,tuple,np.ndarray)
Parameters: - x:
anything
Returns: - bool:
True if it belongs to one of the three expected type (list,tuple,np.ndarray)
-
pygom.model.ode_utils.
str_or_list
(x) Test to see whether input is a string or a list. If it is a string, then we convert it to a list.
Parameters: - x:
str or list
Returns: - x:
x in list form