kronecker in Stan

931 views
Skip to first unread message

Andrew Gelman

unread,
Jan 30, 2015, 10:30:38 AM1/30/15
to stan-...@googlegroups.com, stan...@googlegroups.com, Volf...@fas.harvard.edu, Seth Flaxman, Aki Vehtari, golchi.shirin
Hi all. I was speaking with Alex Volfovsky and now I’m all excited again about his hierarchical anova model with Peter Hoff; see here;
http://andrewgelman.com/2013/04/03/hierarchical-array-priors-for-anova-decompositions/
The model uses matrix-normal and array-normal MVN distributions in which the cov matrix is set up as a kronecker product. I recall we had some earlier convos about using kron product in Stan. Anyone interested in this? A possible intermediate solution would be to write a Stan function that implements kron, and if it works we could talk about hardcoding it? What do people think?
See you
A


Bob Carpenter

unread,
Jan 30, 2015, 1:14:48 PM1/30/15
to stan...@googlegroups.com, stan-...@googlegroups.com, Volf...@fas.harvard.edu, Seth Flaxman, Aki Vehtari, golchi.shirin
There's a current feature request for Kronecker quadratic forms:

https://github.com/stan-dev/stan/issues/1196

I believe that was to support Gaussian process models.

Andrew --- what do we need to add to Stan in the way of functions
to do what you want to do? If you let me know what we need in
addition to the quadratic form above, I'll create an issue. Anyone
with a GitHub ID can create an issue by clicking on "new issue", so
feel free to do it yourself.

We should talk at the meeting next week about priorities for the
next three to six months.

- Bob
> --
> You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

Tanner Sorensen

unread,
Jan 30, 2015, 2:16:09 PM1/30/15
to stan-...@googlegroups.com, stan...@googlegroups.com, Volf...@fas.harvard.edu, fla...@gmail.com, Aki.V...@aalto.fi, golchi...@gmail.com, gel...@stat.columbia.edu
Here is a minimal example of (just) the Kronecker product. In order to execute it, run the R script with kron_example.stan in the current working directory. I have been messing around with using similar code to fit a multi-task GP model. Is this currently the fastest way to comput Kronecker products in Stan?
kron_example.R
kron_example.stan

Christian Roy

unread,
Jan 30, 2015, 2:58:08 PM1/30/15
to stan-...@googlegroups.com
For what it is worth I would also be happy if there was a Kronecker product function in stan

I wrote a spatially varying coefficients model and I had to implement the Kronecker product manually. My own code look exactly liker Tanner code except that the Kronecker product is in the transformed parameters block. 

Chris
-----------------



--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.

Ben Goodrich

unread,
Jan 30, 2015, 4:17:51 PM1/30/15
to stan...@googlegroups.com, stan-...@googlegroups.com, Volf...@fas.harvard.edu, fla...@gmail.com, Aki.V...@aalto.fi, golchi...@gmail.com, gel...@stat.columbia.edu
We have a matrix normal (log) PDF in C++ already

https://raw.githubusercontent.com/stan-dev/stan/develop/src/stan/prob/distributions/multivariate/continuous/matrix_normal.hpp

but it appears not to be exposed to the Stan language for some reason.

Ben

Andrew Gelman

unread,
Jan 30, 2015, 4:40:34 PM1/30/15
to stan...@googlegroups.com, stan-...@googlegroups.com, Volf...@fas.harvard.edu, Seth Flaxman, Aki Vehtari, golchi.shirin
Bob:
I’ll defer to the others on what exactly is needed here. If it can be done initially via a Stan function, then it’s possible that we’re already there, or close to it. One meta-question is: to what extent can we use Stan functions as intermediate septs between “having an idea” and “having it in Stan.”
A

Seth Flaxman

