def generate_four_moving_gaussians(x_min=-10,
                                   x_max=10,
                                   y_min=-10,
                                   y_max=10,
                                   size=200,
                                   weights=None):
    if weights is None:
        weights = [1, 1, 1, 1]
    int_gaussians = [None, None, None, None]

    colorschemes = color_schemes.get_colorbrewer_schemes()
    cov_matrix = [[5, 0], [0, 5]]
    z_lists = []
    z_sums = []
    gaussians = []
    for i in range(1, 6):
        int_gaussians[0] = Gaussian(x_min=x_min,
                                    x_max=x_max,
                                    y_min=y_min,
                                    y_max=y_max,
                                    size=size,
                                    means=[+i, +i],
                                    cov_matrix=cov_matrix,
                                    weight=weights[0])
        int_gaussians[1] = Gaussian(x_min=x_min,
                                    x_max=x_max,
                                    y_min=y_min,
                                    y_max=y_max,
                                    size=size,
                                    means=[-i, -i],
                                    cov_matrix=cov_matrix,
                                    weight=weights[1])
        int_gaussians[2] = Gaussian(x_min=x_min,
                                    x_max=x_max,
                                    y_min=y_min,
                                    y_max=y_max,
                                    size=size,
                                    means=[+i, -i],
                                    cov_matrix=cov_matrix,
                                    weight=weights[2])
        int_gaussians[3] = Gaussian(x_min=x_min,
                                    x_max=x_max,
                                    y_min=y_min,
                                    y_max=y_max,
                                    size=size,
                                    means=[-i, +i],
                                    cov_matrix=cov_matrix,
                                    weight=weights[3])
        logger.info(" \n ".join(str(i) for i in int_gaussians))
        z_list = helper.generate_distribution_grids(int_gaussians)
        z_min, z_max, z_sum = helper.generate_weights(z_list)
        z_lists.append(z_list)
        z_sums.append(z_sum)
        gaussians.append([copy.deepcopy(i) for i in int_gaussians])
    return gaussians
def generate_reversed_moving_gaussian(x_min=-10,
                                      x_max=10,
                                      y_min=-10,
                                      y_max=10,
                                      size=200,
                                      weight=0.5):
    variance_x, variance_y = 5, 5

    var_x, var_y = [2, 5, 10, 15, 20], [15, 20]
    gaussians_2d = []

    for i, mu_y in enumerate([5, 2, 0, -2, -5]):
        for j, mu_x in enumerate([5, 2, 0, -2, -5]):
            if mu_y < 0:
                variance_y = var_y[i - 3]
                variance_x = var_x[j]
            else:
                variance_x = 5
            gaussians_2d.append(
                Gaussian(means=[mu_x, mu_y],
                         cov_matrix=[[variance_x, 2], [2, variance_y]],
                         x_min=x_min,
                         x_max=x_max,
                         y_min=y_min,
                         y_max=y_max,
                         size=size,
                         weight=weight))
    return gaussians_2d
Пример #3
0
    def test_generate_crosses_colors(self):
        dist_one_colors = [[0.77647059, 0.85882353, 0.9372549, 1.],
                           [0.12941176, 0.44313725, 0.70980392, 1.],
                           [.12941176, 0.44313725, 0.70980392, 1.],
                           [0.77647059, 0.85882353, 0.9372549, 1.]]

        dist_two_colors = [[0.99607843, 0.92428677, 0.85887397, 1.],
                           [0.99215686, 0.77615063, 0.57159781, 1.],
                           [0.99215686, 0.77615063, 0.57159781, 1.],
                           [0.99607843, 0.92428677, 0.85887397, 1.]]

        dist_1 = Gaussian(means=[1, 0],
                          cov_matrix=[[3, 2], [2, 3]],
                          x_min=self.x_min,
                          x_max=self.x_max,
                          y_min=self.y_min,
                          y_max=self.y_max,
                          size=self.size,
                          weight=self.weight)
        dist_2 = Gaussian(means=[0, 1],
                          cov_matrix=[[6, 2], [2, 6]],
                          x_min=self.x_min,
                          x_max=self.x_max,
                          y_min=self.y_min,
                          y_max=self.y_max,
                          size=self.size,
                          weight=self.weight)
        distributions = [dist_1, dist_2]

        # unpleasant....
        limits = helper.get_limits(distributions)
        z_list = helper.generate_distribution_grids(distributions,
                                                    limits=limits)
        z_min, z_max, z_sum = helper.generate_weights(z_list)
        colorschemes = color_schemes.get_colorbrewer_schemes()

        crosses = picture_cross.generate_crosses(distributions,
                                                 z_list,
                                                 z_min,
                                                 z_max,
                                                 colorschemes,
                                                 method="normal",
                                                 num_of_levels=1)
        np.testing.assert_almost_equal(dist_one_colors, crosses[0][2])
        np.testing.assert_almost_equal(dist_one_colors, crosses[0][3])
        np.testing.assert_almost_equal(dist_two_colors, crosses[1][2])
        np.testing.assert_almost_equal(dist_two_colors, crosses[1][3])
