timothydmorton / isochrones

Pythonic stellar model grid access; easy MCMC fitting of stellar properties
http://isochrones.readthedocs.org
MIT License
120 stars 61 forks source link

Not sure if model.fit() is working... #32

Closed jessiechristiansen closed 7 years ago

jessiechristiansen commented 7 years ago

Here's what I'm running in spyder

from isochrones import StarModel from isochrones.dartmouth import Dartmouth_Isochrone

Teff = (5770, 80) logg = (4.44, 0.08) feh = (0.00, 0.10) V = (10.0,0.05) dar = Dartmouth_Isochrone() model = StarModel(dar, Teff=Teff, logg=logg, feh=feh) model.fit()

Should something be happening? It's possible it's running successfully and I just don't know how to access the parameters? (Mass, radius, etc).

timothydmorton commented 7 years ago

if it's worked, then you should be able to access model.samples that will give posterior samples.

timothydmorton commented 7 years ago

model.fit(), when pymultinest is available, will run MultiNest, which may look like a background process, depending on what shell/environment you are running. Should take a few minutes max.

jessiechristiansen commented 7 years ago

Okay excellent, I can certainly see things in model.samples. Then do we use our method of choice for choosing an average value from the posteriors? Or is the best mass, radius, etc saved somewhere?

jessiechristiansen commented 7 years ago

I see the maxlike function, what order are the results coming out in? E.g.

mod = StarModel(dar,Teff=(5293,70),logg=(4.49,0.08), feh=(0.11,0.05), B=(9.767,0.023))

mod.maxlike() Out[82]: array([ 8.67815083e-01, 1.00158328e+01, 9.92699465e-02, 4.61601411e+01, 3.41879100e-02])

timothydmorton commented 7 years ago

You can ignore the maxlike function (though for reference the parameter order is mass, log(age), feh, distance, A_V). I recommended doing your own analysis of the posterior samples (eg median or quantiles). For visualization use 'triangle_physical', etc to make a corner plot. On Fri, Sep 16, 2016 at 17:54 jessiechristiansen notifications@github.com wrote:

I see the maxlike function, what order are the results coming out in? E.g.

mod = StarModel(dar,Teff=(5293,70),logg=(4.49,0.08), feh=(0.11,0.05), B=(9.767,0.023))

mod.maxlike() Out[82]: array([ 8.67815083e-01, 1.00158328e+01, 9.92699465e-02, 4.61601411e+01, 3.41879100e-02])

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/timothydmorton/isochrones/issues/32#issuecomment-247718003, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzr2x9OYliWeLol2McJl6l3M5VRcRm0ks5qqxADgaJpZM4J_Tvh .

jessiechristiansen commented 7 years ago

Great, will do.

So, it looks like the MultiNest install didn't work (I did encounter a bunch of errors that I variously fixed or navigated around) so it defaulted to emcee, which is fine with me. But something is still not working:

mod.fit_mcmc() Out[20]: <emcee.ensemble.EnsembleSampler at 0x11c2ab208>

mod.plot_samples('radius') <matplotlib.figure.Figure at 0x11c2ab4e0> Traceback (most recent call last):

File "", line 1, in mod.plot_samples('radius')

File "/Applications/anaconda/lib/python3.5/site-packages/isochrones/starmodel.py", line 1023, in plot_samples samples,stats = self.prop_samples(prop)

File "/Applications/anaconda/lib/python3.5/site-packages/isochrones/starmodel.py", line 988, in prop_samples samples = self.samples[prop].values

File "/Applications/anaconda/lib/python3.5/site-packages/isochrones/starmodel.py", line 944, in samples self._make_samples()

File "/Applications/anaconda/lib/python3.5/site-packages/isochrones/starmodel.py", line 884, in _make_samples chain = np.loadtxt('{}post_equal_weights.dat'.format(self._mnest_basename))

File "/Applications/anaconda/lib/python3.5/site-packages/numpy/lib/npyio.py", line 803, in loadtxt fh = iter(open(fname))

FileNotFoundError: [Errno 2] No such file or directory: 'Nonepost_equal_weights.dat'

Any thoughts?

timothydmorton commented 7 years ago

Looks like it's still trying to create the samples dataframe under the assumption it was run with multinest. Make sure 'model.use_emcee' is set to True. Also I can't vouch for the 'plot_samples' function; can't remember when I last touched/tested that.... On Fri, Sep 16, 2016 at 18:32 jessiechristiansen notifications@github.com wrote:

Great, will do.

So, it looks like the MultiNest install didn't work (I did encounter a bunch of errors that I variously fixed or navigated around) so it defaulted to emcee, which is fine with me. But something is still not working:

mod.fit_mcmc() Out[20]:

mod.plot_samples('radius')

Traceback (most recent call last):

File "", line 1, in mod.plot_samples('radius')

File "/Applications/anaconda/lib/python3.5/site-packages/isochrones/starmodel.py", line 1023, in plot_samples samples,stats = self.prop_samples(prop)

File "/Applications/anaconda/lib/python3.5/site-packages/isochrones/starmodel.py", line 988, in prop_samples samples = self.samples[prop].values

File "/Applications/anaconda/lib/python3.5/site-packages/isochrones/starmodel.py", line 944, in samples self._make_samples()

File "/Applications/anaconda/lib/python3.5/site-packages/isochrones/starmodel.py", line 884, in _make_samples chain = np.loadtxt('{}post_equal_weights.dat'.format(self._mnest_basename))

File "/Applications/anaconda/lib/python3.5/site-packages/numpy/lib/npyio.py", line 803, in loadtxt fh = iter(open(fname))

FileNotFoundError: [Errno 2] No such file or directory: 'Nonepost_equal_weights.dat'

Any thoughts?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/timothydmorton/isochrones/issues/32#issuecomment-247723959, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzr29OSA1n6xjibKfHU-2nVXfvG9AHeks5qqxjxgaJpZM4J_Tvh .

jessiechristiansen commented 7 years ago

Ah, that has fixed it. I did model.use_emcee = True mod.fit_mcmc() mod.plot_samples('radius') and got a pretty plot.

It sounds like I should not be following the demo notebook? Is this the best place to be looking for documentation: http://isochrones.readthedocs.io/en/latest/ ?

timothydmorton commented 7 years ago

That is the best place for documentation, but don't hesitate to poke me with questions. Also stay tuned for a substantial upgrade sometime in the next few months, for which I will endeavor to make the documentation up-to-date.

On Fri, Sep 16, 2016 at 7:03 PM jessiechristiansen notifications@github.com wrote:

Ah, that has fixed it. I did model.use_emcee = True mod.fit_mcmc() mod.plot_samples('radius') and got a pretty plot.

It sounds like I should not be following the demo notebook? Is this the best place to be looking for documentation: http://isochrones.readthedocs.io/en/latest/ ?

— You are receiving this because you commented.

Reply to this email directly, view it on GitHub https://github.com/timothydmorton/isochrones/issues/32#issuecomment-247728497, or mute the thread https://github.com/notifications/unsubscribe-auth/ABzr2wKzGCevP7LYpQN49yN3OwzqHo82ks5qqyBSgaJpZM4J_Tvh .