voiage.metamodels module

Metamodels for Value of Information analysis.

class voiage.metamodels.Metamodel(*args, **kwargs)[source]

Bases: Protocol

A protocol for metamodels used in VOI analysis.

fit(x: ParameterSet, y: ndarray) None[source]

Fit the metamodel to the data.

Parameters:
  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The target values.

predict(x: ParameterSet) ndarray[source]

Predict the target values for the given input parameters.

Parameters:

x (ParameterSet) – The input parameters.

Returns:

The predicted target values.

Return type:

np.ndarray

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the prediction.

Parameters:
  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

Returns:

R^2 score.

Return type:

float

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the prediction.

Parameters:
  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

Returns:

RMSE score.

Return type:

float

voiage.metamodels.calculate_diagnostics(model: Metamodel, x: ParameterSet, y: ndarray) dict[source]

Calculate comprehensive diagnostics for a fitted metamodel.

Parameters:
  • model (Metamodel) – A fitted metamodel instance.

  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

Returns:

A dictionary containing various diagnostic metrics.

Return type:

dict

voiage.metamodels.cross_validate(model: Metamodel, x: ParameterSet, y: ndarray, cv_folds: int = 5, random_state: int = 42) dict[source]

Perform cross-validation for a metamodel.

Parameters:
  • model (Metamodel) – A metamodel class (not instance) to be cross-validated.

  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

  • cv_folds (int, default=5) – Number of cross-validation folds.

  • random_state (int, default=42) – Random state for reproducibility.

Returns:

A dictionary containing cross-validation results.

Return type:

dict

voiage.metamodels.compare_metamodels(models: list, x: ParameterSet, y: ndarray, cv_folds: int = 5) dict[source]

Compare multiple metamodels using cross-validation.

Parameters:
  • models (list) – A list of metamodel classes to compare.

  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

  • cv_folds (int, default=5) – Number of cross-validation folds.

Returns:

A dictionary containing comparison results for all models.

Return type:

dict

class voiage.metamodels.MLP(features: int)[source]

Bases: object

A simple MLP model.

class voiage.metamodels.FlaxMetamodel(learning_rate=0.01, n_epochs=100)[source]

Bases: object

A metamodel that uses a Flax MLP to predict the target values.

fit(x: ParameterSet, y: ndarray) None[source]

Fit the metamodel to the data.

predict(x: ParameterSet) ndarray[source]

Predict the target values for the given input parameters.

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the prediction.

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the prediction.

class voiage.metamodels.TinyGPMetamodel[source]

Bases: object

A metamodel that uses a tinygp GP to predict the target values.

fit(x: ParameterSet, y: ndarray) None[source]

Fit the metamodel to the data.

predict(x: ParameterSet) ndarray[source]

Predict the target values for the given input parameters.

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the prediction.

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the prediction.

class voiage.metamodels.RandomForestMetamodel(n_estimators=100, max_depth=None, random_state=42)[source]

Bases: object

A metamodel that uses a Random Forest to predict the target values.

fit(x: ParameterSet, y: ndarray) None[source]

Fit the metamodel to the data.

predict(x: ParameterSet) ndarray[source]

Predict the target values for the given input parameters.

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the prediction.

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the prediction.

class voiage.metamodels.GAMMetamodel(n_splines=10, lam=0.1)[source]

Bases: object

A metamodel that uses a Generalized Additive Model to predict the target values.

fit(x: ParameterSet, y: ndarray) None[source]

Fit the metamodel to the data.

predict(x: ParameterSet) ndarray[source]

Predict the target values for the given input parameters.

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the prediction.

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the prediction.

class voiage.metamodels.BARTMetamodel(num_trees=50, alpha=0.95, beta=2.0)[source]

Bases: object

A metamodel that uses a BART (Bayesian Additive Regression Trees) to predict the target values.

fit(x: ParameterSet, y: ndarray) None[source]

Fit the metamodel to the data.

predict(x: ParameterSet) ndarray[source]

Predict the target values for the given input parameters.

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the prediction.

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the prediction.

class voiage.metamodels.ActiveLearningMetamodel(base_model, n_initial_samples=10, n_query_samples=5, acquisition_function='uncertainty')[source]

Bases: object

A metamodel that uses active learning to iteratively improve its predictions.

__init__(base_model, n_initial_samples=10, n_query_samples=5, acquisition_function='uncertainty')[source]

Initialize the active learning metamodel.

Parameters:
  • base_model (Metamodel) – The base metamodel to use for predictions.

  • n_initial_samples (int, default=10) – Number of initial samples to start with.

  • n_query_samples (int, default=5) – Number of samples to query at each iteration.

  • acquisition_function (str, default='uncertainty') – The acquisition function to use for selecting samples. Options are ‘uncertainty’, ‘random’, ‘margin’.

fit(x: ParameterSet, y: ndarray, x_pool=None, y_pool=None, n_iterations=5) None[source]

Fit the metamodel using active learning.

Parameters:
  • x (ParameterSet) – Initial training parameters.

  • y (np.ndarray) – Initial training targets.

  • x_pool (np.ndarray, optional) – Pool of unlabeled samples to query from.

  • y_pool (np.ndarray, optional) – True labels for the pool (for simulation purposes).

  • n_iterations (int, default=5) – Number of active learning iterations.

predict(x: ParameterSet) ndarray[source]

Predict using the actively learned metamodel.

Parameters:

x (ParameterSet) – The input parameters.

Returns:

The predictions.

Return type:

np.ndarray

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the prediction.

Parameters:
  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

Returns:

R^2 score.

Return type:

float

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the prediction.

Parameters:
  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

Returns:

RMSE.

Return type:

float

class voiage.metamodels.EnsembleMetamodel(models, method='mean')[source]

Bases: object

A metamodel that combines predictions from multiple metamodels.

__init__(models, method='mean')[source]

Initialize the ensemble metamodel.

Parameters:
  • models (list) – A list of metamodel instances to ensemble.

  • method (str, default='mean') – The ensemble method to use. Options are ‘mean’, ‘median’, ‘weighted’.

fit(x: ParameterSet, y: ndarray) None[source]

Fit all metamodels in the ensemble.

Parameters:
  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The target values.

predict(x: ParameterSet) ndarray[source]

Predict using the ensemble of metamodels.

Parameters:

x (ParameterSet) – The input parameters.

Returns:

The ensemble predictions.

Return type:

np.ndarray

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the ensemble prediction.

Parameters:
  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

Returns:

R^2 score of the ensemble.

Return type:

float

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the ensemble prediction.

Parameters:
  • x (ParameterSet) – The input parameters.

  • y (np.ndarray) – The true target values.

Returns:

RMSE of the ensemble.

Return type:

float

class voiage.metamodels.PyTorchNNMetamodel(hidden_layers=None, learning_rate=0.001, n_epochs=1000, batch_size=32)[source]

Bases: object

A metamodel that uses a PyTorch neural network to predict the target values.

fit(x: ParameterSet, y: ndarray) None[source]

Fit the metamodel to the data.

predict(x: ParameterSet) ndarray[source]

Predict the target values for the given input parameters.

score(x: ParameterSet, y: ndarray) float[source]

Return the coefficient of determination R^2 of the prediction.

rmse(x: ParameterSet, y: ndarray) float[source]

Return the root mean squared error of the prediction.