constraints#

Provides Constraints, that can be applied on PredictionTasks.

class Constraint(sm: SystemModelInterface)#

Bases: object

Defines an constraint that does nothing.

Write own constraints by inheriting from this one.

Inits the constraint.

Parameters:

sm – A SystemModel, on which the constraint will be applied.

Example

>>> from simba_ml.example_problems.sir import sm
>>> from simba_ml.simulation.constraints.constraint import Constraint
>>> constrainted_pt = Constraint(sm)
apply_noisifier(signal: DataFrame) DataFrame#

Applies the objects noisifier to a signal.

Parameters:

signal – (pd.DataFrame) The signal.

Returns:

Signal with applied noise.

Return type:

pd.DataFrame

apply_sparsifier(signal: DataFrame) DataFrame#

Applies the objects sparsifier to a signal.

Parameters:

signal – (pd.DataFrame) The signal.

Returns:

Signal of reduced features.

Return type:

pd.DataFrame

property deriv: Callable[[float, list[float], dict[str, float]], Tuple[float, ...]]#

Returns the deriv.

Returns:

The deriv.

get_clean_signal(start_values: dict[str, Any], sample_id: int, deriv_noised: bool = True) DataFrame#

Creates a clean signal.

Parameters:
  • start_values – Start values for the simulation.

  • sample_id – The id of the sample.

  • deriv_noised – If the derivative function should be noised.

Returns:

pd.DataFrame

property kinetic_parameters: Dict[str, KineticParameter[Any]]#

Returns the kinetic_parameters.

Returns:

The kinetic_parameters.

property name: str#

Returns the name.

Returns:

The name.

sample_start_values_from_hypercube(n: int) dict[str, Any]#

Creates a start_values dict.

Parameters:

n – The number of samples.

Returns:

The start_values dict.

Return type:

dict[str, Any]

property specieses: dict[str, simba_ml.simulation.species.Species]#

Returns the specieses.

Returns:

The specieses.

class KeepSpeciesRange(sm: SystemModelInterface, max_retries: int = 10)#

Bases: Constraint

Ensures, that the values are in a valid species-specific range.

Inits the constraint.

Parameters:
  • sm – A PredictionTask, on which the constraint will be applied.

  • max_retries – The maximum number of retries, if the signal is not in the specified range.

Example

>>> from simba_ml.example_problems.sir import sm
>>> from simba_ml.simulation import constraints
>>> constrainted_sm = constraints.KeepSpeciesRange(sm)
apply_noisifier(signal: DataFrame) DataFrame#

Applies the noisifier to a signal but ensures, values stay in correct range.

Parameters:

signal – (pd.DataFrame) The signal.

Returns:

Signal with applied noise.

Return type:

pd.DataFrame

Raises:

MaxRetriesReachedError – if the maximum number of retries was reached without creating an valid signal.

apply_sparsifier(signal: DataFrame) DataFrame#

Applies the objects sparsifier to a signal.

Parameters:

signal – (pd.DataFrame) The signal.

Returns:

Signal of reduced features.

Return type:

pd.DataFrame

property deriv: Callable[[float, list[float], dict[str, float]], Tuple[float, ...]]#

Returns the deriv.

Returns:

The deriv.

get_clean_signal(start_values: dict[str, Any], sample_id: int, deriv_noised: bool = True) DataFrame#

Creates a clean signal.

Parameters:
  • start_values – Start values for the simulation.

  • sample_id – The id of the sample.

  • deriv_noised – If the derivative function should be noised.

Returns:

pd.DataFrame

property kinetic_parameters: Dict[str, KineticParameter[Any]]#

Returns the kinetic_parameters.

Returns:

The kinetic_parameters.

property name: str#

Returns the name.

Returns:

The name.

sample_start_values_from_hypercube(n: int) dict[str, Any]#

Creates a start_values dict.

Parameters:

n – The number of samples.

Returns:

The start_values dict.

Return type:

dict[str, Any]

property specieses: dict[str, simba_ml.simulation.species.Species]#

Returns the specieses.

Returns:

The specieses.

class KeepSpeciesSum(sm: SystemModelInterface, specieses_to_hold_sum: Optional[list[str]] = None, species_sum: Optional[int] = None)#

