コード例 #1
0
ファイル: test_opt_probs.py プロジェクト: xadahiya/mlrose
    def test_sample_pop():
        """Test sample_pop method"""

        problem = DiscreteOpt(5, OneMax(), maximize=True)

        pop = np.array([[0, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 0],
                        [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]])

        problem.keep_sample = pop
        problem.eval_node_probs()

        sample = problem.sample_pop(100)

        assert (np.shape(sample)[0] == 100 and np.shape(sample)[1] == 5
                and np.sum(sample) > 0 and np.sum(sample) < 500)
コード例 #2
0
ファイル: test_opt_probs.py プロジェクト: xadahiya/mlrose
    def test_eval_node_probs():
        """Test eval_node_probs method"""

        problem = DiscreteOpt(5, OneMax(), maximize=True)

        pop = np.array([[0, 0, 0, 0, 1], [1, 0, 1, 0, 1], [1, 1, 1, 1, 0],
                        [1, 0, 0, 0, 1], [0, 0, 0, 0, 0], [1, 1, 1, 1, 1]])

        problem.keep_sample = pop
        problem.eval_node_probs()

        parent = np.array([2, 0, 1, 0])
        probs = np.array([[[0.33333, 0.66667], [0.33333, 0.66667]],
                          [[1.0, 0.0], [0.33333, 0.66667]],
                          [[1.0, 0.0], [0.25, 0.75]], [[1.0, 0.0], [0.0, 1.0]],
                          [[0.5, 0.5], [0.25, 0.75]]])

        assert (np.allclose(problem.node_probs, probs, atol=0.00001)
                and np.array_equal(problem.parent_nodes, parent))