inv_wishart behavior

77 views
Skip to first unread message

Bob Carpenter

unread,
Oct 29, 2013, 3:38:24 PM10/29/13
to stan...@googlegroups.com
One of our tests is for a simple inv_wishart sampler:

transformed data {
cov_matrix[3] S;
S[1, 1] <- 2; S[1, 2] <- 0; S[1, 3] <- 0;
S[2, 2] <- 1; S[2, 1] <- 0; S[2, 3] <- 0;
S[3, 3] <- .5; S[3, 1] <- 0; S[3, 2] <- 0;
}
parameters {
cov_matrix[3] W;
}
model {
W ~ inv_wishart(5, S);
}

The problem is that it's sometimes getting stuck and taking a very
long time for no effective samples.

Sometimes it runs really fast and provides almost reasonable estimates
(diagonals still not quite in the 95% intervals, but right on the
edge).

Anyone know more about this and want to take a look?

- Bob

Michael Betancourt

unread,
Oct 29, 2013, 5:17:16 PM10/29/13
to stan...@googlegroups.com
What's the stan command used to run it?
> --
> 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/groups/opt_out.

Daniel Lee

unread,
Oct 29, 2013, 5:28:03 PM10/29/13
to stan...@googlegroups.com
make src/models/basic_distributions/inv_wishart

src/models/basic_distributions/inv_wishart sample

Ben Goodrich

unread,
Oct 29, 2013, 5:28:24 PM10/29/13
to stan...@googlegroups.com
I don't have so much free time these days, but I would suggest changing the test or adding another test with more than 5 degrees of freedom. When nu = p + 1, there are no moments, so I wouldn't be shocked if there were occasional numerical difficulties.

Ben

Bob Carpenter

unread,
Oct 29, 2013, 5:43:38 PM10/29/13
to stan...@googlegroups.com
Thanks.

The current model has nu = p + 2, so the moments should
match the prior, right?

I'll try it with more degrees of freedom and see if that works.

- Bob

Ben Goodrich

unread,
Oct 29, 2013, 5:50:02 PM10/29/13
to stan...@googlegroups.com
The mean would be defined but not the variance

http://en.wikipedia.org/wiki/Inverse-Wishart_distribution#Moments

Ben

Michael Betancourt

unread,
Oct 29, 2013, 6:42:35 PM10/29/13
to stan...@googlegroups.com
Yeah, but that just means heavy tails which shouldn't be a problem for Stan. Most of the marginals look like student distributions (with a relatively small FWHM and the occasionally large excursion) (and the correlations of the latent Ws with the log_posterior are all funnel like, which is pretty cool).

I think we just need to add init=0 (or init=0.1 if you want to have randomness) . What seems to be happening is that a large random starts the chain way out in the tails where the trajectories drift with little gradient information to guide them to the typical set and you just get a long meandering random walk that never really converges. The marginals have pretty small FWHMs so the inits have to be pretty tight, but tight inits seem to improve sampling significantly.

Daniel Lee

unread,
Oct 29, 2013, 7:17:32 PM10/29/13
to stan...@googlegroups.com


On Oct 29, 2013 6:43 PM, "Michael Betancourt" <betan...@gmail.com> wrote:
>
> Yeah, but that just means heavy tails which shouldn't be a problem for Stan.  Most of the marginals look like student distributions (with a relatively small FWHM and the occasionally large excursion) (and the correlations of the latent Ws with the log_posterior are all funnel like, which is pretty cool).
>
> I think we just need to add init=0 (or init=0.1 if you want to have randomness) .  

That isn't going to work. I've already tried that. Same behavior.

Bob Carpenter

unread,
Oct 29, 2013, 9:15:32 PM10/29/13
to stan...@googlegroups.com
For covariance matrices, init = 0 will conveniently
initialize to the identity matrix, because in the
underlying Cholesky factor, below-diag entries
are 0 and diag entries are exp(0) = 1.

I have no idea what init=0 does for correlation
matrices, though, which is a different topic not
related to inv_wishart behavior.

- Bob


On 10/29/13, 7:17 PM, Daniel Lee wrote:
> stan-dev+u...@googlegroups.com <mailto:stan-dev%2Bunsu...@googlegroups.com>.
> > > For more options, visit https://groups.google.com/groups/opt_out.
> >
> > --
> > 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 <mailto:stan-dev%2Bunsu...@googlegroups.com>.

Ben Goodrich

unread,
Oct 29, 2013, 9:49:50 PM10/29/13
to stan...@googlegroups.com
On Tuesday, October 29, 2013 9:15:32 PM UTC-4, Bob Carpenter wrote:
For covariance matrices, init = 0 will conveniently
initialize to the identity matrix, because in the
underlying Cholesky factor, below-diag entries
are 0 and diag entries are exp(0) = 1.

I have no idea what init=0 does for correlation
matrices, though, which is a different topic not
related to inv_wishart behavior.

