def test_fixedpoint_cm_5(self):
        """test with 3 classes of cardinality 1
        and no zero degrees
        """
        A = np.array([
            [0, 0, 1],
            [0, 0, 1],
            [1, 1, 0],
        ])

        g = sample.UndirectedGraph(A)

        g._solve_problem(
            model="cm-new",
            method="quasinewton",
            initial_guess="random",
            max_steps=100,
            verbose=False,
            linsearch=True,
        )

        g.solution_error()
        # print('degseq = ', np.concatenate((g.dseq_out, g.dseq_in)))
        # print('expected degseq = ',g.expected_dseq)
        # debug
        # print(g.r_dseq_out)
        # print(g.r_dseq_in)
        # print(g.rnz_dseq_out)
        # print(g.rnz_dseq_in)
        # print('\ntest 5: error = {}'.format(g.error))

        # test result
        self.assertTrue(g.error < 1e-1)
    def test_fixedpoint_cm_9(self):
        """classes with cardinality more than 1 and zero degrees"""
        # test Matrix 1
        n, seed = (100, 22)
        A = mg.random_binary_matrix_generator_dense(n, sym=True, seed=seed)

        g = sample.UndirectedGraph(A)

        g._solve_problem(
            model="cm-new",
            method="quasinewton",
            initial_guess="random",
            max_steps=300,
            verbose=False,
            linsearch="True",
        )

        g.solution_error()
        # print('degseq = ', np.concatenate((g.dseq_out, g.dseq_in)))
        # print('expected degseq = ',g.expected_dseq)
        # debug
        # print(g.r_dseq_out)
        # print(g.r_dseq_in)
        # print(g.rnz_dseq_out)
        # print(g.rnz_dseq_in)
        # print('\ntest 9: error = {}'.format(g.error))

        # test result
        self.assertTrue(g.error < 1e-1)
コード例 #3
0
    def test_CReAMa_original_quasinewton_random_dense_20_undir(self):

        network = mg.random_weighted_matrix_generator_dense(n=20,
                                                            sup_ext=10,
                                                            sym=False,
                                                            seed=None)
        network_bin = (network > 0).astype(int)

        g = sample_und.UndirectedGraph(adjacency=network)

        g.solve_tool(
            model="CReAMa",
            method="newton",
            initial_guess="random",
            adjacency=network_bin,
            max_steps=1000,
            verbose=False,
        )

        g.solution_error()

        # test result

        self.assertTrue(g.relative_error_strength < 1e-1)
        self.assertTrue(g.relative_error_strength < 1e-2)
コード例 #4
0
    def test_cm_uniform(self):
        n, seed = (4, 22)
        A = mg.random_binary_matrix_generator_dense(n, sym=True, seed=seed)

        g = sample_u.UndirectedGraph(A)
        g.initial_guess = 'uniform'
        g.last_model = "cm"
        g._set_initial_guess('cm')

        self.assertTrue(g.x0.all() == np.array([0.5, 0.5]).all())
コード例 #5
0
    def test_cm(self):
        n, seed = (4, 22)
        A = mg.random_binary_matrix_generator_dense(n, sym=True, seed=seed)

        x0 = np.random.rand(n)
        g = sample_u.UndirectedGraph(A)
        g.initial_guess = x0
        g._set_initial_guess_cm()
        g.full_return = False
        g.last_model = "cm"
        g._set_solved_problem_cm(g.x0)
        self.assertTrue(g.x.all() == x0.all())
コード例 #6
0
    def test_ecm(self):
        n, seed = (4, 22)
        A = mg.random_weighted_matrix_generator_dense(n,
                                                      sym=False,
                                                      seed=seed,
                                                      sup_ext=100,
                                                      intweights=True)

        x0 = np.random.rand(n)
        g = sample_u.UndirectedGraph(A)
        g.initial_guess = x0
        g._set_initial_guess_CReAMa()
        self.assertTrue(g.x0.all() == x0.all())
コード例 #7
0
    def test_CREAMA_uniform(self):
        n, seed = (4, 22)
        A = mg.random_weighted_matrix_generator_dense(n,
                                                      sym=False,
                                                      seed=seed,
                                                      sup_ext=100,
                                                      intweights=True)

        g = sample_u.UndirectedGraph(A)
        g.initial_guess = 'strengths_minor'
        g._set_initial_guess('CReAMa')

        x = (g.strength_sequence > 0).astype(float) / (g.strength_sequence + 1)
        self.assertTrue(g.x0.all() == x.all())
コード例 #8
0
    def test_CREAMA(self):
        n, seed = (4, 22)
        A = mg.random_weighted_matrix_generator_dense(n,
                                                      sym=False,
                                                      seed=seed,
                                                      sup_ext=100,
                                                      intweights=True)

        x0 = np.random.rand(n)
        g = sample_u.UndirectedGraph(A)
        g.initial_guess = x0
        g._set_initial_guess_CReAMa()
        g.full_return = False
        g._set_solved_problem_CReAMa(g.x0)
        self.assertTrue(g.beta.all() == x0.all())
コード例 #9
0
    def test_ECM_Dianati_random_dense_20_undir(self):

        network = mg.random_weighted_matrix_generator_dense(n=20,
                                                            sup_ext=10,
                                                            sym=True,
                                                            seed=None,
                                                            intweights=True)
        network_bin = (network > 0).astype(int)

        g = sample_und.UndirectedGraph(adjacency=network)

        g.solve_tool(
            model="ecm",
            method="quasinewton",
            max_steps=1000,
            verbose=False,
            initial_guess="random",
        )

        g.solution_error()

        # test result
        self.assertTrue(g.error < 1e-1)