-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add sum-zero constrained intrinsic conditional autoregressive (ICAR) variable #4851
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
Conversation
Copy of the article can be found here: #4518 (comment) |
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.
Thanks for opening the PR. I left some suggestions.
I suggest you check this developer guide for the next steps (docstrings, tests, etc...): https://www.github.com/pymc-devs/pymc3/tree/main/docs%2Fsource%2Fdeveloper_guide_implementing_distribution.md
Codecov Report
@@ Coverage Diff @@
## main #4851 +/- ##
==========================================
- Coverage 73.09% 70.51% -2.59%
==========================================
Files 86 86
Lines 13856 13888 +32
==========================================
- Hits 10128 9793 -335
- Misses 3728 4095 +367
|
@ricardoV94 is there infrastructure to generate adjecency matrices for testing CAR variables? I'm having trouble creating input for the Normally, i'd use something like the following, assuming the area of interest is made up of a rectangular lattice: import libpysal
lattice_rows = 2
lattice_cols = 5
A = libpysal.weights.lat2SW(lattice_rows, lattice_cols, criterion='rook', row_st=False) which gives: >>> A.toarray()
array([[0, 1, 0, 0, 0, 1, 0, 0, 0, 0],
[1, 0, 1, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 1, 0, 0, 0, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 0, 0, 1],
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 0, 0, 1, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 1, 0],
[0, 0, 0, 1, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 1, 0, 0, 0, 1, 0]], dtype=int8) |
You can hardcode some predefined matrices if it's too complicated to generate then dynamically. If it's too many you can put them in a separate file. |
I added a simple function to generate such, though it's far from being robust. I am now getting weird errors locally for the Details
depending on how I define the input to |
@ricardoV94 any suggestions regarding the above errors? |
The edge entries in a |
I tried that using the following: adj_mat = Domain([random_adjacency_matrix(n, rng) for _ in range(5)])
dom = Domain([generate_vals(n, rng) for _ in range(5)])
tau = Domain([0.1, 0.25, 1., 1.5, 2.]) But raises the first error I got, which is: See the full trace below: Details
EDIT: if I comment out the lines:
the the tests run as expected. Is there a subtle bug in EDIT2: I decided to use |
I think this is ready for a round of review @brandonwillard @fonnesbeck @ricardoV94 The generation of the adjacency matrix can probably be improved by a lot to prevent the weird failures in tests. |
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.
Looks like this needs some updates in order for the tests to pass and to get coverage for the logp
implementation.
pymc3/distributions/multivariate.py
Outdated
+ 0.5 * at.log(d).sum() | ||
- 0.5 * tau * at.dot(value, at.dot(W, value)) | ||
) | ||
return bound(out, at.math.abs_(at.sum(value)) < 1e-06) |
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.
Is this effectively being clipped for numerical reasons?
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.
Yep, the sum of the values have to be 0
so I set the precision to 6 digits.
Co-authored-by: Ricardo Vieira <[email protected]>
Co-authored-by: Brandon T. Willard <[email protected]>
Co-authored-by: Ricardo Vieira <[email protected]>
Closing this as stale. @zoj613 let us know if you want to pick this up at another time. Probably pymc-experimental would be a better target |
THis PR is a followup on #4518 (comment) . It impelements the sum-zero constrained intrinsic conditonal autoregressive (ICAR) model as described in [1].
References
[1] Keefe M.J., Ferreira M.A.R., Franck C.T. On the formal specification of sum-zero constrained intrinsic conditional autoregressive models Spat. Stat., 24 (2018), pp. 54-65
Depending on what your PR does, here are a few things you might want to address in the description: