opencr.ml.surrogate
A baseline surrogate of the CR solver with scikit-learn.
Surrogate learns ln(outputs) from ln(inputs) of a dataset
(generate_dataset), by default with a Gaussian
process (a neural network is the optional next step). The solver stays the reference: Surrogate.evaluate
reports the held-out error against it and the speed-up, and
Surrogate.predict flags inputs outside the training ranges (out of
domain), where the surrogate is not to be trusted. scikit-learn is imported
only here (the ml extra).
Classes
| Name | Description |
|---|---|
Prediction | Surrogate outputs and whether each input is inside the training domain. |
Surrogate | A regression of the dataset's outputs on its inputs, in log space. |
Predictionclassdataclass#
class Prediction(values: np.ndarray, in_domain: np.ndarray)Surrogate outputs and whether each input is inside the training domain.
Attributes
| Name | Type | Description |
|---|---|---|
values | np.ndarray | The predicted outputs (sample, output). |
in_domain | np.ndarray | True where every input is inside the training ranges. |
in_domainattributeinstance attribute#
in_domain: np.ndarrayvaluesattributeinstance attribute#
values: np.ndarraySurrogateclass#
class Surrogate(estimator: Any = None, seed: int = 0)A regression of the dataset’s outputs on its inputs, in log space.
Parameters
estimatorattributeinstance attribute#
estimator = estimatorhighattributeinstance attribute#
high = np.empty(0)lowattributeinstance attribute#
low = np.empty(0)outputsattributeinstance attribute#
outputs: tuple[str, ...] = ()parametersattributeinstance attribute#
parameters: tuple[str, ...] = ()provenanceattributeinstance attribute#
provenance: dict[str, Any] = {}seedattributeinstance attribute#
seed = seedevaluatemethod#
def evaluate(dataset: xr.Dataset, split: int = 2, solve_time: float | None = None) -> xr.DatasetReturn the held-out relative errors and the speed-up on one split.
Parameters
Returns
xr.Dataset- Per output: the median, 95th percentile and maximum of
xr.Dataset|predicted / solved - 1|, and in the attributes the surrogate’sxr.Dataset- time per sample and the speed-up.
fitmethod#
def fit(dataset: xr.Dataset) -> SurrogateTrain on the dataset’s training split and return self.
forwardmethod#
def forward(theta: np.ndarray) -> np.ndarrayOne sample’s outputs, as a forward model for opencr.inference.
predictmethod#
def predict(inputs: np.ndarray) -> PredictionReturn the outputs at inputs (sample, parameter) with the domain flag.