コード例 #1
0
ファイル: batch_ops_test.py プロジェクト: zhanglang1860/t3f
 def testBatchMultiply(self):
     # Test multiplying batch of TTMatrices by individual numbers.
     tt = initializers.random_matrix_batch(((2, 3), (3, 3)), batch_size=3)
     weights = [0.1, 0, -10]
     actual = batch_ops.multiply_along_batch_dim(tt, weights)
     individual_desired = [weights[i] * tt[i:i + 1] for i in range(3)]
     desired = batch_ops.concat_along_batch_dim(individual_desired)
     with self.test_session() as sess:
         desired_val, acutual_val = sess.run(
             (ops.full(desired), ops.full(actual)))
         self.assertAllClose(desired_val, acutual_val)
コード例 #2
0
ファイル: batch_ops_test.py プロジェクト: zhanglang1860/t3f
 def testConcatMatrixPlaceholders(self):
     # Test concating TTMatrices of unknown batch sizes along batch dimension.
     number_of_objects = tf.placeholder(tf.int32)
     all = initializers.random_matrix_batch(((2, 3), (2, 3)), batch_size=5)
     actual = batch_ops.concat_along_batch_dim(
         (all[:number_of_objects], all[number_of_objects:]))
     with self.test_session() as sess:
         desired_val, actual_val = sess.run(
             (ops.full(all), ops.full(actual)),
             feed_dict={number_of_objects: 2})
         self.assertAllClose(desired_val, actual_val)
コード例 #3
0
ファイル: batch_ops_test.py プロジェクト: towadroid/t3f
    def testConcatMatrix(self):
        # Test concating TTMatrix batches along batch dimension.
        first = initializers.random_matrix_batch(((2, 3), (3, 3)),
                                                 batch_size=1,
                                                 dtype=self.dtype)
        second = initializers.random_matrix_batch(((2, 3), (3, 3)),
                                                  batch_size=4,
                                                  dtype=self.dtype)
        third = initializers.random_matrix_batch(((2, 3), (3, 3)),
                                                 batch_size=3,
                                                 dtype=self.dtype)
        first_res = batch_ops.concat_along_batch_dim((first))
        first_res = ops.full(first_res)
        first_second_res = batch_ops.concat_along_batch_dim((first, second))
        first_second_res = ops.full(first_second_res)
        first_second_third_res = batch_ops.concat_along_batch_dim(
            (first, second, third))
        first_second_third_res = ops.full(first_second_third_res)

        first_full = ops.full(first)
        second_full = ops.full(second)
        third_full = ops.full(third)
        first_desired = first_full
        first_second_desired = tf.concat((first_full, second_full), axis=0)
        first_second_third_desired = tf.concat(
            (first_full, second_full, third_full), axis=0)
        with self.test_session() as sess:
            res = sess.run((first_res, first_second_res,
                            first_second_third_res, first_desired,
                            first_second_desired, first_second_third_desired))
            first_res_val = res[0]
            first_second_res_val = res[1]
            first_second_third_res_val = res[2]
            first_desired_val = res[3]
            first_second_desired_val = res[4]
            first_second_third_desired_val = res[5]
            self.assertAllClose(first_res_val, first_desired_val)
            self.assertAllClose(first_second_res_val, first_second_desired_val)
            self.assertAllClose(first_second_third_res_val,
                                first_second_third_desired_val)
コード例 #4
0
ファイル: riemannian_test.py プロジェクト: zhanglang1860/t3f
 def testProjectWeightedSumMultipleOutputs(self):
   # Test projecting a batch of TT-tensors with providing weights and outputing
   # several TT objects with different weights.
   tens = initializers.random_tensor_batch((2, 3, 4), 3, batch_size=4)
   np.random.seed(0)
   weights = np.random.randn(4, 2).astype(np.float32)
   tangent_tens = initializers.random_tensor((2, 3, 4), 4)
   weighted_sum_1 = weights[0, 0] * tens[0] + weights[1, 0] * tens[1] +\
                    weights[2, 0] * tens[2] + weights[3, 0] * tens[3]
   weighted_sum_2 = weights[0, 1] * tens[0] + weights[1, 1] * tens[1] +\
                    weights[2, 1] * tens[2] + weights[3, 1] * tens[3]
   direct_proj_1 = riemannian.project_sum(weighted_sum_1, tangent_tens)
   direct_proj_2 = riemannian.project_sum(weighted_sum_2, tangent_tens)
   direct_proj_1 = shapes.expand_batch_dim(direct_proj_1)
   direct_proj_2 = shapes.expand_batch_dim(direct_proj_2)
   direct_projs = batch_ops.concat_along_batch_dim((direct_proj_1, direct_proj_2))
   actual_proj = riemannian.project_sum(tens, tangent_tens, weights)
   with self.test_session() as sess:
     res = sess.run((ops.full(direct_projs), ops.full(actual_proj)))
     desired_val, actual_val = res
     self.assertAllClose(desired_val, actual_val, atol=1e-5, rtol=1e-5)