-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add ICARRV and ICAR #6831
add ICARRV and ICAR #6831
Changes from 9 commits
1dfa059
10fed3b
0a6e963
d496689
8114a7d
bf8be00
299ea68
6f0579a
e6a7acd
6b46604
e66e1d0
2f8072c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -86,6 +86,7 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"MatrixNormal", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"KroneckerNormal", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"CAR", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"ICAR", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"StickBreakingWeights", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
@@ -2218,6 +2219,169 @@ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class ICARRV(RandomVariable): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name = "icar" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ndim_supp = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ndims_params = [2, 1, 1, 0, 0, 0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
dtype = "floatX" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
_print_name = ("ICAR", "\\operatorname{ICAR}") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def __call__(self, W, node1, node2, N, sigma, zero_sum_strength, size=None, **kwargs): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return super().__call__(W, node1, node2, N, sigma, zero_sum_strength, size=size, **kwargs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@classmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def rng_fn(cls, rng, size, W, node1, node2, N, sigma, zero_sum_strength): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise NotImplementedError("Cannot sample from ICAR prior") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
icar = ICARRV() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class ICAR(Continuous): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
r""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The intrinsic conditional autoregressive prior. It is primarily used to model | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
covariance between neighboring areas on large datasets. It is a special case | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
of the :class:`~pymc.CAR` distribution where alpha is set to 1. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The log probability density function is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. math:: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
f(\\phi| W,\\sigma) = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-\frac{1}{2\\sigma^{2}} \\sum_{i\\sim j} (\\phi_{i} - \\phi_{j})^2 - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\frac{1}{2}*\frac{\\sum_{i}{\\phi_{i}}}{0.001N}^{2} - \\ln{\\sqrt{2\\pi}} - | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
\\ln{0.001N} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are some backslashes twice and others once? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure, I wrote them with single slashes. Maybe one of the pre-commit checks added them by mistake? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The first term represents the spatial covariance component. Each $\\phi_{i}$ is penalized | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
based on the square distance from each of its neighbors. The notation $i\\sim j$ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
indicates a sum over all the neighbors of $\\phi_{i}$. The last three terms are the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Normal log density function where the mean is zero and the standard deviation is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
$N * 0.001$ (where N is the length of the vector $\\phi$). This component imposed the zero-sum | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
constraint by finding the sum of the vector $\\phi$ and penalizing based on its | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
distance from zero. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
W : ndarray of int | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Symmetric adjacency matrix of 1s and 0s indicating adjacency between elements. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Must pass either W or both node1 and node2. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sigma : scalar, default 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Standard deviation of the vector of phi's. Putting a prior on sigma | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
will result in a centered parameterization. In most cases, it is | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
preferable to use a non-centered parameterization by using the default | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
value and multiplying the resulting phi's by sigma. See the example below. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zero_sum_strength : scalar, default 0.001 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Controls how strongly to enforce the zero-sum constraint. It sets the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
standard deviation of a normal density function with mean zero. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could add a bit of detail here, like, "It puts an additional normal prior on the sum of the phi, such that the sum is normally distributed with mean zero and a small standard deviation, whose value is |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Examples | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
This example illustrates how to switch between centered and non-centered | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
parameterizations. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. code-block:: python | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import numpy as np | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
import pymc as pm | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# 4x4 adjacency matrix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# arranged in a square lattice | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
W = np.array([[0,1,0,1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[1,0,1,0], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[0,1,0,1], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
[1,0,1,0]]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# centered parameterization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with pm.Model(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sigma = pm.Exponential('sigma',1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
phi = pm.ICAR('phi',W=W,sigma=sigma) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mu = phi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# non-centered parameterization | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
with pm.Model(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sigma = pm.Exponential('sigma',1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
phi = pm.ICAR('phi',W=W) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
adjusted some formatting here, mostly putting a space after comma |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
mu = sigma * phi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
References | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. Mitzi, M., Wheeler-Martin, K., Simpson, D., Mooney, J. S., | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Gelman, A., Dimaggio, C. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
"Bayesian hierarchical spatial models: Implementing the Besag York | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Mollié model in stan" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Spatial and Spatio-temporal Epidemiology, Vol. 31, (Aug., 2019), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pp 1-18 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
.. Banerjee, S., Carlin, B., Gelfand, A. Hierarchical Modeling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
and Analysis for Spatial Data. Second edition. CRC press. (2015) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
""" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
rv_op = icar | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
@classmethod | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def dist(cls, W, sigma=1, zero_sum_strength=0.001, **kwargs): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# check that adjacency matrix is two dimensional, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# square, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# symmetrical | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# and composed of 1s or 0s. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this block of comments doesn't add too much to the code doing the checks below, dont think its necessary |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not W.ndim == 2: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError("W must be matrix with ndim=2") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not W.shape[0] == W.shape[1]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError("W must be a square matrix") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if not np.allclose(W.T, W): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError("W must be a symmetric matrix") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if np.any((W != 0) & (W != 1)): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
raise ValueError("W must be composed of only 1s and 0s") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# convert adjacency matrix to edgelist representation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
bwengals marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node1, node2 = np.where(np.tril(W) == 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node1 = pt.as_tensor_variable(node1, dtype=int) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
node2 = pt.as_tensor_variable(node2, dtype=int) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
W = pt.as_tensor_variable(W, dtype=int) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
N = pt.shape(W)[0] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
N = pt.as_tensor_variable(N) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# check on sigma | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this comment and the comment check on centering strength are out of date now |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
sigma = pt.as_tensor_variable(floatX(sigma)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# check on centering_strength | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
zero_sum_strength = pt.as_tensor_variable(floatX(zero_sum_strength)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return super().dist([W, node1, node2, N, sigma, zero_sum_strength], **kwargs) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def moment(rv, size, W, node1, node2, N, sigma, zero_sum_strength): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return pt.zeros(N) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
def logp(value, W, node1, node2, N, sigma, zero_sum_strength): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pairwise_difference = (-1 / (2 * sigma**2)) * pt.sum( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
pt.square(value[node1] - value[node2]) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
soft_center = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as before RE wording, "center" vs zero sum. I think the latter is better and is more consistent with |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
-0.5 * pt.pow(pt.sum(value) / (zero_sum_strength * N), 2) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- pt.log(pt.sqrt(2.0 * np.pi)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- pt.log(zero_sum_strength * N) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
return check_parameters(pairwise_difference + soft_center, sigma > 0, msg="sigma > 0") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
class StickBreakingWeightsRV(RandomVariable): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name = "stick_breaking_weights" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
ndim_supp = 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or small datasets!