The same. The expectation of each correlation is a multiplicative and additive function of independent CPCs each with an expectation of zero.

Ben

Michael Betancourt

unread,
Oct 30, 2013, 5:10:02 AM10/30/13
to stan...@googlegroups.com
Well, it does seem to improve the probability of success but, you're right, it can still go haywire.

The now-dominant pathology is poor adaptation, with the step size dropping to a dramatically small value.
I think the init step size might be too aggressive, causing the first transition to jump to a bad place in the
tails where the gradients are huge.

Bob Carpenter

unread,
Oct 30, 2013, 11:04:04 PM10/30/13
to stan...@googlegroups.com


On 10/30/13, 5:10 AM, Michael Betancourt wrote:
> Well, it does seem to improve the probability of success but, you're right, it can still go haywire.
>
> The now-dominant pathology is poor adaptation, with the step size dropping to a dramatically small value.
> I think the init step size might be too aggressive, causing the first transition to jump to a bad place in the
> tails where the gradients are huge.

We've seen that before, right? Is there any way to easily
make the adaptation less aggressive? And is that what's going
on with all the models that slow down radically around iteration
20 or so?

- Bob

Michael Betancourt

unread,
Oct 30, 2013, 11:28:08 PM10/30/13
to stan...@googlegroups.com
> We've seen that before, right? Is there any way to easily
> make the adaptation less aggressive?

The flexible adaptation branch has a proper warmup window so that should help.

> And is that what's going
> on with all the models that slow down radically around iteration
> 20 or so?

Early iterations bump the chain out into the tail and it takes 10 or so iterations
before step size adaptation drops the step size to almost zero and the NUTS trees
saturate the maximum tree depth.

You can see the details in the trace plots if you save the warmup.

Bob Carpenter

unread,
Oct 30, 2013, 11:42:52 PM10/30/13
to stan...@googlegroups.com


On 10/30/13, 11:28 PM, Michael Betancourt wrote:
>> We've seen that before, right? Is there any way to easily
>> make the adaptation less aggressive?
>
> The flexible adaptation branch has a proper warmup window so that should help.

Meaning you can set it?

>> And is that what's going
>> on with all the models that slow down radically around iteration
>> 20 or so?
>
> Early iterations bump the chain out into the tail and it takes 10 or so iterations
> before step size adaptation drops the step size to almost zero and the NUTS trees
> saturate the maximum tree depth.

Can't we do something simpler to learn a bit about
covariance early on, then be less agressive about
step size adaptation? (I know these things are much easier
to say than tune!)

> You can see the details in the trace plots if you save the warmup.

I have looked, but often what's happening is that iteration 20 or
so is about where the algorithm seems to have converged to the right
region of the posterior.

So is the covariance that was being used
out in the tail out of whack so that when you get closer
to convergence, the scale's all wrong? If so, maybe tamping down
the scale of the covariance matrix more strongly during warmup would
help.

- Bob

Michael Betancourt

unread,
Oct 31, 2013, 6:17:40 AM10/31/13
to stan...@googlegroups.com
The flexible adaptation branch has a proper warmup window so that should help.

Meaning you can set it?

Yes, the init window, the adaptation window, and the termination window are all customizable.

Can't we do something simpler to learn a bit about
covariance early on, then be less agressive about
step size adaptation?  (I know these things are much easier
to say than tune!)

We should ease back on the stepsize initialization a bit but we need to finish some experiments
to validate that first.  But there's really not much you can do in only 20 iterations to learn the
variances better.
 
I have looked, but often what's happening is that iteration 20 or
so is about where the algorithm seems to have converged to the right
region of the posterior.

So is the covariance that was being used
out in the tail out of whack so that when you get closer
to convergence, the scale's all wrong?  If so, maybe tamping down
the scale of the covariance matrix more strongly during warmup would
help.

The biggest issue is that the covariance estimates are hugely overestimated because
they incorporate the huge swing in the warmup.  In the next adaptation window those
estimates would be wiped, but the chain isn't getting there fast enough.  This is what
the init window is meant to ameliorate. 

Ben Goodrich

unread,
Nov 1, 2013, 12:16:23 PM11/1/13
to stan...@googlegroups.com
On Wednesday, October 30, 2013 11:04:04 PM UTC-4, Bob Carpenter wrote:
We've seen that before, right?  Is there any way to easily
make the adaptation less aggressive?  And is that what's going
on with all the models that slow down radically around iteration
20 or so?

You might try a model that reparameterizes using the Bartlett decomposition

http://en.wikipedia.org/wiki/Wishart_distribution#Bartlett_decomposition

(just invert that for the inverse Wishart). That way we might be able to distinguish between an issue that affects the inverse Wishart distribution vs. an issue that affects the way we do covariance matrices.

Ben
Reply all
Reply to author
Forward
0 new messages