コード例 #1
0
ファイル: cost_functions.py プロジェクト: narg95/goldenberry
 def test_statistics(self):
     sample1, cost1 = np.array([[0, 1, 1, 1, 0]]), 3.0
     sample2, cost2 = np.array([[0, 0, 0, 1, 1]]), 2.0
     sample3, cost3 = np.array([[0, 1, 1, 1, 1]]), 4.0
     func = GbCostFunction(OneMax)
     exp_cost1 = func(sample1)
     exp_cost2 = func(sample2)
     exp_cost3 = func(sample3)
     evals, argmin, argmax, min, max, mean, stdev = func.statistics()
     self.assertEqual((evals, argmin, argmax, min, max, mean),
                      (3, 2, 3, cost2, cost3, 3.0))
     self.assertAlmostEqual(stdev, np.sqrt(2.0 / 3.0), 5)
コード例 #2
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic(self):
     cga = Cga()
     cga.setup(20)
     cga.cost_func = GbCostFunction(OneMax, var_size=10)
     result = cga.search()
     self.assertTrue(result.params.all())
     self.assertGreaterEqual(result.cost, 8)
コード例 #3
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic(self):
     pbil = Pbil()
     pbil.setup(20)
     pbil.cost_func = GbCostFunction(OneMax, var_size=10)
     result = pbil.search()
     self.assertTrue(result.params.all())
     self.assertGreaterEqual(result.cost, 8)
コード例 #4
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic_search_zero(self):
     """Test class for the Bmda algorithm"""
     bmda = Bmda()
     bmda.setup(40)
     bmda.cost_func = GbCostFunction(ZeroMax, var_size=10)
     result = bmda.search()
     self.assertTrue((result.params + 1).all())
     self.assertGreaterEqual(result.cost, 8.0)
コード例 #5
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic_search_onemax(self):
     """Test class for the Bmda algorithm"""
     bmda = Bmda()
     bmda.setup(10, 40)
     bmda.cost_func = GbCostFunction(OneMax)
     result = bmda.search()
     self.assertGreaterEqual(result.params.sum(), 8.0)
     self.assertGreaterEqual(result.cost, 8.0)
コード例 #6
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic_search_onemax_mi_method(self):
     """Test class for the Bmda algorithm"""
     bmda = Bmda()
     bmda.setup(40, dependency_method=DependencyMethod.mi)
     bmda.cost_func = GbCostFunction(OneMax, var_size=10)
     result = bmda.search()
     self.assertGreaterEqual(result.params.sum(), 8.0)
     self.assertGreaterEqual(result.cost, 8.0)
コード例 #7
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_reset(self):
     cga = Cga()
     cga.setup(20)
     cga.cost_func = GbCostFunction(OneMax, var_size=10)
     cga.search()
     cga.reset()
     self.assertEqual(cga.iters, 0)
     self.assertNotEqual(cga.distr, None)
     self.assertEqual(cga.cost_func.evals, 0)
コード例 #8
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic_search_onemax(self):
     """Test class for the Bmda algorithm"""
     var_size = 10
     bmda = Bmda()
     bmda.setup(40)
     bmda.cost_func = GbCostFunction(OneMax, var_size=var_size)
     result = bmda.search()
     self.assertTrue((result.params + 1).all())
     self.assertGreaterEqual(result.cost, var_size * 0.8)
コード例 #9
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_reset(self):
     pbil = Pbil()
     pbil.setup(20)
     pbil.cost_func = GbCostFunction(OneMax, var_size=10)
     pbil.search()
     pbil.reset()
     self.assertEqual(pbil.iters, 0)
     self.assertNotEqual(pbil.distr, None)
     self.assertEqual(pbil.cost_func.evals, 0)
コード例 #10
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_reset(self):
     tilda = Tilda()
     tilda.setup(20)
     tilda.cost_func = GbCostFunction(OneMax, var_size=10)
     result = tilda.search()
     tilda.reset()
     self.assertEqual(tilda.iters, 0)
     self.assertNotEqual(tilda.distr, None)
     self.assertEqual(tilda.cost_func.evals, 0)
コード例 #11
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_reset(self):
     """Test if the reset function allows a new algorithm execution."""
     bmda = Bmda()
     bmda.setup(40)
     bmda.cost_func = GbCostFunction(OneMax, var_size=10)
     bmda.search()
     bmda.reset()
     self.assertEqual(bmda.iters, 0)
     self.assertIsNotNone(bmda.distr)
     self.assertEqual(bmda.cost_func.evals, 0)
コード例 #12
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic(self):
     total_runs = 10
     opttester = GbBlackBoxTester()
     optimizer = Cga()
     optimizer.setup(20)
     optimizer.cost_func = GbCostFunction(OneMax, var_size=10)
     run_results, test_results, candidates = opttester.test(
         optimizer, total_runs)
     self.assertEqual(len(run_results), total_runs)
     self.assertEqual(12, len(test_results))
コード例 #13
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_ready(self):
     pbil = Pbil()
     pbil.setup(20)
     self.assertFalse(pbil.ready())
     pbil.cost_func = GbCostFunction(OneMax, var_size=10)
     self.assertTrue(pbil.ready())
コード例 #14
0
ファイル: cost_functions.py プロジェクト: narg95/goldenberry
 def test_custom_function(self):
     sample = np.array([[0, 1, 0, 1, 0]])
     cust = GbCostFunction(
         script=
         "def mycustomfunction(solution):\n\treturn solution.sum() - 1.0")
     self.assertEqual(cust.cost(sample), 1.0)
コード例 #15
0
ファイル: cost_functions.py プロジェクト: narg95/goldenberry
 def test_onemax(self):
     sample = np.array([[0, 1, 0, 1, 0]])
     func = GbCostFunction(OneMax)
     self.assertEqual(func(sample), 2)
コード例 #16
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_ready(self):
     cga = Cga()
     cga.setup(20)
     self.assertFalse(cga.ready())
     cga.cost_func = GbCostFunction(OneMax, var_size=10)
     self.assertTrue(cga.ready())
コード例 #17
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic(self):
     pbilc = Pbilc()
     pbilc.setup(30, learning_rate=0.5, max_evals=1000)
     pbilc.cost_func = GbCostFunction(OneMax, var_size=10)
     result = pbilc.search()
     self.assertGreaterEqual(result.cost, 8)
コード例 #18
0
ファイル: cost_functions.py プロジェクト: narg95/goldenberry
 def test_zero(self):
     sample = np.array([[0, 1, 0, 1, 0]])
     func = GbCostFunction(ZeroMax)
     self.assertEqual(func(sample), 3)
コード例 #19
0
ファイル: test_edas.py プロジェクト: narg95/goldenberry
 def test_basic(self):
     tilda = Tilda()
     tilda.setup(40, learning_rate=0.3, max_evals=10000)
     tilda.cost_func = GbCostFunction(OneMax, var_size=10)
     result = tilda.search()
     self.assertGreaterEqual(result.cost, 8.0)