forked from SALib/SALib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_hdmr.py
73 lines (53 loc) · 1.96 KB
/
test_hdmr.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
from __future__ import division
from pytest import raises
from SALib.analyze import hdmr
from SALib.sample import latin
from SALib.test_functions import Ishigami, linear_model_1
from SALib.util import read_param_file
def setup_samples(N=10000):
param_file = "src/SALib/test_functions/params/Ishigami.txt"
problem = read_param_file(param_file)
param_values = latin.sample(problem, 10000)
return problem, param_values
def test_insufficient_sample_size():
problem, X = setup_samples()
Y = Ishigami.evaluate(X)
with raises(RuntimeError):
hdmr.analyze(problem, X[:200], Y[:200])
def test_bad_conf_level():
problem, X = setup_samples()
Y = Ishigami.evaluate(X)
with raises(RuntimeError):
hdmr.analyze(problem, X, Y, alpha=1.02)
def test_incorrect_maxorder():
problem, X = setup_samples()
Y = Ishigami.evaluate(X)
with raises(RuntimeError):
hdmr.analyze(problem, X, Y, maxorder=4)
def test_incorrect_maxiter():
problem, X = setup_samples()
Y = Ishigami.evaluate(X)
with raises(RuntimeError):
hdmr.analyze(problem, X, Y, maxiter=1005)
def test_over_bootstrap_sample_size():
problem, X = setup_samples()
Y = Ishigami.evaluate(X)
with raises(RuntimeError):
hdmr.analyze(problem, X, Y, R=10001)
def test_incorrect_maxorder_setting():
problem = {"num_vars": 2, "names": ["x1", "x2"], "bounds": [[0, 1] * 2]}
X = latin.sample(problem, 10000)
Y = linear_model_1.evaluate(X)
with raises(RuntimeError):
hdmr.analyze(problem, X, Y, maxorder=5)
def test_incorrect_lambdax():
problem, X = setup_samples()
Y = Ishigami.evaluate(X)
with raises(RuntimeError):
hdmr.analyze(problem, X, Y, lambdax=11)
def test_dim_mismatch():
problem = {"num_vars": 2, "names": ["x1", "x2"], "bounds": [[0, 1] * 2]}
X = latin.sample(problem, 10000)
Y = linear_model_1.evaluate(X)
with raises(RuntimeError):
hdmr.analyze(problem, X, Y[:-2])