Exemple #1
0
def test_space(settings_ishigami, seed):
    corners = settings_ishigami['space']['corners']
    space = Space(corners)
    assert space.max_points_nb == np.inf

    space = Space(corners, sample=10)
    assert space.max_points_nb == 10

    space = Space(corners, sample=10, nrefine=6,
                  plabels=['x', 'y', 'z'])

    assert space.max_points_nb == 16

    space += (1, 2, 3)
    npt.assert_array_equal(space.values, [(1, 2, 3)])

    space.empty()
    npt.assert_array_equal(space.values, np.empty((0, 3)))

    space += [(1, 2, 3), (1, 1, 3)]
    npt.assert_array_equal(space.values, [(1, 2, 3), (1, 1, 3)])

    space2 = Space(corners, space.values)
    npt.assert_array_equal(space2.values, [(1, 2, 3), (1, 1, 3)])

    s1 = space.sampling()
    assert len(s1) == 10
    space2 = Space(corners,
                   sample=settings_ishigami['space']['sampling']['init_size'],
                   nrefine=settings_ishigami['space']['resampling']['resamp_size'])

    s2 = space2.sampling(10, kind='lhsc')
    assert len(s2) == 10
    assert np.any(s1 != s2)

    space.empty()
    space += (1, 2, 3)
    space += (1, 2, 3)
    assert len(space) == 1

    space = Space(corners, sample=16, duplicate=True)
    space += (1, 2, 3)
    space += (1, 2, 3)
    assert len(space) == 2

    with pytest.raises(ValueError):
        space += (1, 2)
    assert len(space) == 2

    space += (1, 7, 3)
    assert len(space) == 2

    space.sampling(17)
    assert len(space) == 16

    space.empty()
    dists = ['Uniform(0., 1.)', 'Uniform(-1., 2.)', 'Uniform(-2., 3.)']
    space.sampling(5, kind='halton', dists=dists)
    out = [(0.5, 0.0, -1.0), (0.25, 1.0, 0.0), (0.75, -0.67, 1.0),
           (0.125, 0.33, 2.0), (0.625, 1.33, -1.8)]
    npt.assert_almost_equal(space, out, decimal=1)

    space = Space(corners, sample=np.array([(1, 2, 3), (1, 1, 3)]))
    assert space.doe_init == 2
    assert space.max_points_nb == 2

    test_settings = copy.deepcopy(settings_ishigami)
    test_settings['space']['corners'][1] = [np.pi, -np.pi, np.pi]
    with pytest.raises(ValueError):
        Space(test_settings['space']['corners'])
Exemple #2
0
    for s, r in zip(sample_success, density_success):
        r = r if r > min_radius else min_radius
        sample_ += random_uniform_ring(center=s,
                                       r_outer=r,
                                       n_samples=n_resamples)

    for s, r in zip(sample_failure, density_failure):
        r = r if r > min_radius else min_radius
        sample_ += random_uniform_ring(center=s,
                                       r_outer=r,
                                       n_samples=n_resamples)

    sample_scaled = np.concatenate([sample_scaled, sample_])
    data = np.concatenate([data, fun(scaler_inverse_transform(sample_))])

sample.empty()
sample += scaler_inverse_transform(sample_scaled)
doe(sample, fname='final_doe.pdf')

# Analysis
print(f'\n########### N-samples ###########\n {sample.shape}')

# Filtering in/out
mask_threashold = data >= threashold
mask_threashold = mask_threashold.flatten()
inv_mask_threashold = np.logical_not(mask_threashold)

sample_in = sample[mask_threashold]
sample_out = sample[inv_mask_threashold]

ratio = len(sample_in) / len(sample) * 100