unread,
Jan 31, 2015, 7:56:57 AM1/31/15
to stan...@googlegroups.com, stan-...@googlegroups.com, Volf...@fas.harvard.edu, Aki Vehtari, golchi.shirin
Hi Stan. I'm very interested in this; maybe I can collect together the various requests and come to a future Stan dev meeting to help figure out priorities. (Not this coming week, but later is fine.) 

A related question that I expect there'd be much interest in is sparse matrix operations. Is there an issue page for that on the repository / have there already been discussions?

To answer the meta-question: I think with functions Stan can already handle the calculation of a Kronecker matrix-vector product (K1 \otimes K2)v but not (K1 \otimes K2 \otimes K3) v.

Seth

Andrew Gelman

unread,
Feb 2, 2015, 4:08:16 PM2/2/15
to stan...@googlegroups.com, stan-...@googlegroups.com
Bob:
Could we have a place on the Github site for contributed functions (where the “contributors” could include people such as you or me or Aki, i.e., “contributed” just means that it hasn’t been fully tested and doc’d)?

> On Monday, February 2, 2015 at 12:23:46 AM UTC+2, Bob Carpenter wrote:
>>
>>
>> Andrew: We have no mechanism by which to distribute something written
>> as a Stan function. We need to figure out includes first.
>>
>>
>> The big bottleneck to getting things into Stan is the testing and doc.
>>


Sebastian Weber

unread,
Feb 3, 2015, 10:47:07 AM2/3/15
to stan-...@googlegroups.com
Hi!
 
A place with shared code would be great to have. As far as I recall there were plans to extend the testing framework to contributed code? Ideally users would provide fancy Stan functions along with tests (& documentation). Collecting this somewhere would be wonderful for the community.
 
Thinking out loud - a cran like thing for Stan contributed code would be a dream. This would of course include that the code fragements get tested by the tests they were submitted with. In turn this would provide a reliable Stan users library tested with each released Stan release. If a submitted code fragment would fail the tests, it would of course be the responsibility of the supplier to fix it.
 
This may sound far fetched, but having this would be outstanding and with Jenkins such things should be manageable(?).
 
Any plans in this direction?
 
Cheers,
Sebastian



--
You received this message because you are subscribed to the Google Groups "Stan users mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-users+...@googlegroups.com.

Daniel Lee

unread,
Feb 3, 2015, 11:55:54 AM2/3/15
to stan-...@googlegroups.com
Hi Sebastian,

That all sounds great. One thing we don't have yet is a spec. We (the Stan dev team) have thought about it to the extent you've outlined, but haven't really come up with any concrete plans that could be implementable.

Any suggestions?



Daniel

Rob J. Goedman

unread,
Feb 3, 2015, 1:18:34 PM2/3/15
to stan-...@googlegroups.com
Daniel & Sebastian,

In Julia the convention is to name github packages with the extension .jl. I wonder if a similar approach could work for Stan.

If contributed Stan code projects would all be named xxxx.stan they are easy to find on github.

Over time capabilities like Iain’s http://pkg.julialang.org could be added, possibly some of the user code testing could migrate to Travis (e.g https://travis-ci.org/goedman/Stan.jl ) and documentation to ReadTheDocs (e.g.  http://stanjl.readthedocs.org/en/latest/ ).

Just a suggestion. Clearly not free as someone would have to figure out how to install Stan on travis-ci for testing, etc. But having worked with both Cran and the Julia package ecosystem maybe worth to investigate.

Regards,
Rob J. Goedman
goe...@mac.com




Bob Carpenter

unread,
Feb 3, 2015, 5:15:45 PM2/3/15
to stan-...@googlegroups.com
[this should probably be on stan-dev, not stan-users]

From a user’s perspective, I think derivatives should be
opaque. So I’d be happy with something that just let them
specify inputs and then test what outputs should be.

The question is whether we should write this in Stan itself.
That is, they write Stan code that allows something like
Google Test’s EXPECT_EQ and EXPECT_FLOAT_EQ or EXPECT_THROW.

- Bob
Reply all
Reply to author
Forward
0 new messages