Ejemplo n.º 1
0
    def test_equivalence(self):
        """
        Make sure chaining with identity doesn't lead to different values.
        """
        with self.test_context() as session:
            x, x_np, transforms = self.prepare()
            for transform in transforms:
                equiv_transforms = [transform,
                                    Chain(transform, Identity()),
                                    Chain(Identity(), transform)]

                ys_np = [t.forward(x_np) for t in equiv_transforms]
                self.assertEqualElements(ys_np)

                y_np = ys_np[0]
                xs_np = [t.backward(y_np) for t in equiv_transforms]
                self.assertEqualElements(xs_np)

                ys = [t.forward_tensor(x) for t in equiv_transforms]
                ys_tf = [session.run(y) for y in ys]
                self.assertEqualElements(ys_tf)

                logjs = [t.log_jacobian_tensor(x) for t in equiv_transforms]
                logjs_tf = [session.run(logj) for logj in logjs]
                self.assertEqualElements(logjs_tf)
Ejemplo n.º 2
0
    def prepare(self):
        x_np = np.random.randn(10).astype(settings.float_type)
        transforms = []
        for transform_class in gpflow.transforms.Transform.__subclasses__():
            if transform_class == Chain:
                continue  # Chain transform cannot be tested on its own
            if transform_class == gpflow.transforms.LowerTriangular:
                transforms.append(transform_class(4))
            elif transform_class == gpflow.transforms.DiagMatrix:
                transforms.append(transform_class(5))
            else:
                transform = transform_class()
                transforms.append(transform)
                transforms.append(Chain(Identity(), transform))
                transforms.append(Chain(transform, Identity()))

        transforms.append(gpflow.transforms.Logistic(7.3, 19.4))

        # test __call__() and chaining:
        transforms.append(gpflow.transforms.positive(gpflow.transforms.Rescale(7.5)))
        transforms.append(gpflow.transforms.Rescale(9.5)(gpflow.transforms.positive))

        # test helper:
        transforms.append(gpflow.transforms.positiveRescale(9.5))

        return tf.convert_to_tensor(x_np), x_np, transforms
Ejemplo n.º 3
0
 def prepare(self):
     x = tf.placeholder(settings.np_float, 10)
     x_np = np.random.randn(10).astype(settings.np_float)
     transforms = []
     for transform_class in gpflow.transforms.Transform.__subclasses__():
         if transform_class == Chain:
             continue  # Chain transform cannot be tested on its own
         if transform_class == gpflow.transforms.LowerTriangular:
             transforms.append(transform_class(4))
         else:
             transform = transform_class()
             transforms.append(transform)
             transforms.append(Chain(Identity(), transform))
             transforms.append(Chain(transform, Identity()))
     #self.transforms = [C() for C in gpflow.transforms.Transform.__subclasses__()]
     transforms.append(gpflow.transforms.Logistic(7.3, 19.4))
     transforms.append(
         gpflow.transforms.positive(gpflow.transforms.Rescale(
             9.5)))  # test __call__() and chaining
     transforms.append(
         gpflow.transforms.Rescale(9.5)(
             gpflow.transforms.positive))  # test __call__() and chaining
     return x, x_np, transforms