Bases: Constraint

Keeps the sum of specieses constant at every timestep.

Inits KeepSpeciesSum.

Parameters:
  • sm – A SystemModel, on which the constraint will be applied.

  • specieses_to_hold_sum – The specieses, for which the sum has to be constant. If None, all specieses will be taken into account.

  • species_sum – The sum of the given specieses. If None, sum on time 0 will be used.

apply_noisifier(signal: DataFrame) DataFrame#

Applies the noisifier to a signal. Ensures values stay in correct range.

Parameters:

signal – (pd.DataFrame) The signal.

Returns:

Signal with applied noise.

Return type:

pd.DataFrame

apply_sparsifier(signal: DataFrame) DataFrame#

Applies the objects sparsifier to a signal.

Parameters:

signal – (pd.DataFrame) The signal.

Returns:

Signal of reduced features.

Return type:

pd.DataFrame

property deriv: Callable[[float, list[float], dict[str, float]], Tuple[float, ...]]#

Returns the deriv.

Returns:

The deriv.

get_clean_signal(start_values: dict[str, Any], sample_id: int, deriv_noised: bool = True) DataFrame#

Creates a clean signal.

Parameters:
  • start_values – Start values for the simulation.

  • sample_id – The id of the sample.

  • deriv_noised – If the derivative function should be noised.

Returns:

pd.DataFrame

property kinetic_parameters: Dict[str, KineticParameter[Any]]#

Returns the kinetic_parameters.

Returns:

The kinetic_parameters.

property name: str#

Returns the name.

Returns:

The name.

sample_start_values_from_hypercube(n: int) dict[str, Any]#

Creates a start_values dict.

Parameters:

n – The number of samples.

Returns:

The start_values dict.

Return type:

dict[str, Any]

property specieses: dict[str, simba_ml.simulation.species.Species]#

Returns the specieses.

Returns:

The specieses.

class SpeciesValueTruncator(sm: SystemModelInterface)#

Bases: Constraint

Truncates the values to a valid species-specific range.

Inits the constraint.

Parameters:

sm – A SystemModel, on which the constraint will be applied.

Example

>>> from simba_ml.example_problems.sir import sm
>>> from simba_ml.simulation.constraints.constraint import Constraint
>>> constrainted_pt = Constraint(sm)
apply_noisifier(signal: DataFrame) DataFrame#

Applies the noisifier to a signal but ensures values stay in correct range.

Parameters:

signal – (pd.DataFrame) The signal.

Returns:

Signal with applied noise.

Return type:

pd.DataFrame

apply_sparsifier(signal: DataFrame) DataFrame#

Applies the objects sparsifier to a signal.

Parameters:

signal – (pd.DataFrame) The signal.

Returns:

Signal of reduced features.

Return type:

pd.DataFrame

property deriv: Callable[[float, list[float], dict[str, float]], Tuple[float, ...]]#

Returns the deriv.

Returns:

The deriv.

get_clean_signal(start_values: dict[str, Any], sample_id: int, deriv_noised: bool = True) DataFrame#

Creates a clean signal.

Parameters:
  • start_values – Start values for the simulation.

  • sample_id – The id of the sample.

  • deriv_noised – If the derivative function should be noised.

Returns:

pd.DataFrame

property kinetic_parameters: Dict[str, KineticParameter[Any]]#

Returns the kinetic_parameters.

Returns:

The kinetic_parameters.

property name: str#

Returns the name.

Returns:

The name.

sample_start_values_from_hypercube(n: int) dict[str, Any]#

Creates a start_values dict.

Parameters:

n – The number of samples.

Returns:

The start_values dict.

Return type:

dict[str, Any]

property specieses: dict[str, simba_ml.simulation.species.Species]#

Returns the specieses.

Returns:

The specieses.

simba_ml.simulation.constraints.constraint

Provides a constranit, which does nothing.

simba_ml.simulation.constraints.keep_species_sum

Provides a constranit, which does nothing.

simba_ml.simulation.constraints.species_value_in_range

Ensures that the values in a signal are in valid range or raises an error.

simba_ml.simulation.constraints.species_value_truncator

Provides a constranit, which does nothing.