Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions doc/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ packaging
numpy
scipy
scikit-learn
pyDOE3
pyDOE3 >= 1.5.0
numpydoc
matplotlib
jenn >= 1.0.2, <2.0
egobox ~= 0.23.0
egobox ~= 0.33.0
smt-design-space-ext
git+https://github.com/hwangjt/sphinx_auto_embed.git # for doc generation
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Cython
packaging
numpy
scipy
scikit-learn >=1.4
pyDOE3
scikit-learn
pyDOE3 >= 1.5.0
numba # JIT compiler
matplotlib # used in examples and tests
pytest # tests runner
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
install_requires=[
"packaging",
"scikit-learn",
"pyDOE3",
"pyDOE3 >= 1.5.0",
"scipy",
"jenn",
],
Expand Down
4 changes: 1 addition & 3 deletions smt/applications/cckrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,7 @@ def grad_minus_cooperative_reduced_likelihood_function(active_log10t):
theta_all_loops = np.vstack((theta0, theta0_rand))

if self.options["n_start"] > 1:
sampling = LHS(
xlimits=theta_limits, criterion="maximin", random_state=41
)
sampling = LHS(xlimits=theta_limits, criterion="maximin", seed=41)
theta_lhs_loops = sampling(self.options["n_start"])
theta_all_loops = np.vstack((theta_all_loops, theta_lhs_loops))

Expand Down
19 changes: 9 additions & 10 deletions smt/applications/ego.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

import time
from types import FunctionType
from typing import Optional

import numpy as np
from scipy.optimize import minimize
Expand All @@ -29,7 +28,7 @@ class Evaluator(object):
User can derive this interface and override the run() method to implement custom multiprocessing.
"""

def run(self, fun, x, design_space: Optional = None):
def run(self, fun, x, design_space=None):
"""
Evaluates fun at x.

Expand All @@ -48,7 +47,7 @@ def run(self, fun, x, design_space: Optional = None):
"""
if (design_space is not None) and np.any(design_space.is_conditionally_acting):
x_corr, eval_is_acting = design_space.correct_get_acting(x)
return fun(x_corr, eval_is_acting)
return fun(x_corr, eval_is_acting=eval_is_acting)

else:
return fun(x)
Expand Down Expand Up @@ -123,9 +122,9 @@ def _initialize(self):
desc="SMT kriging-based surrogate model used internaly",
)
self.options.declare(
"random_state",
types=(type(None), int, np.random.RandomState),
desc="Numpy RandomState object or seed number which controls random draws",
"seed",
types=(type(None), int, np.random.Generator),
desc="Numpy Generator object or seed number which controls random draws",
)

def optimize(self, fun):
Expand Down Expand Up @@ -281,7 +280,7 @@ def _setup_optimizer(self, fun):
self.gpr.options["is_ri"] = self.options["is_ri"]
self.design_space: BaseDesignSpace = self.gpr.design_space
if isinstance(self.design_space, DesignSpace):
self.design_space.seed = self.options["random_state"]
self.design_space.seed = self.options["seed"]

# Handle mixed integer optimization
is_continuous = self.design_space.is_all_cont
Expand All @@ -301,7 +300,7 @@ def _setup_optimizer(self, fun):
work_in_folded_space=True,
)
self._sampling = self.mixint.build_sampling_method(
random_state=self.options["random_state"],
seed=self.options["seed"],
)

else:
Expand All @@ -310,7 +309,7 @@ def _setup_optimizer(self, fun):
LHS,
self.design_space,
criterion="ese",
random_state=self.options["random_state"],
seed=self.options["seed"],
)
self._sampling = lambda n: sampling(n)

Expand Down Expand Up @@ -467,7 +466,7 @@ def _get_virtual_point(self, x, y_data):
conf = -3.0

if qEI == "KBRand":
conf = np.random.randn()
conf = np.random.standard_normal()
pred = self.gpr.predict_values(x)
var = self.gpr.predict_variances(x)

Expand Down
2 changes: 1 addition & 1 deletion smt/applications/mfck.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def train(self):
sampling = LHS(
xlimits=np.stack((lower_bounds, upper_bounds), axis=1),
criterion="ese",
random_state=0,
seed=0,
)
theta_lhs_loops = sampling(self.options["n_start"])
theta0 = np.vstack((theta_ini, theta_lhs_loops))
Expand Down
31 changes: 27 additions & 4 deletions smt/applications/mfk.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@


class NestedLHS(object):
def __init__(self, nlevel, xlimits=None, design_space=None, random_state=None):
def __init__(
self, nlevel, xlimits=None, design_space=None, seed=None, random_state=None
):
"""
Constructor where values of options can be passed in.

