|  View source on GitHub | 
NegativeBinomial(total_count, probs=mean / (mean + total_count)).
Inherits From: ExponentialFamily
tfp.glm.NegativeBinomialSoftplus(
    total_count=1.0, name=None
)
Where mean = softplus(X @ weights).
| Args | |
|---|---|
| name | Python strused as TF namescope for ops created by member
functions. Default value:None(i.e., the subclass name). | 
| Attributes | |
|---|---|
| name | Returns the name of this module as passed or determined in the ctor. | 
| name_scope | Returns a tf.name_scopeinstance for this class. | 
| non_trainable_variables | Sequence of non-trainable variables owned by this module and its submodules. | 
| submodules | Sequence of all sub-modules. Submodules are modules which are properties of this module, or found as properties of modules which are properties of this module (and so on). 
 | 
| trainable_variables | Sequence of trainable variables owned by this module and its submodules. | 
| variables | Sequence of variables owned by this module and its submodules. | 
Methods
as_distribution
as_distribution(
    predicted_linear_response, name=None
)
Builds a mean parameterized TFP Distribution from linear response.
Example:
model = tfp.glm.Bernoulli()
r = tfp.glm.compute_predicted_linear_response(x, w)
yhat = model.as_distribution(r)
| Args | |
|---|---|
| predicted_linear_response | response-shapedTensorrepresenting linear
predictions based on newmodel_coefficients, i.e.,tfp.glm.compute_predicted_linear_response(
   model_matrix, model_coefficients, offset). | 
| name | Python strused as TF namescope for ops created by member
functions. Default value:None(i.e., 'log_prob'). | 
| Returns | |
|---|---|
| model | tfp.distributions.Distribution-like object with mean
parameterized bypredicted_linear_response. | 
log_prob
log_prob(
    response, predicted_linear_response, name=None
)
Computes D(param=mean(r)).log_prob(response) for linear response, r.
| Args | |
|---|---|
| response | float-likeTensorrepresenting observed ("actual")
responses. | 
| predicted_linear_response | float-likeTensorcorresponding totf.linalg.matmul(model_matrix, weights). | 
| name | Python strused as TF namescope for ops created by member
functions. Default value:None(i.e., 'log_prob'). | 
| Returns | |
|---|---|
| log_prob | Tensorwith shape and dtype ofpredicted_linear_responserepresenting the distribution prescribed log-probability of the observedresponses. | 
with_name_scope
@classmethodwith_name_scope( method )
Decorator to automatically enter the module name scope.
class MyModule(tf.Module):@tf.Module.with_name_scopedef __call__(self, x):if not hasattr(self, 'w'):self.w = tf.Variable(tf.random.normal([x.shape[1], 3]))return tf.matmul(x, self.w)
Using the above module would produce tf.Variables and tf.Tensors whose
names included the module name:
mod = MyModule()mod(tf.ones([1, 2]))<tf.Tensor: shape=(1, 3), dtype=float32, numpy=..., dtype=float32)>mod.w<tf.Variable 'my_module/Variable:0' shape=(2, 3) dtype=float32,numpy=..., dtype=float32)>
| Args | |
|---|---|
| method | The method to wrap. | 
| Returns | |
|---|---|
| The original method wrapped such that it enters the module's name scope. | 
__call__
__call__(
    predicted_linear_response, name=None
)
Computes mean(r), var(mean), d/dr mean(r) for linear response, r.
Here mean and var are the mean and variance of the sufficient statistic,
which may not be the same as the mean and variance of the random variable
itself.  If the distribution's density has the form
p_Y(y) = h(y) Exp[dot(theta, T(y)) - A]
where theta and A are constants and h and T are known functions,
then mean and var are the mean and variance of T(Y).  In practice,
often T(Y) := Y and in that case the distinction doesn't matter.
| Args | |
|---|---|
| predicted_linear_response | float-likeTensorcorresponding totf.linalg.matmul(model_matrix, weights). | 
| name | Python strused as TF namescope for ops created by member
functions. Default value:None(i.e., 'call'). | 
| Returns | |
|---|---|
| mean | Tensorwith shape and dtype ofpredicted_linear_responserepresenting the distribution prescribed mean, given the prescribed
linear-response to mean mapping. | 
| variance | Tensorwith shape and dtype ofpredicted_linear_responserepresenting the distribution prescribed variance, given the prescribed
linear-response to mean mapping. | 
| grad_mean | Tensorwith shape and dtype ofpredicted_linear_responserepresenting the gradient of the mean with respect to the
linear-response and given the prescribed linear-response to mean
mapping. |