Beispiel #1
0
  def test_mmd_name(self):
    with self.test_session():
      x = tf.random_uniform((2, 3), seed=1)
      kernel = partial(utils.gaussian_kernel_matrix, sigmas=tf.constant([1.]))
      loss = losses.maximum_mean_discrepancy(x, x, kernel)

      self.assertEquals(loss.op.name, 'MaximumMeanDiscrepancy/value')
 def test_mmd_is_zero_when_inputs_are_same(self):
     with self.test_session():
         x = tf.random_uniform((2, 3), seed=1)
         kernel = partial(utils.gaussian_kernel_matrix,
                          sigmas=tf.constant([1.]))
         self.assertEquals(
             0,
             losses.maximum_mean_discrepancy(x, x, kernel).eval())
    def test_mmd_name(self):
        with self.test_session():
            x = tf.random_uniform((2, 3), seed=1)
            kernel = partial(utils.gaussian_kernel_matrix,
                             sigmas=tf.constant([1.]))
            loss = losses.maximum_mean_discrepancy(x, x, kernel)

            self.assertEquals(loss.op.name, 'MaximumMeanDiscrepancy/value')
Beispiel #4
0
  def test_mmd_is_zero_when_distributions_are_same(self):

    with self.test_session():
      x = tf.random_uniform((1000, 10), seed=1)
      y = tf.random_uniform((1000, 10), seed=3)

      kernel = partial(utils.gaussian_kernel_matrix, sigmas=tf.constant([100.]))
      loss = losses.maximum_mean_discrepancy(x, y, kernel=kernel).eval()

      self.assertAlmostEqual(0, loss, delta=1e-4)
Beispiel #5
0
  def test_fast_mmd_is_similar_to_slow_mmd(self):
    with self.test_session():
      x = tf.constant(np.random.normal(size=(2, 3)), tf.float32)
      y = tf.constant(np.random.rand(2, 3), tf.float32)

      cost_old = MaximumMeanDiscrepancySlow(x, y, [1.]).eval()
      kernel = partial(utils.gaussian_kernel_matrix, sigmas=tf.constant([1.]))
      cost_new = losses.maximum_mean_discrepancy(x, y, kernel).eval()

      self.assertAlmostEqual(cost_old, cost_new, delta=1e-5)
    def test_fast_mmd_is_similar_to_slow_mmd(self):
        with self.test_session():
            x = tf.constant(np.random.normal(size=(2, 3)), tf.float32)
            y = tf.constant(np.random.rand(2, 3), tf.float32)

            cost_old = MaximumMeanDiscrepancySlow(x, y, [1.]).eval()
            kernel = partial(utils.gaussian_kernel_matrix,
                             sigmas=tf.constant([1.]))
            cost_new = losses.maximum_mean_discrepancy(x, y, kernel).eval()

            self.assertAlmostEqual(cost_old, cost_new, delta=1e-5)
    def test_mmd_is_zero_when_distributions_are_same(self):

        with self.test_session():
            x = tf.random_uniform((1000, 10), seed=1)
            y = tf.random_uniform((1000, 10), seed=3)

            kernel = partial(utils.gaussian_kernel_matrix,
                             sigmas=tf.constant([100.]))
            loss = losses.maximum_mean_discrepancy(x, y, kernel=kernel).eval()

            self.assertAlmostEqual(0, loss, delta=1e-4)
Beispiel #8
0
  def test_multiple_sigmas(self):
    with self.test_session():
      x = tf.constant(np.random.normal(size=(2, 3)), tf.float32)
      y = tf.constant(np.random.rand(2, 3), tf.float32)

      sigmas = tf.constant([2., 5., 10, 20, 30])
      kernel = partial(utils.gaussian_kernel_matrix, sigmas=sigmas)
      cost_old = MaximumMeanDiscrepancySlow(x, y, [2., 5., 10, 20, 30]).eval()
      cost_new = losses.maximum_mean_discrepancy(x, y, kernel=kernel).eval()

      self.assertAlmostEqual(cost_old, cost_new, delta=1e-5)
    def test_multiple_sigmas(self):
        with self.test_session():
            x = tf.constant(np.random.normal(size=(2, 3)), tf.float32)
            y = tf.constant(np.random.rand(2, 3), tf.float32)

            sigmas = tf.constant([2., 5., 10, 20, 30])
            kernel = partial(utils.gaussian_kernel_matrix, sigmas=sigmas)
            cost_old = MaximumMeanDiscrepancySlow(x, y,
                                                  [2., 5., 10, 20, 30]).eval()
            cost_new = losses.maximum_mean_discrepancy(x, y,
                                                       kernel=kernel).eval()

            self.assertAlmostEqual(cost_old, cost_new, delta=1e-5)
Beispiel #10
0
    def __init_parameters(self):
        self.tf_x = tf.placeholder(tf.float32, shape=[None, self.input_dim])
        self.tf_source_data = tf.placeholder(tf.float32, shape=[None, self.input_dim])
        self.tf_y = tf.placeholder(tf.float32, shape=[None, self.output_dim])
        self.tf_z = tf.placeholder(tf.float32, shape=[None, self.latent_dim])
        self.trainable_z = tf.get_variable('trainable_latent_value', shape=[self.query_num, self.latent_dim],
                                           initializer=tf.random_normal_initializer(mean=0,stddev=1))

        self.distribute_distance = maximum_mean_discrepancy(self.tf_x, self.tf_source_data)

        self.GAN_params = self.gan(self.tf_x, self.tf_z)
        trainable_fake_data = self.gan.generator(self.trainable_z, reuse=True)
        self.Classifier_params = self.classifier(self.tf_x, self.tf_y, trainable_fake_data, \
                                                 self.trainable_z, self.tf_source_data)

        self.sess = tf.Session()
        self.saver = tf.train.Saver()
        self.sess.run(tf.global_variables_initializer())
Beispiel #11
0
 def test_mmd_is_zero_when_inputs_are_same(self):
   with self.test_session():
     x = tf.random_uniform((2, 3), seed=1)
     kernel = partial(utils.gaussian_kernel_matrix, sigmas=tf.constant([1.]))
     self.assertEquals(0, losses.maximum_mean_discrepancy(x, x, kernel).eval())