Expand All @@ -51,11 +53,32 @@ def __init__(self, nlevel, xlimits=None, design_space=None, random_state=None):
design_space : DesignSpace
The design space with type and bounds for every design variable

random_state : Numpy RandomState object or seed number which controls random draws
seed : Numpy Generator object or seed number which controls random draws

random_state : DEPRECATED use seed. Numpy RandomState object or seed number which controls random draws

"""
self.nlevel = nlevel
self.random_state = random_state
if random_state is None:
self.random_state = np.random.default_rng()
elif isinstance(random_state, np.random.RandomState):
raise ValueError(
"np.random.RandomState object is not handled anymore. Please use seed and np.random.Generator"
)
elif isinstance(random_state, int):
warnings.warn(
"Passing a seed or integer to random_state is deprecated "
"and will raise an error in a future version. Please "
"use seed parameter",
DeprecationWarning,
stacklevel=2,
)
self.random_state = np.random.default_rng(random_state)

if seed is not None:
self.random_state = np.random.default_rng(seed)

if xlimits is None and design_space is None:
raise ValueError(
"Either xlimits or design_space should be specified to have bounds for the sampling."
Expand Down Expand Up @@ -102,7 +125,7 @@ def __call__(self, nb_samples_hifi):
p0 = LHS(
xlimits=np.array(self.design_space.get_unfolded_num_bounds()),
criterion="ese",
random_state=self.random_state,
seed=self.random_state,
)
p0nt0 = p0(nt[0])
if self.design_space:
Expand All @@ -115,7 +138,7 @@ def __call__(self, nb_samples_hifi):
p = LHS(
xlimits=np.array(self.design_space.get_unfolded_num_bounds()),
criterion="ese",
random_state=self.random_state,
seed=self.random_state,
)
pnti = p(nt[i])
if self.design_space:
Expand Down
19 changes: 13 additions & 6 deletions smt/applications/mixed_integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,17 @@ def __init__(self, sampling_method_class, design_space, **kwargs):
or not (enum masks)
"""
self._design_space = design_space

if "random_state" in kwargs:
self._design_space.random_state = kwargs["random_state"]
elif self._design_space.random_state is None:
self._design_space.random_state = 42
raise ValueError(
"random_state is not handled anymore. Please use seed parameter"
)

if "seed" in kwargs:
self._design_space.seed = kwargs["seed"]
elif self._design_space.seed is None:
self._design_space.seed = 42

self._unfolded_xlimits = design_space.get_unfolded_num_bounds()
self._output_in_folded_space = kwargs.get("output_in_folded_space", True)
kwargs.pop("output_in_folded_space", None)
Expand All @@ -57,7 +64,7 @@ def _compute(self, nt, return_is_acting=False):
x_doe, is_acting = self._design_space.sample_valid_x(
nt,
unfolded=not self._output_in_folded_space,
random_state=self._design_space.random_state,
seed=self._design_space.seed,
)
if return_is_acting:
return x_doe, is_acting
Expand Down Expand Up @@ -330,15 +337,15 @@ def __init__(self, design_space, work_in_folded_space=True):
def design_space(self) -> BaseDesignSpace:
return self._design_space

def build_sampling_method(self, random_state=None):
def build_sampling_method(self, seed=None):
"""
Build Mixed Integer LHS ESE sampler.
"""
return_folded = self._work_in_folded_space

def sample(n):
x, _ = self._design_space.sample_valid_x(
n, unfolded=not return_folded, random_state=random_state
n, unfolded=not return_folded, seed=seed
)
return x

Expand Down
2 changes: 1 addition & 1 deletion smt/applications/smfck.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ def train(self):
sampling = LHS(
xlimits=np.stack((lower_bounds, upper_bounds), axis=1),
criterion="ese",
random_state=0,
seed=0,
)
theta_lhs_loops = sampling(self.options["n_start"])
theta0 = np.vstack((theta_ini, theta_lhs_loops))
Expand Down
4 changes: 1 addition & 3 deletions smt/applications/tests/test_cckrg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ def run_cckrg_example():
ncomp = 3

# Initial sampling
samp = LHS(xlimits=prob.xlimits, random_state=42)
np.random.seed(0)
samp = LHS(xlimits=prob.xlimits, seed=42)
xt = samp(50)
yt = prob(xt)
np.random.seed(1)

# Random design variable to component allocation
comps = [*range(ncomp)]
Expand Down
Loading