def test_eval_mate_probs(): """Test eval_mate_probs method""" problem = OptProb(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.set_population(pop) problem.eval_mate_probs() probs = np.array([0.06667, 0.2, 0.26667, 0.13333, 0, 0.33333]) assert np.allclose(problem.get_mate_probs(), probs, atol=0.00001)
def test_eval_mate_probs_all_zero(): """Test eval_mate_probs method when all states have zero fitness""" problem = OptProb(5, OneMax(), maximize=True) pop = np.array([[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]) problem.set_population(pop) problem.eval_mate_probs() probs = np.array( [0.16667, 0.16667, 0.16667, 0.16667, 0.16667, 0.16667]) assert np.allclose(problem.get_mate_probs(), probs, atol=0.00001)