示例#1
0
 def setUp(self):
     super().setUp()
     self._solver_cls = deep_evolution_solver.MutationPredictorSolver
     tf.enable_eager_execution()
     self.problem = simple_ising_model.AlternatingChainIsingModel(
         length=20, vocab_size=4)
     self.vocab_size = self.problem.domain.vocab_size
     self.length = self.problem.domain.length
  def test_alternating_chain_model_optima(self):
    model = simple_ising_model.AlternatingChainIsingModel(
        length=4, vocab_size=2)
    actual_optima = model._get_global_optima()
    expected_optima = [[0, 1, 0, 1], [1, 0, 1, 0]]
    self.assertAllClose(actual_optima, expected_optima)

    model = simple_ising_model.AlternatingChainIsingModel(
        length=5, vocab_size=2)
    actual_optima = model._get_global_optima()
    expected_optima = [[0, 1, 0, 1, 0], [1, 0, 1, 0, 1]]
    self.assertAllClose(actual_optima, expected_optima)

    model = simple_ising_model.AlternatingChainIsingModel(
        length=4, vocab_size=4)
    actual_optima = model._get_global_optima()
    expected_optima = [[0, 1, 0, 1], [1, 0, 1, 0], [2, 3, 2, 3], [3, 2, 3, 2]]
    self.assertAllClose(actual_optima, expected_optima)
示例#3
0
 def test_solve(self):
     problem = simple_ising_model.AlternatingChainIsingModel(length=8,
                                                             vocab_size=4)
     solver = deep_evolution_solver.MutationPredictorSolver(
         domain=problem.domain)
     controller.run(problem, solver, num_rounds=20, batch_size=10)
 def test_alternating_chain_model_energy(self):
   model = simple_ising_model.AlternatingChainIsingModel(
       length=4, vocab_size=2)
   inputs = np.array([[0, 1, 0, 1], [1, 0, 1, 0], [1, 0, 1, 1]])
   energy = model(inputs)
   self.assertAllClose(energy, [3., 3., 2.])