pararealml.operators.ml.auto_regression package

Submodules

pararealml.operators.ml.auto_regression.auto_regression_operator module

class pararealml.operators.ml.auto_regression.auto_regression_operator.AutoRegressionOperator(d_t: float, vertex_oriented: bool)[source]

Bases: pararealml.operator.Operator

A supervised machine learning operator that uses auto regression to model a high fidelity operator for solving initial value problems.

fit_model(model: pararealml.operators.ml.auto_regression.auto_regression_operator.SKLearnRegressor, data: Tuple[numpy.ndarray, numpy.ndarray], test_size: float = 0.2, score_func: Callable[[numpy.ndarray, numpy.ndarray], float] = <function mean_squared_error>) → Tuple[float, float][source]

Fits the regression model to the training share of the provided data points using random splitting, it stores the fitted model as a member variable for solving IVPs, and it returns the loss of the model evaluated on both the training and test data sets.

Parameters:
  • model – the regression model to train
  • data – a tuple of the inputs and the target outputs
  • test_size – the fraction of all data points that should be used for testing
  • score_func – the prediction scoring function to use
Returns:

the training and test losses

generate_data(ivp: pararealml.initial_value_problem.InitialValueProblem, oracle: pararealml.operator.Operator, iterations: int, perturbation_function: Callable[[float, numpy.ndarray], numpy.ndarray], isolate_perturbations: bool = False) → Tuple[numpy.ndarray, numpy.ndarray][source]

Generates data to train an operator model by using the oracle to repeatedly solve sub-IVPs with perturbed initial conditions and a time domain extent matching the step size of this operator.

Parameters:
  • ivp – the IVP to train the regression model on
  • oracle – the operator providing the training data
  • iterations – the number of data generation iterations
  • perturbation_function – a function that takes a time argument, representing the start of a sub-IVP’s time domain, and the discrete initial conditions for the sub-IVP and returns a perturbed version of the initial conditions
  • isolate_perturbations – whether to stop perturbations from propagating through to the subsequent sub-IVPs
Returns:

a tuple of the inputs and the target outputs

model

The regression model behind the operator.

solve(ivp: pararealml.initial_value_problem.InitialValueProblem, parallel_enabled: bool = True) → pararealml.solution.Solution[source]

Returns the IVP’s solution.

Parameters:
  • ivp – the initial value problem to solve
  • parallel_enabled – whether in-time parallelization is enabled
Returns:

the solution of the IVP

train(ivp: pararealml.initial_value_problem.InitialValueProblem, oracle: pararealml.operator.Operator, model: pararealml.operators.ml.auto_regression.auto_regression_operator.SKLearnRegressor, iterations: int, perturbation_function: Callable[[float, numpy.ndarray], numpy.ndarray], isolate_perturbations: bool = False, test_size: float = 0.2, score_func: Callable[[numpy.ndarray, numpy.ndarray], float] = <function mean_squared_error>) → Tuple[float, float][source]

Fits a regression model to training data generated by the oracle.

The inputs of the model are time t, spatial coordinates x, and the values of the solution at all points of the IVP’s mesh at time t (for ODEs, no spatial coordinates are included in the features and the solution is evaluated merely at t). The model outputs are the predicted values of the solution at x and t + d_t (for ODEs, it is again just the solution at t + d_t).

The training data is generated by using the oracle to repeatedly solve sub-IVPs with perturbed initial conditions and a time domain extent matching the step size of this operator.

Parameters:
  • ivp – the IVP to train the regression model on
  • oracle – the operator providing the training data
  • model – the model to fit to the training data
  • iterations – the number of data generation iterations
  • perturbation_function – a function that takes a time argument, representing the start of a sub-IVP’s time domain, and the discrete initial values for the sub-IVP’s solution and returns a perturbed version of the initial values
  • isolate_perturbations – whether to stop perturbations from propagating through to the subsequent sub-IVPs
  • test_size – the fraction of all data points that should be used for testing
  • score_func – the prediction scoring function to use
Returns:

the training and test losses

class pararealml.operators.ml.auto_regression.auto_regression_operator.SKLearnRegressor(*args, **kwargs)[source]

Bases: typing.Protocol

A protocol class for scikit-learn regression models.

fit(x: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]], y: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]], sample_weight: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]], None] = None) → pararealml.operators.ml.auto_regression.auto_regression_operator.SKLearnRegressor[source]
predict(x: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]]) → numpy.ndarray[source]
score(x: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]], y: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]], sample_weight: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]], None] = None) → float[source]

pararealml.operators.ml.auto_regression.sklearn_keras_regressor module

class pararealml.operators.ml.auto_regression.sklearn_keras_regressor.SKLearnKerasRegressor(model: keras.engine.training.Model, optimizer: Union[str, keras.optimizer_v2.optimizer_v2.OptimizerV2] = 'adam', loss: str = 'mse', epochs: int = 1000, batch_size: int = 64, verbose: bool = False, **kwargs)[source]

Bases: keras.wrappers.scikit_learn.KerasRegressor

A wrapper for Keras regression models to implement the implicit Scikit-learn model interface.

Module contents

class pararealml.operators.ml.auto_regression.AutoRegressionOperator(d_t: float, vertex_oriented: bool)[source]

