def d2(params): ml.multisetfreeparams([lc1, lc2], params) ret = dispersionmethod(lc1, lc2)["d2"] if plot: d2valuelist.append(ret) return ret
def opt_ml(lc1, lc2, dispersionmethod, plot=False, verbose=False): """ microlensing optimization. Sets the eventual microlensings of lc1 and lc2 so to minimize a dispersion. Does not shift the curves in any other way. If plot is True, it displays the steps of the optimization. @type lc1: lightcurve @param lc1: This one will be passed as first argument (i.e. "reference") to the dispersionmethod @type lc2: lightcurve @param lc2: The light curve that will get interpolated by the dispersionmethod. @todo: implement a better plot ... """ initparams = ml.multigetfreeparams([lc1, lc2]) if verbose: print "Initial params : ", initparams if len(initparams) == 0: raise RuntimeError, "There are no free microlensing params to optimize !" if plot: d2valuelist = [] def d2(params): ml.multisetfreeparams([lc1, lc2], params) ret = dispersionmethod(lc1, lc2)["d2"] if plot: d2valuelist.append(ret) return ret # http://www.scipy.org/doc/api_docs/SciPy.optimize.optimize.html#fmin_bfgs #put disp = 0 to make them silent... #optparams = spopt.fmin(d2, initparams) #optparams = spopt.fmin_cg(d2, initparams) #optparams = spopt.fmin_bfgs(d2, params, epsilon =1.0e-5) #optparams = spopt.fmin_bfgs(d2, params, disp=1, retall=0) #optparams = spopt.anneal(d2, params) #optparams = spopt.fmin_ncg(d2, initparams) # this guy would need a gradient. #optparams = spopt.fmin_bfgs(d2, initparams) # precision loss # [ 2.89270193e-10 4.94366701e-08 -2.63101369e-04 -4.38757115e-03] # [ 2.95294380e-10 3.64696903e-08 -2.63882092e-04 -5.66560156e-05] optparams = spopt.fmin_powell( d2, initparams, disp=int(verbose) ) # 312 , 2.592636, [ 2.89270193e-10 4.94366701e-08 -2.63101369e-04 -4.38757115e-03] #optparams = spopt.fmin(d2, initparams) # 150, 2.614217 #optparams = spopt.fmin(d2, initparams, xtol = 1.0e-10) #optparams = spopt.fmin_bfgs(d2, params, epsilon =1.0e-5) if verbose: print "Optimal params : ", optparams print repr(optparams) ml.multisetfreeparams([lc1, lc2], optparams) if plot: plt.semilogy(d2valuelist) plt.show()
def opt_ml(lc1, lc2, dispersionmethod, plot=False, verbose=False): """ microlensing optimization. Sets the eventual microlensings of lc1 and lc2 so to minimize a dispersion. Does not shift the curves in any other way. If plot is True, it displays the steps of the optimization. @type lc1: lightcurve @param lc1: This one will be passed as first argument (i.e. "reference") to the dispersionmethod @type lc2: lightcurve @param lc2: The light curve that will get interpolated by the dispersionmethod. @todo: implement a better plot ... """ initparams = ml.multigetfreeparams([lc1, lc2]) if verbose: print "Initial params : ", initparams if len(initparams) == 0: raise RuntimeError, "There are no free microlensing params to optimize !" if plot: d2valuelist = [] def d2(params): ml.multisetfreeparams([lc1, lc2], params) ret = dispersionmethod(lc1, lc2)["d2"] if plot: d2valuelist.append(ret) return ret # http://www.scipy.org/doc/api_docs/SciPy.optimize.optimize.html#fmin_bfgs #put disp = 0 to make them silent... #optparams = spopt.fmin(d2, initparams) #optparams = spopt.fmin_cg(d2, initparams) #optparams = spopt.fmin_bfgs(d2, params, epsilon =1.0e-5) #optparams = spopt.fmin_bfgs(d2, params, disp=1, retall=0) #optparams = spopt.anneal(d2, params) #optparams = spopt.fmin_ncg(d2, initparams) # this guy would need a gradient. #optparams = spopt.fmin_bfgs(d2, initparams) # precision loss # [ 2.89270193e-10 4.94366701e-08 -2.63101369e-04 -4.38757115e-03] # [ 2.95294380e-10 3.64696903e-08 -2.63882092e-04 -5.66560156e-05] optparams = spopt.fmin_powell(d2, initparams, disp=int(verbose)) # 312 , 2.592636, [ 2.89270193e-10 4.94366701e-08 -2.63101369e-04 -4.38757115e-03] #optparams = spopt.fmin(d2, initparams) # 150, 2.614217 #optparams = spopt.fmin(d2, initparams, xtol = 1.0e-10) #optparams = spopt.fmin_bfgs(d2, params, epsilon =1.0e-5) if verbose: print "Optimal params : ", optparams print repr(optparams) ml.multisetfreeparams([lc1, lc2], optparams) if plot: plt.semilogy(d2valuelist) plt.show()