def test_full_ising_model_single(self):
   connected = simple_ising_model.IsingModel(
       length=5, vocab_size=3, fully_connected=True)
   output = connected(np.array([[1, 1, 1, 1, 1]]))
   self.assertEqual(3, connected.domain.vocab_size)
   self.assertEqual(5, connected.domain.length)
   self.assertAlmostEqual(-2.47013903, output[0].numpy(), delta=1e-5)
  def test_full_ising_model(self, batch_size, length, vocab_size):
    full = simple_ising_model.IsingModel(
        length=length, vocab_size=vocab_size, fully_connected=True)
    variables = tf.random_uniform(
        shape=[batch_size, length], minval=0, maxval=vocab_size, dtype=tf.int32)
    output = full(variables)

    expected = _manual_full_model(variables, full.potentials)
    self.assertAllClose(expected, output.numpy())

    # Check that it can run with one-hot inputs.
    output = full(tf.one_hot(variables, depth=vocab_size))
    self.assertAllClose(expected, output.numpy())
 def test_local_ising_model_single(self):
   local = simple_ising_model.IsingModel(
       length=5, vocab_size=3, fully_connected=False)
   output = local(np.array([[1, 1, 1, 1, 1]]))
   self.assertAlmostEqual(3.23183179, output[0].numpy(), delta=1e-5)