Пример #1
0
def model(design_matrix: jnp.ndarray, outcome: jnp.ndarray = None) -> None:
    """
    Model definition: Log odds of making a purchase is a linear combination
    of covariates. Specify a Normal prior over regression coefficients.
    :param design_matrix: Covariates. All categorical variables have been one-hot
        encoded.
    :param outcome: Binary response variable. In this case, whether or not the
        customer made a purchase.
    """

    beta = numpyro.sample('coefficients', dist.MultivariateNormal(loc=0.,
                                                                  covariance_matrix=jnp.eye(design_matrix.shape[1])))
    logits = design_matrix.dot(beta)

    with numpyro.plate('data', design_matrix.shape[0]):
        numpyro.sample('obs', dist.Bernoulli(logits=logits), obs=outcome)
Пример #2
0
def logpdf(x: jnp.ndarray, kappa: float, mu: jnp.ndarray) -> jnp.ndarray:
    """Log-density function of the power spherical distribution.

    Args:
        x: The set of points at which to evaluate the power spherical density.
        kappa: Concentration parameter.
        mu: Mean direction on the sphere. The dimensionality of the sphere is
            determined from this paramter.

    Returns:
        out: The log-density of the power spherical distribution with the
            specified concentration and mean parameter at the desired points.

    """
    d = mu.size
    alpha = (d - 1.) / 2. + kappa
    beta = (d - 1.) / 2.
    lognormalizer = ((alpha + beta) * jnp.log(2.) + beta * jnp.log(jnp.pi) +
                     jspsp.gammaln(alpha) - jspsp.gammaln(alpha + beta))
    unlogprob = kappa * jnp.log(1. + x.dot(mu))
    return unlogprob - lognormalizer