[PIPE2D-1238] fitPfsFluxReference should not brute-force the model fitting Created: 16/Jun/23  Updated: 29/Jun/23  Resolved: 29/Jun/23

Status: Done
Project: DRP 2-D Pipeline
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Task Priority: Normal
Reporter: sogo.mineo Assignee: sogo.mineo
Resolution: Done Votes: 0
Labels: flux-calibration
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Relates
relates to PIPE2D-1168 fitPfsReferenceFlux breaks Tiger Done
relates to PIPE2D-1231 Reduce memory usage of fitPfsReferenc... Done
Reviewers: price

 Description   

The current fitPfsFluxReference naively compares observed spectra with ~60,000 model spectra
to find the best-fit models. It could not be helped, for the model interpolation was a heavy task
and I did not want to do it many times at run time, which prevented me from using an optimizer.

Now that the model interpolator has become decently small in memory consumption
and decently fast in interpolation (PIPE2D-1231),
I can use some good optimizer in the model fitting instead of the current brute-force method.

It is essential to guess a good initial guess if we are to use an optimizer,
and some suggestions were given in PIPE2D-1168.
In this ticket, however, I don't take care of initial guesses,
but I rewrite fitPfsFluxReference so that it will use an optimizer.

On optimizers

I have compared "Powell" method with "Nelder-Mead" method (both do not require differentiability)
and I have concluded that "Powell" method is more useful to us
because "Nelder-Mead" method is more apt to fall into a local minimum
though it is 2x faster than "Powell".

Comparison between "Powell" method and the brute-force method

The success rate of "Powell" method depends on the order of parameters
((Teff, log(g), metal, alpha) or (Teff, log(g), alpha, metal) or ...)
I ran "Powell" method for all 4! permutations and have adopted the best one,
that is, (metal, alpha, Teff, log(g)).

Percentages below are (RMS(input - output)) / (stddev(input)) obtained from a test with 100 fibers.

        master   powell
Teff    12.46%   10.96%
log(g)  27.00%   23.62%
metal   43.78%   41.85%
alpha   91.30%   88.75%

The master branch takes 25647 seconds to fit 100 fibers, but with Powell's method, the fitting takes only 7420 seconds
(>~ 3x speed up).

Powell's method outperforms the master branch (brute-force method) not only in speed but in quality.
It seems strange, but I guess that something is wrong in the brute-force method
with the final, sub-grid peak finding algorithm for probability distributions,
which is no longer necessary with Powell's method.



 Comments   
Comment by sogo.mineo [ 20/Jun/23 ]

Could you review this PR?

Comment by sogo.mineo [ 29/Jun/23 ]

Merged. Thanks for reviewing.

Generated at Sat Feb 10 16:04:36 JST 2024 using Jira 8.3.4#803005-sha1:1f96e09b3c60279a408a2ae47be3c745f571388b.