bd-j / prospector

Python code for Stellar Population Inference from Spectra and SEDs
http://prospect.readthedocs.io
MIT License
159 stars 75 forks source link

Emcee sampling in Prospector #322

Open elmiio opened 9 months ago

elmiio commented 9 months ago

Hello,

I am trying to fit a model to some spectroscopic data using emcee optimization. I have defined my model with the 'ssp' and 'optimize_speccal' templates, and have four free parameters: redshift (zred), mass, metallicity (logzsol) and age. The minimization (least-squares) fitting executes nicely for all four parameters that I've set to free, as expected. However, when I run emcee, it seems that the redshift parameter gets left out. The sampling occurs only for the mass, metallicity and age parameters, and thus produces a theta vector array that is 3 entries long rather than 4. To confirm that redshift is excluded, the 'chain' key in my emcee results dictionary has a free parameters dimension of 3 (when I believe it should be 4):

Is there a way to fix this? Thanks in advance

bd-j commented 8 months ago

can you try dispalying the model before you run your fit? E.g. in your parameter file have the following in the main block.

obs, model, sps, noise = build_all(**run_params)
print(model)
sys.exit()
elmiio commented 8 months ago

I can. I get a list of the free parameters in my model (which includes zred), as well as a list of the fixed parameters.

bd-j commented 8 months ago

I don't offhand know of anyway that the free parameters would be turned off in the call to fit_model just after that, and have not encountered that before. Are you doing optimization and sampling in the same run? Can you try just doing --emcee and not optimization to see if the problem persists?

elmiio commented 8 months ago

I just ran emcee without optimization and it appears that the problem is persisting. I tried running print(model) immediately after the emcee sampling is finished, and zred still shows up as a free parameter in my model. So, I am not sure exactly where things are going wrong.

bd-j commented 8 months ago

That's really strange, I don't know how that could happen. Have you tried a run with dynesty instead of emcee?

elmiio commented 8 months ago

I just did a run with dynesty instead of emcee, and it appears I am having the same issue.

bd-j commented 8 months ago

If you can put together a minimum working example of your parameter file and post it somewhere that might help.

elmiio commented 8 months ago

Hello,

Here is a txt file which includes all my code up to the point where I begin having issues (after optimization and emcee sampling):

Modelling_Sandbox.txt