-
-
Notifications
You must be signed in to change notification settings - Fork 69
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
Potential bug with (cmd)stan(py)’s optimisation process running a probabilistic PCA #664
Comments
Just to check, is this bridgestan version being done with Jacobian=True? |
I didn't change that flag, what I did was something like (this - the code below isn't a MWE... can provide one if you'd like) import bridgestan as bs
from scipy.optimize import minimize
bs.set_bridgestan_path('/Users/aditya/github/bridgestan')
bs_model = bs.StanModel.from_stan_file("dr.stan", "data.json")
minimize(
lambda x: -bs_model.log_density(x),
np.hstack([X.reshape(-1), 0.0]),
) |
Stan's optimization by default does not apply jacobian adjustments (this will be configurable next release: #649), but the default in bridgestan is to apply them. I suspect this is the cause of the confusion, since the statement "Stan places an improper uniform prior on the constrained parameters" is only true in the presence of the jacobian adjustment for the change of variables. What happens if you set |
Damn, great catch - I assumed that stan was adding the jacobians when automated transforms are used. I tried this with bridgestan with your suggestion, and it does indeed produce quite similar results to cmdstanpy. I'm curious, does this mean that
doesn't place a uniform density over |
Posting here as the stan forums post didn't get any replies. I would like to understand why I’m seeing the results that I’m seeing running a PCA with Stan on some simulated data.
The data: is nine different mnist digits rotated a bunch of times (the issue below also occurs with different datasets).
The model:
Y | X ~ N(0, XX^T + vI)
(this is matrix normal notation for every column of Y being independently drawn from a zero mean multivariate normal with a dot product covariance function applied to the latents).
The model famously corresponds to probabilistic PCA (the maximum likelihood solution for$\mathbf{X} | \mathbf{Y}$ is attained at the scaled eigenvectors of the sample covariance).
The problem: If I use unconstrained latents, I get a different solution to if I use constrained latents. This is very surprising - is this caused by numerical instabilities? If so, why?
If I set the line (in my parameters block below) as follows:
I obtain the latents:
This are incorrect looking latents.
If instead the line is changed to:
the result becomes:
which is absolutely fine - it’s a rotation of the eigenvectors and since the posterior is invariant to rotation, this makes sense.
I don’t understand this behaviour assuming that Stan places an improper uniform prior on the constrained parameters.
What’s more is that, using a bridgestan model that uses the constrained parameters, and using scipy’s optimize to optimize the parameters works and generates the correct solution (and not the weird axis aligned solution). Could someone shed some light into what’s going on?
I’m using cmdstan 2.31.0.
My code (a minimal reproducing example) is as follows:
The text was updated successfully, but these errors were encountered: