keflavich / MultiComponentFitting

Sprint repository for multi-component fitting. To be migrated to radio-astro-tools when ready
0 stars 0 forks source link

WIP for discussion -- Bayesian multicomponent fitting #4

Closed low-sky closed 7 years ago

low-sky commented 7 years ago

Here's a first cut at Bayesian multicomponent fitting. Of note, it contains an indicator variable by component which goes ahead and models the number of components.

mcmcmc = Markov Chain Monte Carlo Multi Component

keflavich commented 7 years ago

Tried running example, got:

In [1]: %run example.py
Traceback (most recent call last):
  File "/Users/adam/repos/MultiComponentFitting/mcmcmc/example.py", line 13, in <module>
    trace, model = mcmcmc.BayesianMultiComponentFit(Xdata, Ydata, max_ncomp=3, y_error = 1.0)
  File "/Users/adam/repos/MultiComponentFitting/mcmcmc/mcmcmc.py", line 91, in BayesianMultiComponentFit
    trace = pm.sample()
TypeError: sample() missing 1 required positional argument: 'draws'
e-koch commented 7 years ago

Something else to consider here is the case when components "switch" in the chain. I get the first component switching about halfway through sampling with the second component. This makes their posteriors super uncertain.

Maybe we could model this, but the dumb way could be to run a LSQ or MAP to set the initial parameters for the MCMC, draw one set of samples with the MCMC w/ tight constraints on the priors, decide how many component are actually needed based on the on parameters, then use a longer chain to continue sampling with the reduced number of components and less constraints on the priors.

e-koch commented 7 years ago

Here's an example of two components "switching".

mcmcmc_2components_fit_with_3

e-koch commented 7 years ago

I added a naive attempt for choosing the number of components needed for the fit in mcmcmc.MultiComponentFit. It requires running multiple chains, which isn't great.

low-sky commented 7 years ago

The cross-over issue is still going to be a problem and it would great to actually solve that.

e-koch commented 7 years ago

@low-sky - Want to add anything before merging this?

low-sky commented 7 years ago

Nope. Trigger pulled.