Exemplo n.º 1
0
 def island(self, x: np.ndarray) -> np.ndarray:
     """
     Generator function of 2D vectors of class 0 (the island in the center)
     :param x: a 2D random generated vector
     :return: the corresponding individual of class 0
     """
     cartesian = polar_to_cartesian(random_to_polar(x))
     f = cartesian * self.island_radius + self.island_origin
     return f
Exemplo n.º 2
0
 def sea(self, x: np.array):
     """
     Generator function of 2D vectors of class 0 (the ring around the island)
     :param x: a 2D random generated vector
     :return: the corresponding individual of class 0
     """
     polar = random_to_polar(x)
     polar[0] = polar[0] * self.sea_width + self.sea_inner_diameter
     cartesian = polar_to_cartesian(
         polar) * self.sea_scale + self.island_origin
     return cartesian
Exemplo n.º 3
0
 def swirl(self, x: np.array, phase):
     """
     Generates individuals of a swirl with a given phase
     :param x: a random 2D array of scalars between 0 and 1
     :param phase: the swirl phase
     :return: a swirl individual
     """
     polar = random_to_polar(x)
     polar[1] = polar[1] * self.turns + phase
     distance_offset = polar[0] * self.arm_max_offset
     angle_offset = polar[1] - np.pi
     polar_offset = np.array([distance_offset, angle_offset])
     polar[0] = (polar[1] - phase) / (self.turns * 4 * np.pi)
     cartesian = polar_to_cartesian(polar)
     if (polar[1] - phase) < np.pi:
         polar_offset[0] *= (polar[1] - phase) / np.pi
     cartesian_offset = polar_to_cartesian(polar_offset)
     cartesian += cartesian_offset
     f = cartesian * self.scale + self.origin
     return f
Exemplo n.º 4
0
 def unitary_cluster(self, x: np.array):
     polar = random_to_polar(x)
     polar[0] = 11.**polar[0] / 10. - 0.6
     f = polar_to_cartesian(polar)
     return f
Exemplo n.º 5
0
def test_random_to_polar(x: np.array, expected: np.array):
    actual = random_to_polar(x)
    assert_array_almost_equal(actual, expected, verbose=True)