Skip to content

Commit

Permalink
Fixes RSS tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dimtsap committed Nov 21, 2022
1 parent 2818b25 commit 38c96f5
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/UQpy/sampling/SimplexSampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def __init__(
self,
nodes: Union[list, Numpy2DFloatArray] = None,
nsamples: PositiveInteger = None,
random_state: RandomStateType = None,
random_state: Union[RandomStateType, np.random.Generator] = None,
):
"""
Generate uniform random samples inside an n-dimensional simplex.
Expand Down
8 changes: 4 additions & 4 deletions tests/unit_tests/sampling/test_adaptive_kriging.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_akmcs_u():
bounds_1 = [[10 ** (-4), 10 ** 3], [10 ** (-3), 10 ** 2], [10 ** (-3), 10 ** 2]]
optimizer1 = MinimizeOptimizer(method='L-BFGS-B', bounds=bounds_1)
gpr = GaussianProcessRegression(kernel=kernel1, hyperparameters=[1, 10 ** (-3), 10 ** (-2)], optimizer=optimizer1,
optimizations_number=10, noise=False, regression_model=LinearRegression(),
optimizations_number=100, noise=False, regression_model=LinearRegression(),
random_state=0)
# OPTIONS: 'U', 'EFF', 'Weighted-U'
learning_function = UFunction(u_stop=2)
Expand All @@ -52,7 +52,7 @@ def test_akmcs_u():
random_state=2)
a.run(nsamples=25, samples=x.samples)

assert a.samples[23, 0] == 4.027342825480197
assert a.samples[23, 0] == -3.781937137406927
assert a.samples[20, 1] == 0.17610325620498946


Expand All @@ -66,7 +66,7 @@ def test_akmcs_expected_feasibility():
bounds_1 = [[10 ** (-4), 10 ** 3], [10 ** (-3), 10 ** 2], [10 ** (-3), 10 ** 2]]
optimizer1 = MinimizeOptimizer(method='L-BFGS-B', bounds=bounds_1)
gpr = GaussianProcessRegression(kernel=kernel1, hyperparameters=[1, 10 ** (-3), 10 ** (-2)], optimizer=optimizer1,
optimizations_number=20, noise=False, regression_model=LinearRegression(),
optimizations_number=100, noise=False, regression_model=LinearRegression(),
random_state=0)
# OPTIONS: 'U', 'EFF', 'Weighted-U'
learning_function = ExpectedFeasibility(eff_a=0, eff_epsilon=2, eff_stop=0.001)
Expand All @@ -75,7 +75,7 @@ def test_akmcs_expected_feasibility():
random_state=2)
a.run(nsamples=25, samples=x.samples)

assert a.samples[23, 0] == 4.553078100499578
assert a.samples[23, 0] == 5.423754197908594
assert a.samples[20, 1] == 2.0355505295053384


Expand Down
40 changes: 20 additions & 20 deletions tests/unit_tests/sampling/test_refined_stratified.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def test_rss_simple_rectangular():
samples_per_iteration=2,
refinement_algorithm=algorithm,
random_state=2)
assert y.samples[16, 0] == 0.06614276178462988
assert y.samples[16, 1] == 0.7836449863362334
assert y.samples[17, 0] == 0.1891972651582183
assert y.samples[17, 1] == 0.2961099664117288
assert y.samples[16, 0] == 0.22677821757428504
assert y.samples[16, 1] == 0.2729789855337742
assert y.samples[17, 0] == 0.07501256574570675
assert y.samples[17, 1] == 0.9321401317029486


def test_rss_simple_voronoi():
Expand All @@ -40,10 +40,10 @@ def test_rss_simple_voronoi():
samples_per_iteration=2,
refinement_algorithm=algorithm,
random_state=2)
assert np.round(y.samples[16, 0], 6) == 0.363793
assert np.round(y.samples[16, 1], 6) == 0.467625
assert np.round(y.samples[17, 0], 6) == 0.424586
assert np.round(y.samples[17, 1], 6) == 0.217301
assert np.round(y.samples[16, 0], 6) == 0.324738
assert np.round(y.samples[16, 1], 6) == 0.488029
assert np.round(y.samples[17, 0], 6) == 0.349367
assert np.round(y.samples[17, 1], 6) == 0.132426


def test_rect_rss():
Expand All @@ -57,10 +57,10 @@ def test_rect_rss():
refinement_algorithm=RandomRefinement(strata=strata))
assert np.allclose(y.samples, np.array([[0.417022, 0.36016225], [1.00011437, 0.15116629],
[0.14675589, 0.5461693], [1.18626021, 0.67278036],
[0.77483124, 0.7176612], [1.7101839, 0.66516741]]))
[1.90711287, 0.04595797], [0.80005026, 0.86428026]]))
assert np.allclose(np.array(y.samplesU01), np.array([[0.208511, 0.36016225], [0.50005719, 0.15116629],
[0.07337795, 0.5461693], [0.59313011, 0.67278036],
[0.38741562, 0.7176612], [0.85509195, 0.66516741]]))
[0.95355644, 0.04595797], [0.40002513, 0.86428026]]))


def test_rect_gerss():
Expand Down Expand Up @@ -123,17 +123,17 @@ def test_vor_gerss():
gpr = GaussianProcessRegression(kernel=kernel1, hyperparameters=[1, 10 ** (-3), 10 ** (-2)], optimizer=optimizer1,
optimizations_number=100, noise=False, regression_model=LinearRegression(),
random_state=0)
z_vor = RefinedStratifiedSampling(stratified_sampling=x_vor, nsamples=6, random_state=x_vor.random_state,
z_vor = RefinedStratifiedSampling(stratified_sampling=x_vor, nsamples=6, random_state=0,
refinement_algorithm=GradientEnhancedRefinement(strata=x_vor.strata_object,
runmodel_object=rmodel,
surrogate=gpr,
nearest_points_number=4))
assert np.allclose(z_vor.samples, np.array([[1.78345908, 0.01640854], [1.46201137, 0.70862104],
[0.4021338, 0.05290083], [0.1062376, 0.88958226],
[0.61246269, 0.47160095], [1.16609055, 0.30832536]]))
[0.66730342, 0.46988084], [1.37411577, 0.39064685]]))
assert np.allclose(z_vor.samplesU01, np.array([[0.89172954, 0.01640854], [0.73100569, 0.70862104],
[0.2010669, 0.05290083], [0.0531188, 0.88958226],
[0.30623134, 0.47160095], [0.58304527, 0.30832536]]))
[0.33365171, 0.46988084], [0.68705789, 0.39064685]]))


def test_rss_random_state():
Expand All @@ -155,17 +155,17 @@ def test_rss_runmodel_object():
marginals = [Uniform(loc=0., scale=2.), Uniform(loc=0., scale=1.)]
strata = RectangularStrata(strata_number=[2, 2])
x = TrueStratifiedSampling(distributions=marginals, strata_object=strata, nsamples_per_stratum=1, random_state=1)
from UQpy.surrogates.kriging.regression_models import LinearRegression
from UQpy.surrogates.kriging.correlation_models import ExponentialCorrelation

K = Kriging(regression_model=LinearRegression(), correlation_model=ExponentialCorrelation(), optimizations_number=20,
correlation_model_parameters=[1, 1], optimizer=MinimizeOptimizer('l-bfgs-b'), )
kernel1 = RBF()
bounds_1 = [[10 ** (-4), 10 ** 3], [10 ** (-3), 10 ** 2], [10 ** (-3), 10 ** 2]]
optimizer1 = MinimizeOptimizer(method='L-BFGS-B', bounds=bounds_1)
gpr = GaussianProcessRegression(kernel=kernel1, hyperparameters=[1, 10 ** (-3), 10 ** (-2)], optimizer=optimizer1,
optimizations_number=100, noise=False, regression_model=LinearRegression(),
random_state=0)
model = PythonModel(model_script='python_model_function.py', model_object_name="y_func")
rmodel = RunModel(model=model)
K.fit(samples=x.samples, values=rmodel.qoi_list)
with pytest.raises(BeartypeCallHintPepParamException):
refinement = GradientEnhancedRefinement(strata=x.strata_object, runmodel_object='abc',
surrogate=K)
surrogate=gpr)
RefinedStratifiedSampling(stratified_sampling=x, samples_number=6, samples_per_iteration=2,
refinement_algorithm=refinement)

Expand Down

0 comments on commit 38c96f5

Please sign in to comment.