def r2(self, nostab=True, nosquare=False):
"""
Evaluates the spline, compares it with the data points and returns a weighted sum of residuals r2.
If nostab = False, stab points are included
This is precisely the same r2 as is used by splrep for the fit, and thus the same value as
returned by optc !
This method can set lastr2nostab, so be sure to end any optimization with it.
If nostab = True, we don't count the stab points
"""
if nostab == True :
splinemags = self.eval(nostab = True, jds = None)
errs = self.datapoints.mags[self.datapoints.mask] - splinemags
werrs = errs/self.datapoints.magerrs[self.datapoints.mask]
if nosquare:
r2 = np.sum(np.fabs(werrs))
else:
r2 = np.sum(werrs * werrs)
self.lastr2nostab = r2
else :
splinemags = self.eval(nostab = False, jds = None)
errs = self.datapoints.mags - splinemags
werrs = errs/self.datapoints.magerrs
if nosquare:
r2 = np.sum(np.fabs(werrs))
else:
r2 = np.sum(werrs * werrs)
self.lastr2stab = r2
return r2
#if red:
# return chi2/len(self.datapoints.jds)
评论列表
文章目录