def check(name, data, target, origin=False, tol=2e-16): """ name data set name data [y,x] target [p,dp] but low to high rather than high to low """ p = wpolyfit(data[:, 1], data[:, 0], degree=target.shape[0] - 1, origin=origin) Ep, Edp = N.flipud(target).T show_result(name, p.coeff, p.std, Ep, Edp, tol=tol)
def check_uncertainty(n=10000): """ This function computes a number of fits to simulated data to determine how well the values and uncertainties reported by the wpolyfit solver correspond to individual fits of the data. For large N the reported parameters do indeed converge to the mean parameter values for fits to resampled data. Reported parameter uncertainty estimates are not supported by MC. """ ## x y dy data = N.matrix( """ 0.0013852 0.2144023 0.020470; 0.0018469 0.2516856 0.022868; 0.0023087 0.3070443 0.026362; 0.0027704 0.3603186 0.029670; 0.0032322 0.4260864 0.033705; 0.0036939 0.4799956 0.036983 """ ).A x, y, dy = data[:, 0], data[:, 1], data[:, 2] if True: # simpler system to analyze x = N.linspace(2, 4, 12) y = 3 * x + 5 dy = y p = wpolyfit(x, y, dy=dy, degree=1) P = N.empty((2, n), "d") for i in xrange(n): # pi = N.polyfit(x,N.random.normal(y,dy),degree=1) pi = wpolyfit(x, N.random.normal(y, dy), dy=dy, degree=1) P[:, i] = pi.coeff # print "P",P Ep, Edp = N.mean(P, 1), N.std(P, 1) show_result("uncertainty check", p.coeff, p.std, Ep, Edp) if False: import pylab pylab.hist(P[0, :]) pylab.show() """ # Not yet converted from octave
def check_uncertainty(n=10000): """ This function computes a number of fits to simulated data to determine how well the values and uncertainties reported by the wpolyfit solver correspond to individual fits of the data. For large N the reported parameters do indeed converge to the mean parameter values for fits to resampled data. Reported parameter uncertainty estimates are not supported by MC. """ ## x y dy data = N.matrix(""" 0.0013852 0.2144023 0.020470; 0.0018469 0.2516856 0.022868; 0.0023087 0.3070443 0.026362; 0.0027704 0.3603186 0.029670; 0.0032322 0.4260864 0.033705; 0.0036939 0.4799956 0.036983 """).A x, y, dy = data[:, 0], data[:, 1], data[:, 2] if True: # simpler system to analyze x = N.linspace(2, 4, 12) y = 3 * x + 5 dy = y p = wpolyfit(x, y, dy=dy, degree=1) P = N.empty((2, n), 'd') for i in xrange(n): #pi = N.polyfit(x,N.random.normal(y,dy),degree=1) pi = wpolyfit(x, N.random.normal(y, dy), dy=dy, degree=1) P[:, i] = pi.coeff #print "P",P Ep, Edp = N.mean(P, 1), N.std(P, 1) show_result("uncertainty check", p.coeff, p.std, Ep, Edp) if False: import pylab pylab.hist(P[0, :]) pylab.show() """ # Not yet converted from octave