Python Plant Model
- class ExternalPlant(central_param: ndarray = array([0.5, 0.5]), param_limits: ndarray = array([[0, 1], [0, 1]]), name: str | None = None)[source]
Bases:
BaseModel
,ArtificialModelInterface
A plant model which uses functions defined outside the class to evaluate the forward pass and the jacobian Param0: Water [0,1] Param1: Sun [0,1] Data0: Size [0,2] # the more water and sun the better Data1: Health [0,1], to much water is not good, too much sun is not good Data2: Trauerfliegen :P
- forward(param)[source]
Executed the forward pass of the model to obtain data from a parameter.
- Parameters:
param (np.ndarray) – The parameter for which the data should be generated.
- Returns:
The data generated from the parameter.
- Return type:
np.ndarray
Examples:
import numpy as np from eulerpi.examples.heat import Heat from eulerpi.core.models import JaxModel from jax import vmap # instantiate the heat model model = Heat() # define a 3D example parameter for the heat model example_param = np.array([1.4, 1.6, 0.5]) # the forward simulation is achieved by using the forward method of the model sim_result = model.forward(example_param) # in a more realistic scenario, we would like to perform the forward pass on multiple parameters at once multiple_params = np.array([[1.5, 1.5, 0.5], [1.4, 1.4, 0.6], [1.6, 1.6, 0.4], model.central_param, [1.5, 1.4, 0.4]]) multiple_sim_results = model.forward_vectorized(multiple_params)
- generate_artificial_params(num_samples: int)[source]
This method must be overwritten an return an numpy array of num_samples parameters.
- Parameters:
num_samples (int) – The number of parameters to generate.
- Returns:
The generated parameters.
- Return type:
np.ndarray
- Raises:
NotImplementedError – If the method is not overwritten in a subclass.
- jacobian(param)[source]
Evaluates the jacobian of the
forward()
method.- Parameters:
param (np.ndarray) – The parameter for which the jacobian should be evaluated.
- Returns:
The jacobian for the variables returned by the
forward()
method with respect to the parameters.- Return type:
np.ndarray
Examples:
import numpy as np from eulerpi.examples.heat import Heat from eulerpi.core.models import JaxModel from jax import vmap # instantiate the heat model model = Heat() # define a 3D example parameter for the heat model example_param = np.array([1.4, 1.6, 0.5]) sim_jacobian = model.jacobian(example_param) # Similar to the forward pass, also the evaluation of the jacobian can be vectorized. # This yields a 3D array of shape (num_params, data_dim, param_dim) = (4,5,3) in this example. multiple_params = np.array([[1.5, 1.5, 0.5], [1.4, 1.4, 0.6], model.central_param, [1.5, 1.4, 0.4]]) # try to use jax vmap for vectorization if possible if isinstance(model, JaxModel): multiple_sim_jacobians = vmap(model.jacobian, in_axes=0)(multiple_params) # if the model is not a jax model, we can use numpy vectorize to vectorize else: multiple_sim_jacobians = np.vectorize(model.jacobian, signature="(n)->(m)")(multiple_params)
- CENTRAL_PARAM = array([0.5, 0.5])
- PARAM_LIMITS = array([[0, 1], [0, 1]])
- data_dim: int | None = 3
- param_dim: int | None = 2
- class JaxPlant(central_param: ndarray = array([0.5, 0.5]), param_limits: ndarray = array([[0, 1], [0, 1]]), name: str | None = None, **kwargs)[source]
Bases:
JaxModel
,ArtificialModelInterface
A plant model which inherits from the JaxModel to define the jacobian Param0: Water [0,1] Param1: Sun [0,1] Data0: Size [0,2] # the more water and sun the better Data1: Health [0,1], to much water is not good, too much sun is not good Data2: Sciarid :P
- classmethod forward(param)[source]
Executed the forward pass of the model to obtain data from a parameter.
- Parameters:
param (np.ndarray) – The parameter for which the data should be generated.
- Returns:
The data generated from the parameter.
- Return type:
np.ndarray
Examples:
import numpy as np from eulerpi.examples.heat import Heat from eulerpi.core.models import JaxModel from jax import vmap # instantiate the heat model model = Heat() # define a 3D example parameter for the heat model example_param = np.array([1.4, 1.6, 0.5]) # the forward simulation is achieved by using the forward method of the model sim_result = model.forward(example_param) # in a more realistic scenario, we would like to perform the forward pass on multiple parameters at once multiple_params = np.array([[1.5, 1.5, 0.5], [1.4, 1.4, 0.6], [1.6, 1.6, 0.4], model.central_param, [1.5, 1.4, 0.4]]) multiple_sim_results = model.forward_vectorized(multiple_params)
- generate_artificial_params(num_samples: int)[source]
This method must be overwritten an return an numpy array of num_samples parameters.
- Parameters:
num_samples (int) – The number of parameters to generate.
- Returns:
The generated parameters.
- Return type:
np.ndarray
- Raises:
NotImplementedError – If the method is not overwritten in a subclass.
- CENTRAL_PARAM = array([0.5, 0.5])
- PARAM_LIMITS = array([[0, 1], [0, 1]])
- data_dim: int | None = 3
- param_dim: int | None = 2