-
Notifications
You must be signed in to change notification settings - Fork 142
initial commit of matrix normal base API , regression, and MN-RSA #341
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
Merged
mihaic
merged 90 commits into
brainiak:master
from
mshvartsman:matnormal-regression-rsa
Oct 13, 2020
Merged
Changes from all commits
Commits
Show all changes
90 commits
Select commit
Hold shift + click to select a range
fb18dc2
initial commit of matrix normal base API , regression, and MNRSA
94dfcbb
add tensorflow to requirements
7264b3f
make the linter happy
aa54772
Merge pull request #1 from brainiak/master
narayanan2004 6e9fd68
Merge branch 'matnormal-regression-rsa' of https://github.com/mshvart…
34087a7
Fix style issues
4eb39f6
Merge branch 'master' into matnormal-regression-rsa
mshvartsman 6ab49df
Merge pull request #1 from narayanan2004/matnormal-regression-rsa
mshvartsman 347cdc8
Merge branch 'matnormal-regression-rsa' of github.com:mshvartsman/bra…
a75d866
more linter fixes
3dcf915
fix ambiguous varname
e9da333
linter fixes in tests
5ae24f1
broke this to make the linter happy, fixing
01aed20
more cleanup from hacky copypaste-squash
9ca2cef
More linter checks (for some reason run-checks.sh ignores /tests on m…
9ee9734
fixing sphinx complaints
39fbc3b
Merge remote-tracking branch 'upstream/master' into matnormal-regress…
e72998d
sync with upstream
mshvartsman 56cc6c8
move kronecker solvers to their own file, utils.py was getting unwieldy
mshvartsman e5a2e94
initial refactor, all tests pass
mshvartsman bb57f74
remove CovTFWrap, use constant cholesky cov with passed Sigma instead
mshvartsman 1ee89b3
linter and formatting fixes
mshvartsman 835558a
merge upstream
mshvartsman 231391b
add metaclass reference
mshvartsman d2bb285
further cleanup post refactor, doc changes, addressing minor comments
mshvartsman af2e0ac
Merge remote-tracking branch 'upstream/master' into matnormal-regress…
mshvartsman 79092ee
linter and deprecation fixes, rename Matnorm to Matnormal in one spot
mshvartsman 1fedd0c
fix missing comma
mshvartsman 87eb10d
strict linter fixes
mshvartsman bc87a00
need old TF for things to work
mshvartsman 05258b3
docstring formatting fix
mshvartsman c362426
run tf1 -> tf2 conversion script
mshvartsman 16bf442
run v1 -> v2 conversion on tests
mshvartsman e4f28d6
tf 1 -> 2 on solvers
mshvartsman dea4d10
test_cov passes
mshvartsman a5b2c7e
logp tests pass
mshvartsman d82a1b6
cov tests pass eager
mshvartsman b0eb0c6
matnorm test passes in eager
mshvartsman 0ba7509
rest of likelihoods pass in eager
mshvartsman 1ec4425
pack/unpack for fitting using scipy
mshvartsman d032b1a
do cholesky covs better now
mshvartsman ed63f6d
test for new packing/unpacking utils
mshvartsman 1db0080
tests now pass eager mode
mshvartsman b134a05
pull out repeated code as a util
mshvartsman 7ffbe91
Follow more standard sklearn API where est params come out as trailin…
mshvartsman 9a6b4b7
mnrsa now works with eager, tests pass
mshvartsman b041460
final removal of tf print and session stuff
mshvartsman cee8c81
typo fixes
mshvartsman 6e95082
likelihood docstrings
mshvartsman 12eff1f
simplify make_val_and_grad
mshvartsman 41eda2b
fix old tf1 stuff that would break in tf2
mshvartsman 3f6dde5
fix for maintaining the graph correctly
mshvartsman 429e329
More stringent tests by doing bad initialization
mshvartsman ad6ce7d
Update example with new way of doing things
mshvartsman a1fa69e
final typo fixes
mshvartsman dca4b51
Merge branch 'mnorm-eager' into matnormal-regression-rsa
mshvartsman ee57283
autoformat
mshvartsman 0cf0a77
remove nb_black dependency
mshvartsman d3c0a5a
minor docstring cleanup
mshvartsman 73d2945
fix the kron covs to work correctly with the new optimizer wrapper
mshvartsman 98607ea
autoformat
mshvartsman 4fcf557
correctly pass optimizer args
mshvartsman a1fe394
Make test linter happy
mshvartsman 39646f7
Merge branch 'master' into matnormal-regression-rsa
mshvartsman 495c656
maybe this will make travis use a recent TF?
mshvartsman c9a5688
workaround to be able to use pymanopt (for theano) in the presence of…
mshvartsman c599f92
Merge branch 'master' into matnormal-regression-rsa (pull in tf2.3 fi…
mshvartsman 570f4a2
doc build fixes
mshvartsman 5f04a82
doc cleanup and removal of unused functions
mshvartsman 8a41b9d
fix linter issues introduced by fixing docbuild issues
mshvartsman b77ddf3
remove hard tf2.3 requirement (tensorflow_probability deps should res…
mshvartsman c0af0e6
add reproducible rng fixture, improve test coverage, fixup linear dec…
mshvartsman 6250fc8
don't print debug on tests, improve cov
mshvartsman 3dfec38
improve coverage
mshvartsman 549bf2a
docstring cleanups
mshvartsman d0da34c
notation consistency fix for the example too
mshvartsman 0022cc7
addressing @mihaic's comments
mshvartsman 1887a80
make cholesky flat/unflat use consistently TF ops
mshvartsman 78a13a2
float comparison
mshvartsman 55296e8
revert whitespace change
mshvartsman 4e0397a
fix conda build for travis
mshvartsman 3413d90
more conda build fixes
mshvartsman 7d983da
whitespace
mshvartsman f9f595e
pull in TF2.3 from PyPI since conda only has 2.2
mshvartsman 9e60f23
escape
mshvartsman 5e472a1
Fix tensorflow-probability dependencies
mihaic 6894f94
Make matnormal optional
mihaic 845ca84
Add tensorflow dependency, docs
mihaic 0da0201
Change dependencies installation instructions
mihaic c55e963
Merge branch 'master' into matnormal-regression-rsa
mihaic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,252 @@ | ||
| """ | ||
| Some properties of the matrix-variate normal distribution | ||
| --------------------------------------------------------- | ||
|
|
||
| .. math:: | ||
| \\DeclareMathOperator{\\Tr}{Tr} | ||
| \\newcommand{\\trp}{^{T}} % transpose | ||
| \\newcommand{\\trace}{\\text{Trace}} % trace | ||
| \\newcommand{\\inv}{^{-1}} | ||
| \\newcommand{\\mb}{\\mathbf{b}} | ||
| \\newcommand{\\M}{\\mathbf{M}} | ||
| \\newcommand{\\C}{\\mathbf{C}} | ||
| \\newcommand{\\G}{\\mathbf{G}} | ||
| \\newcommand{\\A}{\\mathbf{A}} | ||
| \\newcommand{\\R}{\\mathbf{R}} | ||
| \\renewcommand{\\S}{\\mathbf{S}} | ||
| \\newcommand{\\B}{\\mathbf{B}} | ||
| \\newcommand{\\Q}{\\mathbf{Q}} | ||
| \\newcommand{\\mH}{\\mathbf{H}} | ||
| \\newcommand{\\U}{\\mathbf{U}} | ||
| \\newcommand{\\mL}{\\mathbf{L}} | ||
| \\newcommand{\\diag}{\\mathrm{diag}} | ||
| \\newcommand{\\etr}{\\mathrm{etr}} | ||
| \\renewcommand{\\H}{\\mathbf{H}} | ||
| \\newcommand{\\vecop}{\\mathrm{vec}} | ||
| \\newcommand{\\I}{\\mathbf{I}} | ||
| \\newcommand{\\X}{\\mathbf{X}} | ||
| \\newcommand{\\Y}{\\mathbf{Y}} | ||
| \\newcommand{\\Z}{\\mathbf{Z}} | ||
| \\renewcommand{\\L}{\\mathbf{L}} | ||
|
|
||
|
|
||
| The matrix-variate normal distribution is a generalization to matrices of the | ||
| normal distribution. Another name for it is the multivariate normal | ||
| distribution with kronecker separable covariance. | ||
| The distributional intuition is as follows: if | ||
| :math:`X \\sim \\mathcal{MN}(M,R,C)` then | ||
| :math:`\\mathrm{vec}(X)\\sim\\mathcal{N}(\\mathrm{vec}(M), C \\otimes R)`, | ||
| where :math:`\\mathrm{vec}(\\cdot)` is the vectorization operator and | ||
| :math:`\\otimes` is the Kronecker product. If we think of X as a matrix of TRs | ||
| by voxels in the fMRI setting, then this model assumes that each voxel has the | ||
| same TR-by-TR covariance structure (represented by the matrix R), | ||
| and each volume has the same spatial covariance (represented by the matrix C). | ||
| This assumption allows us to model both covariances separately. | ||
| We can assume that the spatial covariance itself is kronecker-structured, | ||
| which implies that the spatial covariance of voxels is the same in the X, | ||
| Y and Z dimensions. | ||
|
|
||
| The log-likelihood for the matrix-normal density is: | ||
|
|
||
| .. math:: | ||
| \\log p(X\\mid \\M,\\R, \\C) = -2\\log mn - m \\log|\\C| - n \\log|\\R| - | ||
| \\Tr\\left[\\C\\inv(\\X-\\M)\\trp\\R\\inv(\\X-\\M)\\right] | ||
|
|
||
| Here :math:`X` and :math:`M` are both :math:`m\\times n` matrices, :math:`\\R` | ||
| is :math:`m\\times m` and :math:`\\C` is :math:`n\\times n`. | ||
|
|
||
| The `brainiak.matnormal` package provides structure to infer models that | ||
| can be stated in the matrix-normal notation that are useful for fMRI analysis. | ||
| It provides a few interfaces. `MatnormModelBase` is intended as a | ||
| base class for matrix-variate models. It provides a wrapper for the tensorflow | ||
| optimizer that provides convergence checks based on thresholds on the function | ||
| value and gradient, and simple verbose outputs. It also provides an interface | ||
| for noise covariances (`CovBase`). Any class that follows the interface | ||
| can be used as a noise covariance in any of the matrix normal models. The | ||
| package includes a variety of noise covariances to work with. | ||
|
|
||
| Matrix normal marginals | ||
| ------------------------- | ||
|
|
||
| Here we extend the multivariate gaussian marginalization identity to matrix | ||
| normals. This is used in a number of the models in the package. Below, we | ||
| use lowercase subscripts for sizes to make dimensionalities easier to track. | ||
| Uppercase subscripts for covariances help keep track where they come from. | ||
|
|
||
| .. math:: | ||
| \\mathbf{X}_{ij} &\\sim \\mathcal{MN}(\\mathbf{A}_{ij}, | ||
| \\Sigma_{\\mathbf{X}i},\\Sigma_{\\mathbf{X}j})\\\\ | ||
| \\mathbf{Y}_{jk} &\\sim \\mathcal{MN}(\\mathbf{B}_{jk}, | ||
| \\Sigma_{\\mathbf{Y}j},\\Sigma_{\\mathbf{Y}k})\\\\ | ||
| \\mathbf{Z}_{ik}\\mid\\mathbf{X}_{ij},\\mathbf{Y}_{jk} &\\sim | ||
| \\mathcal{MN}(\\mathbf{X}_{ij}\\mathbf{Y}_{jk} + \\mathbf{C}_{ik}, | ||
| \\Sigma_{\\mathbf{Z}_i}, \\Sigma_{\\mathbf{Z}_k})\\\\ | ||
|
|
||
|
|
||
| We vectorize, and convert to a form we recognize as | ||
| :math:`y \\sim \\mathcal{N}(Mx+b, \\Sigma)`. | ||
|
|
||
| .. math:: | ||
| \\vecop(\\mathbf{Z}_{ik})\\mid\\mathbf{X}_{ij},\\mathbf{Y}_{jk} &\\sim | ||
| \\mathcal{N}(\\vecop(\\X_{ij}\\mathbf{Y}_{jk}+\\mathbf{C}_{ik}), | ||
| \\Sigma_{\\mathbf{Z}_k}\\otimes\\Sigma_{\\mathbf{Z}_i})\\\\ | ||
| \\vecop(\\mathbf{Z}_{ik})\\mid\\mathbf{X}_{ij},\\mathbf{Y}_{jk} | ||
| &\\sim \\mathcal{N}((\\I_k\\otimes\\X_{ij})\\vecop(\\mathbf{Y}_{jk}) | ||
| + \\vecop(\\mathbf{C}_{ik}), | ||
| \\Sigma_{\\mathbf{Z}_k}\\otimes\\Sigma_{\\mathbf{Z}_i}) | ||
|
|
||
|
|
||
| Now we can use our standard gaussian marginalization identity: | ||
|
|
||
| .. math:: | ||
| \\vecop(\\mathbf{Z}_{ik})\\mid\\mathbf{X}_{ij} \\sim | ||
| \\mathcal{N}((\\I_k\\otimes\\X_{ij})\\vecop(\\mathbf{B}_{jk}) + | ||
| \\vecop(\\mathbf{C}_{ik}), | ||
| \\Sigma_{\\mathbf{Z}_k}\\otimes\\Sigma_{\\mathbf{Z}_i} + | ||
| (\\I_k\\otimes\\X_{ij})(\\Sigma_{\\mathbf{Y}_k}\\otimes | ||
| \\Sigma_{\\mathbf{Y}_j})(\\I_k\\otimes\\X_{ij})\\trp ) | ||
|
|
||
|
|
||
| Collect terms using the mixed-product property of kronecker products: | ||
|
|
||
| .. math:: | ||
| \\vecop(\\mathbf{Z}_{ik})\\mid\\mathbf{X}_{ij} \\sim | ||
| \\mathcal{N}(\\vecop(\\X_{ij}\\mathbf{B}_{jk}) + | ||
| \\vecop(\\mathbf{C}_{ik}), \\Sigma_{\\mathbf{Z}_k}\\otimes | ||
| \\Sigma_{\\mathbf{Z}_i} + \\Sigma_{\\mathbf{Y}_k}\\otimes | ||
| \\X_{ij}\\Sigma_{\\mathbf{Y}_j}\\X_{ij}\\trp) | ||
|
|
||
|
|
||
| Now, we can see that the marginal density is a matrix-variate normal only if | ||
| :math:`\\Sigma_{\\mathbf{Z}_k}= \\Sigma_{\\mathbf{Y}_k}` -- that is, the | ||
| variable we're marginalizing over has the same covariance in the dimension | ||
| we're *not* marginalizing over as the marginal density. Otherwise the densit | ||
| is well-defined but the covariance retains its kronecker structure. So we let | ||
| :math:`\\Sigma_k:=\\Sigma_{\\mathbf{Z}_k}= \\Sigma_{\\mathbf{Y}_k}`, factor, | ||
| and transform it back into a matrix normal: | ||
|
|
||
| .. math:: | ||
| \\vecop(\\mathbf{Z}_{ik})\\mid\\mathbf{X}_{ij} &\\sim | ||
| \\mathcal{N}(\\vecop(\\X\\mathbf{B}_{jk}) + \\vecop(\\mathbf{C}_{ik}), | ||
| \\Sigma_{k}\\otimes\\Sigma_{\\mathbf{Z}_i} + \\Sigma_{_k}\\otimes | ||
| \\X\\Sigma_{\\mathbf{Y}_j}\\X\\trp)\\\\ | ||
| \\vecop(\\mathbf{Z}_{ik})\\mid\\mathbf{X}_{ij} &\\sim | ||
| \\mathcal{N}(\\vecop(\\X\\mathbf{B}_{jk}) + \\vecop(\\mathbf{C}_{ik}), | ||
| \\Sigma_{k}\\otimes(\\Sigma_{\\mathbf{Z}_i} | ||
| +\\X\\Sigma_{\\mathbf{Y}_j}\\X\\trp))\\\\ | ||
| \\mathbf{Z}_{ik}\\mid\\mathbf{X}_{ij} &\\sim | ||
| \\mathcal{MN}(\\X\\mathbf{B}_{jk} + \\mathbf{C}_{ik}, | ||
| \\Sigma_{\\mathbf{Z}_i} +\\X\\Sigma_{\\mathbf{Y}_j}\\X\\trp,\\Sigma_{k}) | ||
|
|
||
|
|
||
| We can do it in the other direction as well, because if | ||
| :math:`\\X \\sim \\mathcal{MN}(M, U, V)` then :math:`\\X\\trp \\sim | ||
| \\mathcal{MN}(M\\trp, V, U)`: | ||
|
|
||
| .. math:: | ||
| \\mathbf{Z\\trp}_{ik}\\mid\\mathbf{X}_{ij},\\mathbf{Y}_{jk} &\\sim | ||
| \\mathcal{MN}(\\mathbf{Y}_{jk}\\trp\\mathbf{X}_{ij}\\trp + | ||
| \\mathbf{C}\\trp_{ik}, \\Sigma_{\\mathbf{Z}_k},\\Sigma_{\\mathbf{Z}_i})\\\\ | ||
| \\mbox{let } \\Sigma_i := | ||
| \\Sigma_{\\mathbf{Z}_i}=\\Sigma_{\\mathbf{X}_i} \\\\ | ||
| \\cdots\\\\ | ||
| \\mathbf{Z\\trp}_{ik}\\mid\\mathbf{Y}_{jk} &\\sim | ||
| \\mathcal{MN}(\\mathbf{A}_{jk}\\trp\\mathbf{X}_{ij}\\trp + | ||
| \\mathbf{C}\\trp_{ik}, \\Sigma_{\\mathbf{Z}_k} + | ||
| \\Y\\trp\\Sigma_{\\mathbf{Y}_j}\\Y,\\Sigma_{\\mathbf{Z}_i})\\\\ | ||
| \\mathbf{Z}_{ik}\\mid\\mathbf{Y}_{jk} &\\sim | ||
| \\mathcal{MN}(\\mathbf{X}_{ij}\\mathbf{A}_{jk}+ | ||
| \\mathbf{C}_{ik},\\Sigma_{\\mathbf{Z}_i},\\Sigma_{\\mathbf{Z}_k} + | ||
| \\Y\\trp\\Sigma_{\\mathbf{Y}_j}\\Y) | ||
|
|
||
| These marginal likelihoods are implemented relatively efficiently in | ||
| `MatnormModelBase.matnorm_logp_marginal_row` and | ||
| `MatnormModelBase.matnorm_logp_marginal_col`. | ||
|
|
||
| Partitioned matrix normal conditionals | ||
| -------------------------------------- | ||
|
|
||
| Here we extend the multivariate gaussian conditional identity to matrix | ||
| normals. This is used for prediction in some models. Below, we | ||
| use lowercase subscripts for sizes to make dimensionalities easier to track. | ||
| Uppercase subscripts for covariances help keep track where they come from. | ||
|
|
||
|
|
||
| Next, we do the same for the partitioned gaussian identity. First two | ||
| vectorized matrix-normals that form our partition: | ||
|
|
||
| .. math:: | ||
| \\mathbf{X}_{ij} &\\sim \\mathcal{MN}(\\mathbf{A}_{ij}, \\Sigma_{i}, | ||
| \\Sigma_{j}) \\rightarrow \\vecop[\\mathbf{X}_{ij}] \\sim | ||
| \\mathcal{N}(\\vecop[\\mathbf{A}_{ij}], \\Sigma_{j}\\otimes\\Sigma_{i})\\\\ | ||
| \\mathbf{Y}_{ik} &\\sim \\mathcal{MN}(\\mathbf{B}_{ik}, \\Sigma_{i}, | ||
| \\Sigma_{k}) \\rightarrow \\vecop[\\mathbf{Y}_{ik}] \\sim | ||
| \\mathcal{N}(\\vecop[\\mathbf{B}_{ik}], \\Sigma_{k}\\otimes\\Sigma_{i})\\\\ | ||
| \\begin{bmatrix}\\vecop[\\mathbf{X}_{ij}] \\\\ \\vecop[\\mathbf{Y}_{ik}] | ||
| \\end{bmatrix} | ||
| & \\sim \\mathcal{N}\\left(\\vecop\\begin{bmatrix}\\mathbf{A}_{ij} | ||
| \\\\ \\mathbf{B}_{ik} | ||
| \\end{bmatrix} | ||
| , \\begin{bmatrix} \\Sigma_{j}\\otimes \\Sigma_i & | ||
| \\Sigma_{jk} \\otimes \\Sigma_i \\\\ | ||
| \\Sigma_{kj}\\otimes \\Sigma_i & \\Sigma_{k} \\otimes | ||
| \\Sigma_i\\end{bmatrix}\\right) | ||
|
|
||
| We apply the standard partitioned Gaussian identity and simplify using the | ||
| properties of the :math:`\\vecop` operator and the mixed product property | ||
| of kronecker products: | ||
|
|
||
| .. math:: | ||
| \\vecop[\\X_{ij}] \\mid \\vecop[\\Y_{ik}]\\sim | ||
| \\mathcal{N}(&\\vecop[\\A_{ij}] + (\\Sigma_{jk}\\otimes\\Sigma_i) | ||
| (\\Sigma_k\\inv\\otimes\\Sigma_i\\inv)(\\vecop[\\Y_{ik}]-\\vecop[\\B_{ik}]),\\\\ | ||
| & \\Sigma_j\\otimes\\Sigma_i - (\\Sigma_{jk}\\otimes\\Sigma_i) | ||
| (\\Sigma_k\\inv\\otimes\\Sigma_i\\inv) (\\Sigma_{kj}\\otimes\\Sigma_i))\\\\ | ||
| =\\mathcal{N}(&\\vecop[\\A_{ij}] + | ||
| (\\Sigma_{jk}\\Sigma_k\\inv\\otimes\\Sigma_i\\Sigma_i\\inv) | ||
| (\\vecop[\\Y_{ik}]-\\vecop[\\B_{ik}]), \\\\ | ||
| & \\Sigma_j\\otimes\\Sigma_i - | ||
| (\\Sigma_{jk}\\Sigma_k\\inv\\Sigma_{kj}\\otimes | ||
| \\Sigma_i\\Sigma_i\\inv \\Sigma_i))\\\\ | ||
| =\\mathcal{N}(&\\vecop[\\A_{ij}] + (\\Sigma_{jk}\\Sigma_k\\inv\\otimes\\I) | ||
| (\\vecop[\\Y_{ik}]-\\vecop[\\B_{ik}]), \\\\ | ||
| & \\Sigma_j\\otimes\\Sigma_i - | ||
| (\\Sigma_{jk}\\Sigma_k\\inv\\Sigma_{kj}\\otimes\\Sigma_i)\\\\ | ||
| =\\mathcal{N}(&\\vecop[\\A_{ij}] + | ||
| \\vecop[\\Y_{ik}-\\B_{ik}\\Sigma_k\\inv\\Sigma_{kj}], | ||
| (\\Sigma_j-\\Sigma_{jk}\\Sigma_k\\inv\\Sigma_{kj})\\otimes\\Sigma_i) | ||
|
|
||
|
|
||
| Next, we recognize that this multivariate gaussian is equivalent to the | ||
| following matrix variate gaussian: | ||
|
|
||
| .. math:: | ||
| \\X_{ij} \\mid \\Y_{ik}\\sim \\mathcal{MN}(\\A_{ij} + | ||
| (\\Y_{ik}-\\B_{ik})\\Sigma_k\\inv\\Sigma_{kj}, \\Sigma_i, | ||
| \\Sigma_j-\\Sigma_{jk}\\Sigma_k\\inv\\Sigma_{kj}) | ||
|
|
||
| The conditional in the other direction can be written by working through the | ||
| same algebra: | ||
|
|
||
| .. math:: | ||
| \\Y_{ik} \\mid \\X_{ij}\\sim \\mathcal{MN}(\\B_{ik} +(\\X_{ij}- | ||
| \\A_{ij})\\Sigma_j\\inv\\Sigma_{jk}, \\Sigma_i, | ||
| \\Sigma_k-\\Sigma_{kj}\\Sigma_j\\inv\\Sigma_{jk}) | ||
|
|
||
| Finally, vertical rather than horizontal concatenation (yielding a partitioned | ||
| row rather than column covariance) can be written by recognizing the behavior | ||
| of the matrix normal under transposition: | ||
|
|
||
| .. math:: | ||
| \\X\\trp_{ji} \\mid \\Y\\trp_{ki}\\sim \\mathcal{MN}(&\\A\\trp_{ji} + | ||
| \\Sigma_{jk}\\Sigma_k\\inv(\\Y\\trp_{ki}-\\B\\trp_{ki}), | ||
| \\Sigma_j-\\Sigma_{jk}\\Sigma_k\\inv\\Sigma_{kj}, \\Sigma_i)\\\\ | ||
| \\Y\\trp_{ki} \\mid \\X\\trp_{ji}\\sim \\mathcal{MN}(&\\B\\trp_{ki} + | ||
| \\Sigma_{kj}\\Sigma_j\\inv(\\X\\trp_{ji}-\\A\\trp_{ji}), | ||
| \\Sigma_k-\\Sigma_{kj}\\Sigma_j\\inv\\Sigma_{jk}, \\Sigma_i) | ||
|
|
||
| These conditional likelihoods are implemented relatively efficiently | ||
| in `MatnormModelBase.matnorm_logp_conditional_row` and | ||
| `MatnormModelBase.matnorm_logp_conditional_col`. | ||
|
|
||
| """ | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.