def test_mapping_to_cube_and_bound(self): """ Test map_to_cube and map_to_bounds. """ self.report('map_to_cube and map_to_bounds') bounds = np.array([[1, 3], [2, 4], [5, 6]]) x = np.array([1.7, 3.1, 5.5]) X = np.array([[1.7, 3.1, 5.5], [2.1, 2.9, 5.0]]) y = np.array([0.35, 0.55, 0.5]) Y = np.array([[0.35, 0.55, 0.5], [0.55, 0.45, 0]]) # Map to cube y_ = general_utils.map_to_cube(x, bounds) Y_ = general_utils.map_to_cube(X, bounds) # Map to Bounds x_ = general_utils.map_to_bounds(y, bounds) X_ = general_utils.map_to_bounds(Y, bounds) # Check if correct. assert np.linalg.norm(y - y_) < 1e-5 assert np.linalg.norm(Y - Y_) < 1e-5 assert np.linalg.norm(x - x_) < 1e-5 assert np.linalg.norm(X - X_) < 1e-5
def _get_mf_cost_function(fidel_bounds, is_0_1): """ Returns the cost function. fidel_bounds are the bounds for the fidelity space and is_0_1 should be true if fidel_bounds is [0,1]^p. """ fidel_dim = len(fidel_bounds) if fidel_dim == 1: fidel_powers = [2] elif fidel_dim == 2: fidel_powers = [3, 2] elif fidel_dim == 3: fidel_powers = [3, 2, 1.5] else: fidel_powers = [3] + list(np.linspace(2, 1.2, fidel_dim-1)) # Define the normalised def _norm_cost_function(norm_z): """ The cost function with normalised coordinates. """ min_cost = 0.05 return min_cost + (1-min_cost) * np.power(norm_z, fidel_powers).sum() # Now return based on whether or not is_0_1 ret = (_norm_cost_function if is_0_1 else lambda z: _norm_cost_function(map_to_cube(z, fidel_bounds))) return ret
def get_normalised_coords(self, Z, X): """ Maps points in the original space to the cube. """ ret_Z = None if Z is None else map_to_cube(Z, self.fidel_bounds) ret_X = None if X is None else map_to_cube(X, self.domain_bounds) return ret_Z, ret_X
def _norm_cost_function(z): """ Normalised cost function. """ return 0.1 + 0.9 * (_unnorm_cost_function( map_to_cube(np.array(z), fidel_bounds)) / max_unnorm_cost)
def get_normalised_domain_coords(self, X): """ Maps points in the original domain to the cube. """ if self.domain_is_normalised: return map_to_cube(X, self.raw_domain.bounds) else: return X
def get_normalised_fidel_coords(self, Z): """ Maps points in the original fidelity space to the cube. """ if self.domain_is_normalised: return map_to_cube(Z, self.raw_fidel_space.bounds) else: return Z
def get_normalised_coords(self, X): """ Maps points in the original space to the unit cube. """ return map_to_cube(X, self.true_dom_bounds)