Skip to content
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

Add a function to get a best-fit metadata blob #126

Open
astrolog1986 opened this issue Aug 12, 2016 · 2 comments
Open

Add a function to get a best-fit metadata blob #126

astrolog1986 opened this issue Aug 12, 2016 · 2 comments

Comments

@astrolog1986
Copy link

astrolog1986 commented Aug 12, 2016

Hi,

Sorry just a question about saving the results with naima.
When the particle distribution are saved as a metadata blob as
electron_e = np.logspace(11, 15, 100) * u.eV
electron_dist = ECPL(electron_e)

# The first object returned must be the model photon spectrum, and
# subsequent objects will be stored as metadata blobs
return IC(data), (electron_e, electron_dist), We

it plots the electron distribution versus electron energy. Is there any way to
save spectrum with best parameters in a ascii file, for example:
electron_e electron_dist
$$$$ $$$$$
$$$$ $$$$$
....... .........
Thank you in advance

@zblz
Copy link
Owner

zblz commented Jan 26, 2017

@astrolog1986 - There is a function in the plot module that allows you to obtain this sort of information, but currently it is only used used internally. The function is naima.plot.find_ML. The function takes a sampler and lets you specify the index of the blob for which you want to obtain the ML (maximum likelihood) value. For your example above, the index would be 1. This how you can use it (I assume a sampler that has already been run stored in the variable sampler):

from naima.plot import find_ML
ML, ML_params, ML_err, ML_model = find_ML(sampler, 1)

The four items returned are:

  • ML: The value of the loglikelihood for the returned model (which is the highest among all the samples).
  • ML_params: A tuple of the parameters that result in the maximum likelihood.
  • ML_err: A 1-sigma estimate of the confidence interval for each of the parameters considering all the samples.
  • ML_model: The model corresponding to the highest likelihood. The shape of this variable will always be (model_energy, model_value), and corresponds to the values saved in the metadata blobs.

@zblz
Copy link
Owner

zblz commented Jan 26, 2017

It might be worthwile to have a high-level function that does this and only returns the metadata blob of interest, so I'll keep the issue open and rename it to add that function.

@zblz zblz changed the title saving the results with naima Add a function to get a best-fit metadata blob Jan 26, 2017
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

No branches or pull requests

2 participants