Beispiel #1
0
 def _base_dist(self, mu: TensorLike, alpha: TensorLike, *args, **kwargs):
     total_count = mu + alpha
     probs = mu / (mu + alpha)
     return tfd.NegativeBinomial(total_count=total_count,
                                 probs=probs,
                                 *args,
                                 **kwargs)
Beispiel #2
0
 def _init_distribution(conditions, **kwargs):
     return tfd.Mixture(
         cat=tfd.Categorical(
             probs=[1.0 - conditions["psi"], conditions["psi"]]),
         components=[
             tfd.Deterministic(loc=tf.zeros_like(conditions["mu"])),
             tfd.NegativeBinomial(
                 total_count=conditions["alpha"],
                 probs=(conditions["mu"]) /
                 (conditions["mu"] + conditions["alpha"]),
             ),
         ],
         **kwargs,
     )
Beispiel #3
0
    def _base_dist(self, *args, **kwargs):
        """
        Zero-inflated negative binomial base distribution.

        A ZeroInflatedNegativeBinomial is a mixture between a deterministic
        distribution and a NegativeBinomial distribution.
        """
        mix = kwargs.pop("mix")
        return tfd.Mixture(
            cat=tfd.Categorical(probs=[mix, 1.0 - mix]),
            components=[
                tfd.Deterministic(0.0),
                tfd.NegativeBinomial(*args, **kwargs)
            ],
            name="ZeroInflatedNegativeBinomial",
        )
Beispiel #4
0
 def _init_distribution(conditions):
     mu, alpha = conditions["mu"], conditions["alpha"]
     return tfd.NegativeBinomial(total_count=mu + alpha,
                                 probs=mu / (mu + alpha))
Beispiel #5
0
 def _init_distribution(conditions):
     total_count, probs = conditions["total_count"], conditions["probs"]
     return tfd.NegativeBinomial(total_count=total_count, probs=probs)
Beispiel #6
0
         rate=tf.exp(theta["log_lambda"])),
                                pi=theta["pi"])
 },
 "negative binomial": {
     "parameters": {
         "p": {
             "support": [0, 1],
             "activation function": sigmoid
         },
         "log_r": {
             "support": [-10, 10],
             "activation function": identity
         }
     },
     "class":
     lambda theta: tensorflow_distributions.NegativeBinomial(
         total_count=tf.exp(theta["log_r"]), probs=theta["p"])
 },
 "zero-inflated negative binomial": {
     "parameters": {
         "pi": {
             "support": [0, 1],
             "activation function": sigmoid
         },
         "p": {
             "support": [0, 1],
             "activation function": sigmoid
         },
         "log_r": {
             "support": [-10, 10],
             "activation function": identity
         }
Beispiel #7
0
     )
 },
 
 "negative binomial": {
     "parameters": {
         "p": {
             "support": [0, 1],
             "activation function": sigmoid
         },
         "log_r": {
             "support": [-10, 10],
             "activation function": identity
         }
     },
     "class": lambda theta: tensorflow_distributions.NegativeBinomial(
         total_count = tf.exp(theta["log_r"]),
         probs = theta["p"]
     )
 },
 
 "zero-inflated negative binomial": {
     "parameters": {
         "pi": {
             "support": [0, 1],
             "activation function": sigmoid
         },
         "p": {
             "support": [0, 1],
             "activation function": sigmoid
         },
         "log_r": {
             "support": [-10, 10],