Skip to content

Add a notebook for Bayesian Factor Analysis #3396

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
merged 3 commits into from
May 6, 2019

Conversation

chartl
Copy link

@chartl chartl commented Mar 8, 2019

Fulfilling the request here:

https://discourse.pymc.io/t/unique-solution-for-probabilistic-pca/1324/48

This PR adds a notebook that features Bayesian factor analysis, addressing issues both of model factor identification:

https://discourse.pymc.io/t/unique-solution-for-probabilistic-pca/1324

as well as scalability:

https://discourse.pymc.io/t/large-scale-factor-analysis-with-minibatch-advi/246/10

@junpenglao
Copy link
Member

A few comments:

pm.traceplot(trace);

@chartl
Copy link
Author

chartl commented Mar 9, 2019

By "the other solution" I assume you mean the sign-flip symmetrized ADVI? It's a nice example of the group API, but rotation and permutation symmetries remain using this method.

And is "the other case" a reference to a different synthetic dataset? (the obs here: https://discourse.pymc.io/t/unique-solution-for-probabilistic-pca/1324/14)?

@junpenglao
Copy link
Member

By "the other solution" I assume you mean the sign-flip symmetrized ADVI? It's a nice example of the group API, but rotation and permutation symmetries remain using this method.

Oh I see - thanks for the information. In that case if you just fix the plotting that would be sufficient.

@chartl
Copy link
Author

chartl commented Mar 11, 2019

I've installed a fresh pull of master with python setup.py develop, but I still seem to be getting the same plots. I also switched from python2 to python3 -- is there a way to check i have the right branch version? (pm.version gives 3.6)

@lucianopaz
Copy link
Member

@chartl, I think that this problem is similar to what you came across on discourse earlier. Now your repo should be up to date with master for you to re run the notebook.

@fonnesbeck
Copy link
Member

A few recommendations:

  • when plotting a large number of variables, a forest plot is more appropriate than a trace plot, which gets awfully crowded.
  • rather than plotting every variable, perhaps just pick a few illustrative ones.
  • either use a semicolon after the plot call, or assign the return values to variables, to suppress the figure and axes objects from being printed
  • remove stray line at bottom of notebook

@twiecki
Copy link
Member

twiecki commented Apr 22, 2019

ping @chartl

@chartl
Copy link
Author

chartl commented Apr 23, 2019

I couldn't find documentation in arviz on how to plot just a few components of a matrix or vector. Is there a proper way to do this?

For now I used pm.Deterministic to pull a few into the trace that I could reference with traceplot(varnames=foo)

@chartl
Copy link
Author

chartl commented May 6, 2019

ping @fonnesbeck

@fonnesbeck
Copy link
Member

Looks really good! I was wondering the same thing regarding Arviz, particularly for forest plots, actually. Might be worth a feature request.

@fonnesbeck fonnesbeck merged commit ab128aa into pymc-devs:master May 6, 2019
@ColCarroll
Copy link
Member

For the example you provided, the equivalent call would be:

az.plot_trace(trace, ('W', 'F', 'psi'), 
              coords={'W_dim_0': range(1, 4), 
                      'W_dim_1': 0, 
                      'F_dim_0': 0, 
                      'F_dim_1': range(1, 4)});

Note that we do not yet have "compact" as an option for the traceplot, so the dimensions are spread out:
image

@ColCarroll
Copy link
Member

(er, and note that az.plot_trace is aliased to pm.traceplot. also, i figured this out by manually calling data = az.from_pymc3(trace), and inspecting data.posterior to figure out the coordinates to slice)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants