noisy_vector_mapping

This module contains a test noisy function

noisy_vector_mapping.func_wrapper(H, persis_info, sim_specs, libE_info)

Wraps an objective function

noisy_vector_mapping.noisy_function(x)
noisy_vector_mapping.py
 1"""
 2This module contains a test noisy function
 3"""
 4
 5import numpy as np
 6from numpy import cos, sin
 7from numpy.linalg import norm
 8
 9
10def func_wrapper(H, persis_info, sim_specs, libE_info):
11    """
12    Wraps an objective function
13
14    .. seealso::
15        `test_persistent_fd_param_finder.py` <https://github.com/Libensemble/libensemble/blob/develop/libensemble/tests/regression_tests/test_persistent_fd_param_finder.py>`_ # noqa
16    """
17
18    batch = len(H["x"])
19    H0 = np.zeros(batch, dtype=sim_specs["out"])
20
21    for i, x in enumerate(H["x"]):
22        H0["f_val"][i] = noisy_function(x)[H["f_ind"][i]]
23
24    return H0, persis_info
25
26
27def noisy_function(x):
28    """ """
29    x1 = x[0]
30    x2 = x[1]
31    term1 = (4 - 2.1 * x1**2 + (x1**4) / 3) * x1**2
32    term2 = x1 * x2
33    term3 = (-4 + 4 * x2**2) * x2**2
34
35    phi1 = 0.9 * sin(100 * norm(x, 1)) * cos(100 * norm(x, np.inf)) + 0.1 * cos(norm(x, 2))
36    phi1 = phi1 * (4 * phi1**2 - 3)
37
38    phi2 = 0.8 * sin(100 * norm(x, 1)) * cos(100 * norm(x, np.inf)) + 0.2 * cos(norm(x, 2))
39    phi2 = phi2 * (4 * phi2**2 - 3)
40
41    phi3 = 0.7 * sin(100 * norm(x, 1)) * cos(100 * norm(x, np.inf)) + 0.3 * cos(norm(x, 2))
42    phi3 = phi3 * (4 * phi3**2 - 3)
43
44    F = np.zeros(3)
45    F[0] = (1 + 1e-1 * phi1) * term1
46    F[1] = (1 + 1e-2 * phi2) * term2
47    F[2] = (1 + 1e-3 * phi3) * term3
48
49    return F