autoemulate 0.3.1__tar.gz → 0.3.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {autoemulate-0.3.1 → autoemulate-0.3.3}/PKG-INFO +3 -1
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/base.py +21 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/gaussian_process/exact.py +3 -5
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/lightgbm.py +5 -3
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/neural_processes/conditional_neural_process.py +4 -3
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/random_forest.py +3 -3
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/svm.py +3 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/model_selection.py +2 -1
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/history_matching.py +48 -28
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/history_matching_dashboard.py +1 -18
- autoemulate-0.3.3/autoemulate/mcmc.py +348 -0
- autoemulate-0.3.3/autoemulate/mcmc_dashboard.py +818 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/simulations/epidemic.py +30 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/simulations/projectile.py +30 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/pyproject.toml +3 -2
- {autoemulate-0.3.1 → autoemulate-0.3.3}/LICENSE +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/README.md +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/compare.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/cross_validate.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/data_splitting.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/datasets.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/conditional_neural_process.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/conditional_neural_process_attn.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gaussian_process.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gaussian_process_mogp.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gaussian_process_mt.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gaussian_process_sklearn.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gaussian_process_utils/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gaussian_process_utils/early_stopping_criterion.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gaussian_process_utils/poly_mean.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gaussian_process_utils/polynomial_features.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/gradient_boosting.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/light_gbm.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/neural_net_sk.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/neural_networks/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/neural_networks/cnp_module.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/neural_networks/cnp_module_attn.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/neural_networks/datasets.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/neural_networks/gp_module.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/neural_networks/losses.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/polynomials.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/radial_basis_functions.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/random_forest.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/emulators/support_vector_machines.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/compare.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/data/preprocessors.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/data/utils.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/device.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/gaussian_process/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/exploratory/active_matter/README.md +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/exploratory/active_matter/active_matter.ipynb +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/learners/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/learners/base.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/learners/membership.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/learners/pool.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/learners/stream.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/simulations/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/tuner.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/types.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental_design.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/hyperparam_searching.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/logging_config.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/metrics.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/model_processing.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/model_registry.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/plotting.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/preprocess_target.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/printing.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/save.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/sensitivity_analysis.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/simulations/__init__.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/simulations/base.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/simulations/circ_utils.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/simulations/flow_functions.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/simulations/naghavi_cardiac_ModularCirc.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/simulations/reaction_diffusion.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/utils.py +0 -0
- {autoemulate-0.3.1 → autoemulate-0.3.3}/misc/AE_logo_final.png +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: autoemulate
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.3
|
|
4
4
|
Summary: A python package for semi-automated emulation
|
|
5
5
|
License: MIT
|
|
6
6
|
Author: AutoEmulate contributors (see our GitHub page)
|
|
@@ -12,6 +12,7 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
12
12
|
Classifier: Programming Language :: Python :: 3.12
|
|
13
13
|
Provides-Extra: docs
|
|
14
14
|
Requires-Dist: anytree (>=2.12.1,<3.0.0)
|
|
15
|
+
Requires-Dist: corner (>=2.2.3,<3.0.0)
|
|
15
16
|
Requires-Dist: gpytorch (>=1.12,<2.0)
|
|
16
17
|
Requires-Dist: iprogress (>=0.4,<0.5)
|
|
17
18
|
Requires-Dist: ipywidgets (>=8.1.2,<9.0.0)
|
|
@@ -21,6 +22,7 @@ Requires-Dist: matplotlib (>=3.7.2,<4.0.0)
|
|
|
21
22
|
Requires-Dist: mogp-emulator (>=0.7.2,<0.8.0)
|
|
22
23
|
Requires-Dist: numpy (>=1.24,<2.0)
|
|
23
24
|
Requires-Dist: pandas (>=2.1,<3.0)
|
|
25
|
+
Requires-Dist: pyro-ppl (>=1.9.1,<2.0.0)
|
|
24
26
|
Requires-Dist: salib (>=1.5.1,<2.0.0)
|
|
25
27
|
Requires-Dist: scikit-learn (>=1.3.0,<1.6.0)
|
|
26
28
|
Requires-Dist: scipy (>=1.11.3,<2.0.0)
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import random
|
|
1
2
|
from abc import ABC, abstractmethod
|
|
2
3
|
from typing import ClassVar
|
|
3
4
|
|
|
4
5
|
import numpy as np
|
|
6
|
+
import torch
|
|
5
7
|
from sklearn.base import BaseEstimator
|
|
6
8
|
from torch import nn, optim
|
|
7
9
|
|
|
@@ -88,6 +90,25 @@ class Emulator(ABC, ValidationMixin, ConversionMixin, TorchDeviceMixin):
|
|
|
88
90
|
)
|
|
89
91
|
raise NotImplementedError(msg)
|
|
90
92
|
|
|
93
|
+
@staticmethod
|
|
94
|
+
def set_random_seed(seed: int, deterministic: bool = False):
|
|
95
|
+
"""Set random seed for Python, NumPy and PyTorch.
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
seed : int
|
|
100
|
+
The random seed to use.
|
|
101
|
+
deterministic : bool
|
|
102
|
+
Use "deterministic" algorithms in PyTorch.
|
|
103
|
+
"""
|
|
104
|
+
random.seed(seed)
|
|
105
|
+
np.random.seed(seed)
|
|
106
|
+
torch.manual_seed(seed)
|
|
107
|
+
torch.cuda.manual_seed(seed)
|
|
108
|
+
if deterministic:
|
|
109
|
+
torch.backends.cudnn.benchmark = False
|
|
110
|
+
torch.use_deterministic_algorithms(True)
|
|
111
|
+
|
|
91
112
|
|
|
92
113
|
class PyTorchBackend(nn.Module, Emulator, Preprocessor):
|
|
93
114
|
"""
|
{autoemulate-0.3.1 → autoemulate-0.3.3}/autoemulate/experimental/emulators/gaussian_process/exact.py
RENAMED
|
@@ -31,7 +31,6 @@ from autoemulate.experimental.emulators.gaussian_process import (
|
|
|
31
31
|
MeanModuleFn,
|
|
32
32
|
)
|
|
33
33
|
from autoemulate.experimental.types import DeviceLike, OutputLike, TensorLike
|
|
34
|
-
from autoemulate.utils import set_random_seed
|
|
35
34
|
|
|
36
35
|
|
|
37
36
|
class GaussianProcessExact(Emulator, gpytorch.models.ExactGP, Preprocessor):
|
|
@@ -53,16 +52,15 @@ class GaussianProcessExact(Emulator, gpytorch.models.ExactGP, Preprocessor):
|
|
|
53
52
|
mean_module_fn: MeanModuleFn = constant_mean,
|
|
54
53
|
covar_module_fn: CovarModuleFn = rbf,
|
|
55
54
|
preprocessor_cls: type[Preprocessor] | None = None,
|
|
56
|
-
|
|
55
|
+
random_seed: int | None = None,
|
|
57
56
|
epochs: int = 50,
|
|
58
57
|
batch_size: int = 16,
|
|
59
58
|
activation: type[nn.Module] = nn.ReLU,
|
|
60
59
|
lr: float = 2e-1,
|
|
61
60
|
device: DeviceLike | None = None,
|
|
62
61
|
):
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
set_random_seed(random_state)
|
|
62
|
+
if random_seed is not None:
|
|
63
|
+
self.set_random_seed(random_seed)
|
|
66
64
|
|
|
67
65
|
# Init device
|
|
68
66
|
TorchDeviceMixin.__init__(self, device=device)
|
|
@@ -34,13 +34,15 @@ class LightGBM(Emulator):
|
|
|
34
34
|
colsample_bytree: float = 1.0,
|
|
35
35
|
reg_alpha: float = 0.0,
|
|
36
36
|
reg_lambda: float = 0.0,
|
|
37
|
-
|
|
37
|
+
random_seed: int | None = None,
|
|
38
38
|
n_jobs: int | None = 1,
|
|
39
39
|
importance_type: str = "split",
|
|
40
40
|
verbose: int = -1,
|
|
41
41
|
device: DeviceLike = "cpu",
|
|
42
42
|
):
|
|
43
43
|
"""Initializes a LightGBM object."""
|
|
44
|
+
if random_seed is not None:
|
|
45
|
+
self.set_random_seed(random_seed)
|
|
44
46
|
_, _ = x, y # ignore unused arguments
|
|
45
47
|
TorchDeviceMixin.__init__(self, device=device)
|
|
46
48
|
self.boosting_type = boosting_type
|
|
@@ -58,7 +60,7 @@ class LightGBM(Emulator):
|
|
|
58
60
|
self.colsample_bytree = colsample_bytree
|
|
59
61
|
self.reg_alpha = reg_alpha
|
|
60
62
|
self.reg_lambda = reg_lambda
|
|
61
|
-
self.
|
|
63
|
+
self.random_seed = random_seed
|
|
62
64
|
self.n_jobs = n_jobs
|
|
63
65
|
self.importance_type = importance_type
|
|
64
66
|
self.verbose = verbose
|
|
@@ -78,7 +80,7 @@ class LightGBM(Emulator):
|
|
|
78
80
|
colsample_bytree=self.colsample_bytree,
|
|
79
81
|
reg_alpha=self.reg_alpha,
|
|
80
82
|
reg_lambda=self.reg_lambda,
|
|
81
|
-
random_state=self.
|
|
83
|
+
random_state=self.random_seed,
|
|
82
84
|
n_jobs=self.n_jobs,
|
|
83
85
|
importance_type=self.importance_type,
|
|
84
86
|
verbose=self.verbose,
|
|
@@ -58,12 +58,10 @@ class CNPDataset(Dataset, TorchDeviceMixin):
|
|
|
58
58
|
def __getitem__(self, idx):
|
|
59
59
|
return self.sample()
|
|
60
60
|
|
|
61
|
-
def sample(self
|
|
61
|
+
def sample(self):
|
|
62
62
|
"""
|
|
63
63
|
From the full dataset, sample context and target points.
|
|
64
64
|
"""
|
|
65
|
-
if seed is not None:
|
|
66
|
-
np.random.seed(seed)
|
|
67
65
|
|
|
68
66
|
x = self.x
|
|
69
67
|
y = self.y
|
|
@@ -262,6 +260,7 @@ class CNPModule(PyTorchBackend):
|
|
|
262
260
|
offset_context_points: int = 2,
|
|
263
261
|
n_episodes: int = 12,
|
|
264
262
|
batch_size: int = 4,
|
|
263
|
+
random_seed: int | None = None,
|
|
265
264
|
device: DeviceLike | None = None,
|
|
266
265
|
):
|
|
267
266
|
"""
|
|
@@ -294,6 +293,8 @@ class CNPModule(PyTorchBackend):
|
|
|
294
293
|
device: DeviceLike | None
|
|
295
294
|
Device to use for training. If None, use the default device.
|
|
296
295
|
"""
|
|
296
|
+
if random_seed is not None:
|
|
297
|
+
self.set_random_seed(random_seed, deterministic=True)
|
|
297
298
|
super().__init__()
|
|
298
299
|
TorchDeviceMixin.__init__(self, device=device)
|
|
299
300
|
x, y = self._move_tensors_to_device(x, y)
|
|
@@ -25,7 +25,7 @@ class RandomForest(SklearnBackend):
|
|
|
25
25
|
bootstrap: bool = True,
|
|
26
26
|
oob_score: bool = False,
|
|
27
27
|
max_samples: int | None = None,
|
|
28
|
-
|
|
28
|
+
random_seed: int | None = None,
|
|
29
29
|
device: DeviceLike = "cpu",
|
|
30
30
|
):
|
|
31
31
|
"""Initializes a RandomForest object."""
|
|
@@ -40,7 +40,7 @@ class RandomForest(SklearnBackend):
|
|
|
40
40
|
self.bootstrap = bootstrap
|
|
41
41
|
self.oob_score = oob_score
|
|
42
42
|
self.max_samples = max_samples
|
|
43
|
-
self.
|
|
43
|
+
self.random_seed = random_seed
|
|
44
44
|
self.model = RandomForestRegressor(
|
|
45
45
|
n_estimators=self.n_estimators,
|
|
46
46
|
max_depth=self.max_depth,
|
|
@@ -48,7 +48,7 @@ class RandomForest(SklearnBackend):
|
|
|
48
48
|
min_samples_leaf=self.min_samples_leaf,
|
|
49
49
|
max_features=self.max_features,
|
|
50
50
|
bootstrap=self.bootstrap,
|
|
51
|
-
random_state=self.
|
|
51
|
+
random_state=self.random_seed,
|
|
52
52
|
)
|
|
53
53
|
|
|
54
54
|
@staticmethod
|
|
@@ -29,9 +29,12 @@ class SupportVectorMachine(SklearnBackend):
|
|
|
29
29
|
verbose: bool = False,
|
|
30
30
|
max_iter: int = 100,
|
|
31
31
|
normalise_y: bool = True,
|
|
32
|
+
random_seed: int | None = None,
|
|
32
33
|
device: DeviceLike = "cpu",
|
|
33
34
|
):
|
|
34
35
|
"""Initializes a SupportVectorMachines object."""
|
|
36
|
+
if random_seed is not None:
|
|
37
|
+
self.set_random_seed(random_seed)
|
|
35
38
|
_, _, _ = x, y, device # ignore unused arguments
|
|
36
39
|
TorchDeviceMixin.__init__(self, device=device, cpu_only=True)
|
|
37
40
|
self.kernel = kernel
|
|
@@ -70,6 +70,7 @@ def cross_validate(
|
|
|
70
70
|
dataset: Dataset,
|
|
71
71
|
model: type[Emulator],
|
|
72
72
|
device: DeviceLike = "cpu",
|
|
73
|
+
random_seed: int = np.random.randint(int(1e5)),
|
|
73
74
|
**kwargs: Any,
|
|
74
75
|
):
|
|
75
76
|
"""
|
|
@@ -105,7 +106,7 @@ def cross_validate(
|
|
|
105
106
|
|
|
106
107
|
# fit model
|
|
107
108
|
x, y = next(iter(train_loader))
|
|
108
|
-
m = model(x, y, device=device, **best_model_config)
|
|
109
|
+
m = model(x, y, device=device, random_seed=random_seed, **best_model_config)
|
|
109
110
|
m.fit(x, y)
|
|
110
111
|
|
|
111
112
|
# evaluate on batches
|
|
@@ -169,23 +169,13 @@ class HistoryMatching:
|
|
|
169
169
|
|
|
170
170
|
# Need to handle discontinuous NROY spaces
|
|
171
171
|
# i.e., region within min/max bounds is RO
|
|
172
|
-
valid_samples = np.empty((0, nroy_samples.shape[1]))
|
|
173
|
-
while len(valid_samples) < n_samples:
|
|
174
|
-
# Generate candidates
|
|
175
|
-
candidate_samples = np.random.uniform(
|
|
176
|
-
min_bounds, max_bounds, size=(n_samples, nroy_samples.shape[1])
|
|
177
|
-
)
|
|
178
|
-
|
|
179
|
-
# Filter valid samples based on implausibility and concatenate
|
|
180
|
-
implausibility = self.calculate_implausibility(candidate_samples)
|
|
181
|
-
valid_candidates = candidate_samples[implausibility["NROY"]]
|
|
182
|
-
valid_samples = np.concatenate((valid_samples, valid_candidates), axis=0)
|
|
183
172
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
173
|
+
# Generate candidates
|
|
174
|
+
candidate_samples = np.random.uniform(
|
|
175
|
+
min_bounds, max_bounds, size=(n_samples, nroy_samples.shape[1])
|
|
176
|
+
)
|
|
187
177
|
|
|
188
|
-
return
|
|
178
|
+
return candidate_samples
|
|
189
179
|
|
|
190
180
|
def predict(
|
|
191
181
|
self,
|
|
@@ -298,13 +288,22 @@ class HistoryMatching:
|
|
|
298
288
|
|
|
299
289
|
with tqdm(total=n_waves, desc="History Matching", unit="wave") as pbar:
|
|
300
290
|
for wave in range(n_waves):
|
|
291
|
+
# CHECK IF WE HAVE SAMPLES TO PROCESS
|
|
292
|
+
if len(current_samples) == 0:
|
|
293
|
+
print(f"Wave {wave}: No valid samples found, skipping...")
|
|
294
|
+
pbar.update(1)
|
|
295
|
+
continue
|
|
296
|
+
|
|
301
297
|
# Run wave using batch processing
|
|
302
298
|
pred_means, pred_vars, successful_samples = self.predict(
|
|
303
299
|
x=current_samples,
|
|
304
300
|
# Emulate predictions unless emulator_predict=False
|
|
305
301
|
emulator=emulator if emulator_predict else None,
|
|
306
302
|
)
|
|
307
|
-
|
|
303
|
+
if len(successful_samples) == 0:
|
|
304
|
+
print(f"Wave {wave}: All simulations failed, skipping...")
|
|
305
|
+
pbar.update(1)
|
|
306
|
+
continue
|
|
308
307
|
# Calculate implausibility in batch
|
|
309
308
|
implausibility = self.calculate_implausibility(pred_means, pred_vars)
|
|
310
309
|
|
|
@@ -328,18 +327,39 @@ class HistoryMatching:
|
|
|
328
327
|
emulator, successful_samples, pred_means
|
|
329
328
|
)
|
|
330
329
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
330
|
+
# Generate new samples for next wave
|
|
331
|
+
if wave < n_waves - 1:
|
|
332
|
+
if nroy_samples.size > 0:
|
|
333
|
+
# Sample candidates
|
|
334
|
+
candidate_samples = self.sample_nroy(
|
|
335
|
+
nroy_samples, n_samples_per_wave
|
|
336
|
+
)
|
|
337
|
+
|
|
338
|
+
# Filter candidates using emulator before simulation
|
|
339
|
+
if not emulator_predict and emulator is not None:
|
|
340
|
+
pred_means, pred_vars = emulator.predict(
|
|
341
|
+
candidate_samples, return_std=True
|
|
342
|
+
)
|
|
343
|
+
pred_vars = pred_vars**2
|
|
344
|
+
|
|
345
|
+
# Ensure correct shape for single output case
|
|
346
|
+
if len(pred_means.shape) == 1:
|
|
347
|
+
pred_means = pred_means.reshape(-1, 1)
|
|
348
|
+
pred_vars = pred_vars.reshape(-1, 1)
|
|
349
|
+
|
|
350
|
+
implausibility = self.calculate_implausibility(
|
|
351
|
+
pred_means, pred_vars
|
|
352
|
+
)
|
|
353
|
+
current_samples = candidate_samples[
|
|
354
|
+
implausibility["NROY"]
|
|
355
|
+
]
|
|
356
|
+
else:
|
|
357
|
+
current_samples = candidate_samples
|
|
358
|
+
else:
|
|
359
|
+
# If no NROY points, sample from full space
|
|
360
|
+
current_samples = self.simulator.sample_inputs(
|
|
361
|
+
n_samples_per_wave
|
|
362
|
+
)
|
|
343
363
|
pbar.update(1)
|
|
344
364
|
|
|
345
365
|
# Concatenate all samples and implausibility scores
|
|
@@ -401,6 +401,7 @@ class HistoryMatchingDashboard:
|
|
|
401
401
|
self._plot_bayesian_style_comparison(filtered_df, filtered_scores)
|
|
402
402
|
elif plot_type == "Wave Evolution":
|
|
403
403
|
self._plot_wave_evolution(filtered_df, filtered_scores)
|
|
404
|
+
plt.show()
|
|
404
405
|
|
|
405
406
|
except Exception as e:
|
|
406
407
|
plt.figure(figsize=(10, 6))
|
|
@@ -1208,26 +1209,8 @@ class HistoryMatchingDashboard:
|
|
|
1208
1209
|
|
|
1209
1210
|
heading = widgets.HTML(value="<h2>History Matching Dashboard</h2>")
|
|
1210
1211
|
|
|
1211
|
-
instructions = widgets.HTML(
|
|
1212
|
-
value="""
|
|
1213
|
-
<div style="background-color: #f8f9fa; padding: 15px; border-radius: 5px; margin-bottom: 15px;">
|
|
1214
|
-
<h3>Instructions:</h3>
|
|
1215
|
-
<ul>
|
|
1216
|
-
<li><strong>Plot Type</strong>: Select the type of visualization from the dropdown.</li>
|
|
1217
|
-
<li><strong>Threshold</strong>: Adjust the implausibility threshold for NROY classification.</li>
|
|
1218
|
-
<li><strong>Parameters</strong>: Select parameters to visualize (availability depends on plot type).</li>
|
|
1219
|
-
<li><strong>Show only NROY points</strong>: When available, filters to show only viable parameter combinations.</li>
|
|
1220
|
-
<li><strong>Update Plot</strong>: Click to regenerate the visualization with current settings.</li>
|
|
1221
|
-
</ul>
|
|
1222
|
-
<p><em>Note: Some controls are only available for certain plot types.</em></p>
|
|
1223
|
-
</div>
|
|
1224
|
-
"""
|
|
1225
|
-
)
|
|
1226
|
-
|
|
1227
1212
|
# Display the heading and instructions first
|
|
1228
1213
|
display(heading)
|
|
1229
|
-
display(instructions)
|
|
1230
|
-
|
|
1231
1214
|
display(self.main_layout)
|
|
1232
1215
|
# Initialize the first plot
|
|
1233
1216
|
self._update_plot(None)
|