annayqho / TheCannon

a data-driven method for determining stellar parameters and abundances from stellar spectra
MIT License
39 stars 16 forks source link

Scatter Fit #26

Open annayqho opened 9 years ago

annayqho commented 9 years ago

Currently we step through different possible scatter values, and for each value we perform a least squares fit to solve for the coefficients. In the first released version of the code, so we want to optimize for the scatter term somehow instead of doing a guess-and-check? @davidwhogg , @HWRix , @mkness

davidwhogg commented 9 years ago

Really? I thought we used an optimizer! Can you point me into the code + line number in your code, and the code + line number in @mkness 's code?

mkness commented 9 years ago

Currently for the scatter we input an array of scatter values to calculate the chi2 for these values and use a polynomial fit to return the minimum - I thought that still counted as "optimisation" although I didn't upgrade it to actually use the optimiser function (is still an open issue!). I haven't forgotten this is an open issue I am just slow... Line 673. I will make this a priority to try to upgrade this part of the code if necessary.

davidwhogg commented 9 years ago

Well, we should start by benchmarking an optimizer -- but we should only optimize in 1-d (the scatter direction); at each scatter we should solve the linear algebra. Let's discuss before implementation.

davidwhogg commented 9 years ago

ps by "benchmark" I mean compare speed between what we do now and an optimizer; I think the optimizer will be fast but we should make sure.

annayqho commented 9 years ago

OK, good to know (my code is basically the same as Melissa's, lines below) z = np.polyfit(ln_scatter_vals_short, chis_eval_short, 2) fit_pder = np.polyder(z) best_scatter = np.exp(np.roots(fit_pder)[0])

Perhaps the three of us could discuss this over Skype sometime? It would be good to get it completely straightened out before I code anything new.

davidwhogg commented 9 years ago

does np.polyder() take the first derivative?

annayqho commented 9 years ago

Yes, 1st order differentiation is the default, but can be changed with an additional argument.

davidwhogg commented 9 years ago

Okay then I agree with this code. The only question is whether one-d optimization would be faster. But I would downgrade this issue to "low priority" in the short term.