def __init__(self, logits, dtype=None, group_event_ndims=0): self._logits = tf.convert_to_tensor(logits) param_dtype = assert_same_float_dtype( [(self._logits, 'Categorical.logits')]) if dtype is None: dtype = tf.int32 assert_same_float_and_int_dtype([], dtype) static_logits_shape = self._logits.get_shape() shape_err_msg = "logits should have rank >= 1." if static_logits_shape and (static_logits_shape.ndims < 1): raise ValueError(shape_err_msg) elif static_logits_shape and ( static_logits_shape[-1].value is not None): self._n_categories = static_logits_shape[-1].value else: _assert_shape_op = tf.assert_rank_at_least( self._logits, 1, message=shape_err_msg) with tf.control_dependencies([_assert_shape_op]): self._logits = tf.identity(self._logits) self._n_categories = tf.shape(self._logits)[-1] super(Categorical, self).__init__( dtype=dtype, param_dtype=param_dtype, is_continuous=False, is_reparameterized=False, group_event_ndims=group_event_ndims)
def __init__(self, logits, n_experiments, dtype=None, group_ndims=0, **kwargs): self._logits = tf.convert_to_tensor(logits) param_dtype = assert_same_float_dtype([(self._logits, 'Multinomial.logits')]) if dtype is None: dtype = tf.int32 assert_same_float_and_int_dtype([], dtype) self._logits, self._n_categories = assert_rank_at_least_one( self._logits, 'Multinomial.logits') self._n_experiments = assert_positive_int32_integer( n_experiments, 'Multinomial.n_experiments') super(Multinomial, self).__init__(dtype=dtype, param_dtype=param_dtype, is_continuous=False, is_reparameterized=False, group_ndims=group_ndims, **kwargs)
def __init__(self, logits, normalize_logits=True, dtype=None, group_ndims=0, **kwargs): self._logits = tf.convert_to_tensor(logits) param_dtype = assert_same_float_dtype( [(self._logits, 'UnnormalizedMultinomial.logits')]) if dtype is None: dtype = tf.int32 assert_same_float_and_int_dtype([], dtype) self._logits = assert_rank_at_least_one( self._logits, 'UnnormalizedMultinomial.logits') self._n_categories = get_shape_at(self._logits, -1) self.normalize_logits = normalize_logits super(UnnormalizedMultinomial, self).__init__( dtype=dtype, param_dtype=param_dtype, is_continuous=False, is_reparameterized=False, group_ndims=group_ndims, **kwargs)
def __init__(self, logits, n_experiments, dtype=None, group_event_ndims=0): self._logits = tf.convert_to_tensor(logits) param_dtype = assert_same_float_dtype( [(self._logits, 'Multinomial.logits')]) if dtype is None: dtype = tf.int32 assert_same_float_and_int_dtype([], dtype) static_logits_shape = self._logits.get_shape() shape_err_msg = "logits should have rank >= 1." if static_logits_shape and (static_logits_shape.ndims < 1): raise ValueError(shape_err_msg) elif static_logits_shape and ( static_logits_shape[-1].value is not None): self._n_categories = static_logits_shape[-1].value else: _assert_shape_op = tf.assert_rank_at_least( self._logits, 1, message=shape_err_msg) with tf.control_dependencies([_assert_shape_op]): self._logits = tf.identity(self._logits) self._n_categories = tf.shape(self._logits)[-1] sign_err_msg = "n_experiments must be positive" if isinstance(n_experiments, int): if n_experiments <= 0: raise ValueError(sign_err_msg) self._n_experiments = n_experiments else: try: n_experiments = tf.convert_to_tensor(n_experiments, tf.int32) except ValueError: raise TypeError('n_experiments must be int32') _assert_rank_op = tf.assert_rank( n_experiments, 0, message="n_experiments should be a scalar (0-D Tensor).") _assert_positive_op = tf.assert_greater( n_experiments, 0, message=sign_err_msg) with tf.control_dependencies([_assert_rank_op, _assert_positive_op]): self._n_experiments = tf.identity(n_experiments) super(Multinomial, self).__init__( dtype=dtype, param_dtype=param_dtype, is_continuous=False, is_reparameterized=False, group_event_ndims=group_event_ndims)
def __init__(self, logits, dtype=None, group_event_ndims=0): self._logits = tf.convert_to_tensor(logits) param_dtype = assert_same_float_dtype([(self._logits, 'Bernoulli.logits')]) if dtype is None: dtype = tf.int32 assert_same_float_and_int_dtype([], dtype) super(Bernoulli, self).__init__(dtype=dtype, param_dtype=param_dtype, is_continuous=False, is_reparameterized=False, group_event_ndims=group_event_ndims)
def __init__(self, logits, dtype=None, group_event_ndims=0): self._logits = tf.convert_to_tensor(logits) param_dtype = assert_same_float_dtype([(self._logits, 'Categorical.logits')]) if dtype is None: dtype = tf.int32 assert_same_float_and_int_dtype([], dtype) self._logits, self._n_categories = assert_rank_at_least_one( self._logits, 'Categorical.logits') static_logits_shape = self._logits.get_shape() super(Categorical, self).__init__(dtype=dtype, param_dtype=param_dtype, is_continuous=False, is_reparameterized=False, group_event_ndims=group_event_ndims)
def __init__(self, rate, dtype=None, group_event_ndims=0, check_numerics=False): self._rate = tf.convert_to_tensor(rate) param_dtype = assert_same_float_dtype([(self._rate, 'Poisson.rate')]) if dtype is None: dtype = tf.int32 assert_same_float_and_int_dtype([], dtype) self._check_numerics = check_numerics super(Poisson, self).__init__(dtype=dtype, param_dtype=param_dtype, is_continuous=False, is_reparameterized=False, group_event_ndims=group_event_ndims)
def __init__(self, logits, n_experiments, dtype=None, group_ndims=0, check_numerics=False, **kwargs): self._logits = tf.convert_to_tensor(logits) param_dtype = assert_same_float_dtype([(self._logits, 'Binomial.logits')]) if dtype is None: dtype = tf.int32 assert_same_float_and_int_dtype([], dtype) sign_err_msg = "n_experiments must be positive" if isinstance(n_experiments, int): if n_experiments <= 0: raise ValueError(sign_err_msg) self._n_experiments = n_experiments else: try: n_experiments = tf.convert_to_tensor(n_experiments, tf.int32) except ValueError: raise TypeError('n_experiments must be int32') _assert_rank_op = tf.assert_rank( n_experiments, 0, message="n_experiments should be a scalar (0-D Tensor).") _assert_positive_op = tf.assert_greater(n_experiments, 0, message=sign_err_msg) with tf.control_dependencies( [_assert_rank_op, _assert_positive_op]): self._n_experiments = tf.identity(n_experiments) self._check_numerics = check_numerics super(Binomial, self).__init__(dtype=dtype, param_dtype=param_dtype, is_continuous=False, is_reparameterized=False, group_ndims=group_ndims, **kwargs)