voiage.metamodels module
Metamodels for Value of Information analysis.
- class voiage.metamodels.Metamodel(*args, **kwargs)[source]
Bases:
ProtocolA 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
- voiage.metamodels.calculate_diagnostics(model: Metamodel, x: ParameterSet, y: ndarray) dict[str, float | int][source]
Calculate comprehensive diagnostics for a fitted metamodel.
- voiage.metamodels.cross_validate(model: type[Metamodel], x: ParameterSet, y: ndarray, cv_folds: int = 5, random_state: int = 42) dict[str, object][source]
Perform cross-validation for a metamodel.
- Parameters:
- Returns:
A dictionary containing cross-validation results.
- Return type:
- voiage.metamodels.compare_metamodels(models: list[type[Metamodel]], x: ParameterSet, y: ndarray, cv_folds: int = 5) dict[str, dict[str, object]][source]
Compare multiple metamodels using cross-validation.
- class voiage.metamodels.FlaxMetamodel(learning_rate: float = 0.01, n_epochs: int = 100)[source]
Bases:
objectA metamodel that uses a Flax MLP to predict the target values.
- class voiage.metamodels.TinyGPMetamodel[source]
Bases:
objectA metamodel that uses a tinygp GP to predict the target values.
- class voiage.metamodels.RandomForestMetamodel(n_estimators: int = 100, max_depth: int | None = None, random_state: int = 42)[source]
Bases:
objectA metamodel that uses a Random Forest to predict the target values.
- class voiage.metamodels.GAMMetamodel(n_splines: int = 10, lam: float = 0.1)[source]
Bases:
objectA metamodel that uses a Generalized Additive Model to predict the target values.
- class voiage.metamodels.BARTMetamodel(num_trees: int = 50, alpha: float = 0.95, beta: float = 2.0)[source]
Bases:
objectA metamodel that uses a BART (Bayesian Additive Regression Trees) to predict the target values.
- class voiage.metamodels.ActiveLearningMetamodel(base_model: Metamodel, n_initial_samples: int = 10, n_query_samples: int = 5, acquisition_function: str = 'uncertainty')[source]
Bases:
objectA metamodel that uses active learning to iteratively improve its predictions.
- __init__(base_model: Metamodel, n_initial_samples: int = 10, n_query_samples: int = 5, acquisition_function: str = 'uncertainty') None[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: ndarray | None = None, y_pool: ndarray | None = None, n_iterations: int = 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
- class voiage.metamodels.EnsembleMetamodel(models: list[Metamodel], method: str = 'mean')[source]
Bases:
objectA metamodel that combines predictions from multiple metamodels.
- __init__(models: list[Metamodel], method: str = 'mean') None[source]
Initialize the ensemble metamodel.
- 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
- class voiage.metamodels.PyTorchNNMetamodel(hidden_layers: list[int] | None = None, learning_rate: float = 0.001, n_epochs: int = 1000, batch_size: int = 32)[source]
Bases:
objectA metamodel that uses a PyTorch neural network to predict the target values.