emulators.linear
Ordinary least squares (OLS) linear regression emulator.
The simplest emulator: fast to fit, but assumes a linear relationship between parameters and outputs and provides only limited uncertainty information. Useful for prototyping or for genuinely near-linear responses.
Classes
| Name | Description |
|---|---|
| LinearModel | Emulator based on an ordinary least squares linear regression. |
| LinearModelScipy | Emulator based on an ordinary least squares linear regression. |
LinearModel
emulators.linear.LinearModel(x=None, y=None, test_fraction=0.25)Emulator based on an ordinary least squares linear regression.
Fits a linear regression model that minimizes the residual sum of squares between the observed training targets and the targets predicted by the linear approximation. Fast, but assumes linearity and gives limited uncertainty estimates.
Example
import numpy as np, pandas as pd
from historymatching.emulators.linear import LinearModel
x = pd.DataFrame({'beta': np.random.rand(40), 'gamma': np.random.rand(40)})
y = pd.DataFrame({'peak': 2 * x['beta'] - x['gamma']})
em = LinearModel(x, y)
em.train()
pred = em.predict(x)Methods
| Name | Description |
|---|---|
| get_hyperparameters | Return linear model hyperparameters as a JSON-serializable dict. |
| predict | Predict an output using the trained emulator. |
| print_emulator_description | Display detailed specifications (for example, emulator coefficients) |
| train | Fits a linear regression model to minimize the residual sum of squares between observed targets in the training data and the targets predicted by the linear approximation. |
get_hyperparameters
emulators.linear.LinearModel.get_hyperparameters()Return linear model hyperparameters as a JSON-serializable dict.
predict
emulators.linear.LinearModel.predict(x)Predict an output using the trained emulator.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | pd.DataFrame | Input data. Pandas dataframe with columns representing parameter values. | required |
Returns
| Name | Type | Description |
|---|---|---|
| EmulationResults | EmulationResults with predicted values and uncertainty intervals. |
print_emulator_description
emulators.linear.LinearModel.print_emulator_description()Display detailed specifications (for example, emulator coefficients) for the trained emulator.
train
emulators.linear.LinearModel.train()Fits a linear regression model to minimize the residual sum of squares between observed targets in the training data and the targets predicted by the linear approximation.
LinearModelScipy
emulators.linear.LinearModelScipy(x=None, y=None, test_fraction=0.25)Emulator based on an ordinary least squares linear regression. The emulator fits a linear regression model to minimize the residual sum of squares between observed targets in the training data and the targets predicted by the linear approximation.
Methods
| Name | Description |
|---|---|
| get_hyperparameters | Return linear model (scipy) hyperparameters as a JSON-serializable dict. |
| predict | Predict an output using the trained emulator. |
| print_emulator_description | Display detailed specifications (for example, emulator coefficients) |
| train | Fits a linear regression model to minimize the residual sum of squares between observed targets in the training data and the targets predicted by the linear approximation. |
get_hyperparameters
emulators.linear.LinearModelScipy.get_hyperparameters()Return linear model (scipy) hyperparameters as a JSON-serializable dict.
predict
emulators.linear.LinearModelScipy.predict(x)Predict an output using the trained emulator.
Parameters
| Name | Type | Description | Default |
|---|---|---|---|
| x | pd.DataFrame | Input data. Pandas dataframe with columns representing parameter values. | required |
Returns
| Name | Type | Description |
|---|---|---|
| EmulationResults | EmulationResults with predicted values and uncertainty intervals. |
print_emulator_description
emulators.linear.LinearModelScipy.print_emulator_description()Display detailed specifications (for example, emulator coefficients) for the trained emulator.
train
emulators.linear.LinearModelScipy.train()Fits a linear regression model to minimize the residual sum of squares between observed targets in the training data and the targets predicted by the linear approximation.