Esempio n. 1
0
    def __init__(self,
                 power=0.,
                 validate_args=False,
                 parameters=None,
                 name='power_transform'):
        """Instantiates the `PowerTransform` bijector.

    Args:
      power: Python `float` scalar indicating the transform power, i.e.,
        `Y = g(X) = (1 + X * c)**(1 / c)` where `c` is the `power`.
      validate_args: Python `bool` indicating whether arguments should be
        checked for correctness.
      parameters: Locals dict captured by subclass constructor, to be used for
        copy/slice re-instantiation operators.
      name: Python `str` name given to ops managed by this object.

    Raises:
      ValueError: if `power < 0` or is not known statically.
    """
        parameters = dict(locals()) if parameters is None else parameters
        with tf.name_scope(name) as name:
            power = tf.get_static_value(ps.constant(power, name='power'))
            if power is None or power < 0:
                raise ValueError('`power` must be a non-negative TF constant.')
            self._power = power
            super(PowerTransform, self).__init__(forward_min_event_ndims=0,
                                                 validate_args=validate_args,
                                                 parameters=parameters,
                                                 name=name)
Esempio n. 2
0
 def _event_shape_tensor(self, index_points=None):
     index_points = self._get_index_points(index_points)
     if self._is_univariate_marginal(index_points):
         return ps.constant([], dtype=tf.int32)
     else:
         # The examples index is one position to the left of the feature dims.
         examples_index = -(self.kernel.feature_ndims + 1)
         return ps.shape(index_points)[examples_index:examples_index + 1]
Esempio n. 3
0
 def _event_shape_tensor(self, loc=None):
     del loc
     return ps.constant([], dtype=tf.int32)
Esempio n. 4
0
 def test_convert_dimension_to_tensor(self):
     v = ps.constant(tf1.Dimension(1))
     self.assertEqual(1, v)