Bases: pararealml.operator.Operator

A supervised machine learning operator that uses auto regression to model a high fidelity operator for solving initial value problems.

fit_model(model: pararealml.operators.ml.auto_regression.auto_regression_operator.SKLearnRegressor, data: Tuple[numpy.ndarray, numpy.ndarray], test_size: float = 0.2, score_func: Callable[[numpy.ndarray, numpy.ndarray], float] = <function mean_squared_error>) → Tuple[float, float][source]

Fits the regression model to the training share of the provided data points using random splitting, it stores the fitted model as a member variable for solving IVPs, and it returns the loss of the model evaluated on both the training and test data sets.

Parameters:
  • model – the regression model to train
  • data – a tuple of the inputs and the target outputs
  • test_size – the fraction of all data points that should be used for testing
  • score_func – the prediction scoring function to use
Returns:

the training and test losses

generate_data(ivp: pararealml.initial_value_problem.InitialValueProblem, oracle: pararealml.operator.Operator, iterations: int, perturbation_function: Callable[[float, numpy.ndarray], numpy.ndarray], isolate_perturbations: bool = False) → Tuple[numpy.ndarray, numpy.ndarray][source]

Generates data to train an operator model by using the oracle to repeatedly solve sub-IVPs with perturbed initial conditions and a time domain extent matching the step size of this operator.

Parameters:
  • ivp – the IVP to train the regression model on
  • oracle – the operator providing the training data
  • iterations – the number of data generation iterations
  • perturbation_function – a function that takes a time argument, representing the start of a sub-IVP’s time domain, and the discrete initial conditions for the sub-IVP and returns a perturbed version of the initial conditions
  • isolate_perturbations – whether to stop perturbations from propagating through to the subsequent sub-IVPs
Returns:

a tuple of the inputs and the target outputs

model

The regression model behind the operator.

solve(ivp: pararealml.initial_value_problem.InitialValueProblem, parallel_enabled: bool = True) → pararealml.solution.Solution[source]

Returns the IVP’s solution.

Parameters:
  • ivp – the initial value problem to solve
  • parallel_enabled – whether in-time parallelization is enabled
Returns:

the solution of the IVP

train(ivp: pararealml.initial_value_problem.InitialValueProblem, oracle: pararealml.operator.Operator, model: pararealml.operators.ml.auto_regression.auto_regression_operator.SKLearnRegressor, iterations: int, perturbation_function: Callable[[float, numpy.ndarray], numpy.ndarray], isolate_perturbations: bool = False, test_size: float = 0.2, score_func: Callable[[numpy.ndarray, numpy.ndarray], float] = <function mean_squared_error>) → Tuple[float, float][source]

Fits a regression model to training data generated by the oracle.

The inputs of the model are time t, spatial coordinates x, and the values of the solution at all points of the IVP’s mesh at time t (for ODEs, no spatial coordinates are included in the features and the solution is evaluated merely at t). The model outputs are the predicted values of the solution at x and t + d_t (for ODEs, it is again just the solution at t + d_t).

The training data is generated by using the oracle to repeatedly solve sub-IVPs with perturbed initial conditions and a time domain extent matching the step size of this operator.

Parameters:
  • ivp – the IVP to train the regression model on
  • oracle – the operator providing the training data
  • model – the model to fit to the training data
  • iterations – the number of data generation iterations
  • perturbation_function – a function that takes a time argument, representing the start of a sub-IVP’s time domain, and the discrete initial values for the sub-IVP’s solution and returns a perturbed version of the initial values
  • isolate_perturbations – whether to stop perturbations from propagating through to the subsequent sub-IVPs
  • test_size – the fraction of all data points that should be used for testing
  • score_func – the prediction scoring function to use
Returns:

the training and test losses

class pararealml.operators.ml.auto_regression.SKLearnRegressor(*args, **kwargs)[source]

Bases: typing.Protocol

A protocol class for scikit-learn regression models.

fit(x: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]], y: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]], sample_weight: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]], None] = None) → pararealml.operators.ml.auto_regression.auto_regression_operator.SKLearnRegressor[source]
predict(x: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]]) → numpy.ndarray[source]
score(x: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]], y: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]]], sample_weight: Union[numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype], numpy.typing._nested_sequence._NestedSequence[numpy.typing._array_like._SupportsArray[numpy.dtype]][numpy.typing._array_like._SupportsArray[numpy.dtype][numpy.dtype]], bool, int, float, complex, str, bytes, numpy.typing._nested_sequence._NestedSequence[typing.Union[bool, int, float, complex, str, bytes]][Union[bool, int, float, complex, str, bytes]], None] = None) → float[source]
class pararealml.operators.ml.auto_regression.SKLearnKerasRegressor(model: keras.engine.training.Model, optimizer: Union[str, keras.optimizer_v2.optimizer_v2.OptimizerV2] = 'adam', loss: str = 'mse', epochs: int = 1000, batch_size: int = 64, verbose: bool = False, **kwargs)[source]

Bases: keras.wrappers.scikit_learn.KerasRegressor

A wrapper for Keras regression models to implement the implicit Scikit-learn model interface.