Пример #4
0
    def test_generate_crosses_iso_lines(self):
        dist_one_iso_lines = [0.25, 0.75, 0.75, 0.25]

        dist_two_iso_lines = [
            0.09889134000871382, 0.2966740200253193, 0.2966740200253193,
            0.09889134000871382
        ]
        dist_1 = Gaussian(means=[1, 0],
                          cov_matrix=[[3, 2], [2, 3]],
                          x_min=self.x_min,
                          x_max=self.x_max,
                          y_min=self.y_min,
                          y_max=self.y_max,
                          size=self.size,
                          weight=self.weight)
        dist_2 = Gaussian(means=[0, 1],
                          cov_matrix=[[6, 2], [2, 6]],
                          x_min=self.x_min,
                          x_max=self.x_max,
                          y_min=self.y_min,
                          y_max=self.y_max,
                          size=self.size,
                          weight=self.weight)
        distributions = [dist_1, dist_2]

        # unpleasant....
        limits = helper.get_limits(distributions)
        z_list = helper.generate_distribution_grids(distributions,
                                                    limits=limits)
        z_min, z_max, z_sum = helper.generate_weights(z_list)
        colorschemes = color_schemes.get_colorbrewer_schemes()

        crosses = picture_cross.generate_crosses(distributions,
                                                 z_list,
                                                 z_min,
                                                 z_max,
                                                 colorschemes,
                                                 method="normal",
                                                 num_of_levels=1)
        np.testing.assert_almost_equal(dist_one_iso_lines, crosses[0][4])
        np.testing.assert_almost_equal(dist_two_iso_lines, crosses[1][4])
Пример #5
0
def get_random_gaussian(x_min, x_max, y_min, y_max, variance_min, variance_max, size, scale_factor=1.):
    """
    generates a random gaussian inbetween the given min and max values

    :param x_min: minimal x-value for the x-expectation
    :param x_max: maximal x-value for the x-expectation
    :param y_min: minimal y-value for the y-expectation
    :param y_max: maximal y-value for the y-expectation
    :param variance_min: minimal variance of the gaussian
    :param variance_max: maximal variance of the gaussian
    :param size: shape of the 2D-gaussian (size*size)
    :param scale_factor: scalar for x_min, x_max, y_min, y_max
    :return: 2D-gaussian (size, size)
    """
    mu_x_1 = random.randint(int(x_min * scale_factor), int(x_max * scale_factor))
    mu_y_1 = random.randint(int(y_min * scale_factor), int(y_max * scale_factor))
    cov = np.array([[random.randint(variance_min, variance_max), random.randint(variance_min, variance_max)],
                     [random.randint(variance_min, variance_max), random.randint(variance_min, variance_max)]])
    cov = np.dot(cov, cov.transpose())
    gau = Gaussian([mu_x_1, mu_y_1], np.array(cov), size=size)
    logger.debug(f"Gaussian: {gau}")
    return gau
