Exemplo n.º 1
0
def test_regression_hdmr_case3():
    problem = {
        'num_vars': 5,
        'names': ['x1', 'x2', 'x3', 'x4', 'x5'],
        'bounds': [[0, 1] * 5]
    }
    # Generate correlated samples
    mean = np.zeros((problem['num_vars']))
    cov = [[1, 0.6, 0.2, 0, 0], [0.6, 1, 0.2, 0, 0], [0.2, 0.2, 1, 0, 0],
           [0, 0, 0, 1, 0.2], [0, 0, 0, 0.2, 1]]
    X = np.random.multivariate_normal(mean, cov, 10000)
    Y = linear_model_2.evaluate(X)
    options = {
        'maxorder': 2,
        'maxiter': 100,
        'm': 2,
        'K': 1,
        'R': 10000,
        'alpha': 0.95,
        'lambdax': 0.01,
        'print_to_console': False
    }
    Si = hdmr.analyze(problem, X, Y, **options)
    assert_allclose(Si['Sa'][0:problem['num_vars']],
                    [0.28, 0.17, 0.10, 0.04, 0.02],
                    atol=5e-2,
                    rtol=1e-1)
    assert_allclose(Si['Sb'][0:problem['num_vars']],
                    [0.16, 0.16, 0.06, 0.00, 0.00],
                    atol=5e-2,
                    rtol=1e-1)
Exemplo n.º 2
0
def test_regression_hdmr_case1():
    problem = {
        'num_vars': 5,
        'names': ['x1', 'x2', 'x3', 'x4', 'x5'],
        'bounds': [[0, 1] * 5]
    }
    X = latin.sample(problem, 10000)
    Y = linear_model_1.evaluate(X)
    options = {
        'maxorder': 2,
        'maxiter': 100,
        'm': 2,
        'K': 1,
        'R': 10000,
        'alpha': 0.95,
        'lambdax': 0.01,
        'print_to_console': False
    }
    Si = hdmr.analyze(problem, X, Y, **options)
    assert_allclose(Si['Sa'][0:problem['num_vars']], [0.20] * 5,
                    atol=5e-2,
                    rtol=1e-1)
    assert_allclose(Si['ST'][0:problem['num_vars']], [0.20] * 5,
                    atol=5e-2,
                    rtol=1e-1)
Exemplo n.º 3
0
def test_regression_hdmr_ishigami():
    param_file = 'src/SALib/test_functions/params/Ishigami.txt'
    problem = read_param_file(param_file)
    X = latin.sample(problem, 10000)
    Y = Ishigami.evaluate(X)
    options = {
        'maxorder': 2,
        'maxiter': 100,
        'm': 4,
        'K': 1,
        'R': 10000,
        'alpha': 0.95,
        'lambdax': 0.01,
        'print_to_console': False
    }
    Si = hdmr.analyze(problem, X, Y, **options)
    assert_allclose(Si['Sa'][0:problem['num_vars']], [0.31, 0.44, 0.00],
                    atol=5e-2,
                    rtol=1e-1)
    assert_allclose(Si['ST'][0:problem['num_vars']], [0.55, 0.44, 0.24],
                    atol=5e-2,
                    rtol=1e-1)
Exemplo n.º 4
0
sigma = np.var(Y) / 100

# SALib-HDMR options
options = {
    'maxorder': 2,
    'maxiter': 100,
    'm': 4,
    'K': 30,
    'R': 500,
    'alpha': 0.95,
    'lambdax': 0.01,
    'print_to_console': True,
    'seed': 101
}
# Run SALib-HDMR
Si = hdmr.analyze(problem, X, Y, **options)

# Displays sensitivity results and HDMR training results
Si.plot()

# Generate samples
X = latin.sample(problem, 5000, seed=int(np.random.random() * 100))
# Run the "model"
Y = Ishigami.evaluate(X)

# Test emulator with new Y values.
# Can call `emulate()` without Y values, which will run the emulator
# Emulation results will be in Si["emulated"]
Si.emulate(X, Y)

# Displays results for both training and testing after emulator is tested.
Exemplo n.º 5
0
def test_incorrect_lambdax():
    problem, X = setup_samples()
    Y = Ishigami.evaluate(X)
    with raises(RuntimeError):
        hdmr.analyze(problem, X, Y, lambdax=11)
Exemplo n.º 6
0
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])
Exemplo n.º 7
0
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)
Exemplo n.º 8
0
def test_over_bootstrap_sample_size():
    problem, X = setup_samples()
    Y = Ishigami.evaluate(X)
    with raises(RuntimeError):
        hdmr.analyze(problem, X, Y, R=10001)
Exemplo n.º 9
0
def test_incorrect_maxiter():
    problem, X = setup_samples()
    Y = Ishigami.evaluate(X)
    with raises(RuntimeError):
        hdmr.analyze(problem, X, Y, maxiter=1005)
Exemplo n.º 10
0
def test_bad_conf_level():
    problem, X = setup_samples()
    Y = Ishigami.evaluate(X)
    with raises(RuntimeError):
        hdmr.analyze(problem, X, Y, alpha=1.02)
Exemplo n.º 11
0
def test_insufficient_sample_size():
    problem, X = setup_samples()
    Y = Ishigami.evaluate(X)
    with raises(RuntimeError):
        hdmr.analyze(problem, X[:200], Y[:200])