def generate_default_gaussian(means=None, cov_matrix=None, *args, **kwargs):
    if cov_matrix is None:
        cov_matrix = [[5, 0], [0, 5]]
    if means is None:
        means = [0, 0]
    return Gaussian(means=means, cov_matrix=cov_matrix, *args, **kwargs)
Пример #7
0
    def test_generate_crosses_crosses(self):
        dist_one_first_line = [((1., -4.), (5., 4.440892098500626e-16)),
                               ((-0.181818, -2.818181), (3.818181, 1.181818)),
                               ((-1., -2.), (3., 2.)),
                               ((-1.818181, -1.181818), (2.181818, 2.818181)),
                               ((-3., -4.440892098500626e-16), (1., 4.))]
        dist_one_second_line = [((-1.4721359549995792, -6.47213595499958),
                                 (-5.47213595499958, -2.472135954999579)),
                                ((1.1162821280456323, -3.8837178719543686),
                                 (-2.8837178719543686, 0.11628212804563232)),
                                ((3.0000000000000004, -2.0000000000000004),
                                 (-1.0000000000000004, 2.0000000000000004)),
                                ((4.883717871954369, -0.11628212804563187),
                                 (0.8837178719543681, 3.883717871954369)),
                                ((7.47213595499958, 2.472135954999579),
                                 (3.472135954999579, 6.47213595499958))]
        dist_two_first_line = [
            ((0.0, -7.000000000000002), (8.000000000000002, 1.0)),
            ((-2.363636363636364, -4.636363636363638), (5.636363636363638,
                                                        3.363636363636364)),
            ((-4.000000000000001, -3.000000000000001), (4.000000000000001,
                                                        5.000000000000001)),
            ((-5.636363636363638, -1.3636363636363642), (2.363636363636364,
                                                         6.636363636363638)),
            ((-8.000000000000002, 1.0), (0.0, 9.000000000000002))
        ]
        dist_two_second_line = [((-1.6568542494923806, -8.656854249492383),
                                 (-9.656854249492383, -0.6568542494923806)),
                                ((1.6172644221835126, -5.382735577816489),
                                 (-6.382735577816489, 2.6172644221835126)),
                                ((4.000000000000001, -3.000000000000001),
                                 (-4.000000000000001, 5.000000000000001)),
                                ((6.382735577816488, -0.6172644221835135),
                                 (-1.6172644221835135, 7.382735577816488)),
                                ((9.656854249492383, 2.6568542494923806),
                                 (1.6568542494923806, 10.656854249492383))]

        dist_1 = Gaussian(means=[1, 0],
                          cov_matrix=[[3, 2], [2, 3]],
                          x_min=self.x_min,
                          x_max=self.x_max,
                          y_min=self.y_min,
                          y_max=self.y_max,
                          size=self.size,
                          weight=self.weight)
        dist_2 = Gaussian(means=[0, 1],
                          cov_matrix=[[6, 2], [2, 6]],
                          x_min=self.x_min,
                          x_max=self.x_max,
                          y_min=self.y_min,
                          y_max=self.y_max,
                          size=self.size,
                          weight=self.weight)
        distributions = [dist_1, dist_2]

        # unpleasant....
        limits = helper.get_limits(distributions)
        z_list = helper.generate_distribution_grids(distributions,
                                                    limits=limits)
        z_min, z_max, z_sum = helper.generate_weights(z_list)
        colorschemes = color_schemes.get_colorbrewer_schemes()

        crosses = picture_cross.generate_crosses(distributions,
                                                 z_list,
                                                 z_min,
                                                 z_max,
                                                 colorschemes,
                                                 method="normal",
                                                 num_of_levels=1)
        np.testing.assert_almost_equal(dist_one_first_line,
                                       crosses[0][0],
                                       decimal=5)
        np.testing.assert_almost_equal(dist_one_second_line,
                                       crosses[0][1],
                                       decimal=5)
        np.testing.assert_almost_equal(dist_two_first_line,
                                       crosses[1][0],
                                       decimal=5)
        np.testing.assert_almost_equal(dist_two_second_line,
                                       crosses[1][1],
                                       decimal=5)