# Path: osrefl/loaders/reduction/wsolve.py
# def wpolyfit(x,y,dy=1,degree=None,origin=False):
#     """
#     Return the polynomial of degree n that
#     minimizes sum( (p(x_i) - y_i)**2/dy_i**2).
# 
#     if origin is True, the fit should go through the origin.
#     """
#     assert degree != None, "Missing degree argument to wpolyfit"
# 
#     A = _poly_matrix(x,degree,origin)
#     s = wsolve(A,y,dy)
#     return PolynomialModel(s,origin=origin)


import sys
import numpy as N
        import pylab
from osrefl.loaders.reduction.wsolve import wpolyfit
        for i in xrange(len(p)):
            print "%12.5g  %12.5g %12.5g"%(dp[i],Edp[i],err_dp[i])
        print "-"*39
    assert (err_p<tol).all() and (err_dp<tol).all(),\
        "wsolve %s exceeded tolerance of %g"%(name,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

# Path: osrefl/loaders/reduction/wsolve.py
# def wpolyfit(x,y,dy=1,degree=None,origin=False):
#     """
#     Return the polynomial of degree n that
#     minimizes sum( (p(x_i) - y_i)**2/dy_i**2).
# 
#     if origin is True, the fit should go through the origin.
#     """
#     assert degree != None, "Missing degree argument to wpolyfit"
# 
#     A = _poly_matrix(x,degree,origin)
#     s = wsolve(A,y,dy)
#     return PolynomialModel(s,origin=origin)


# Path: osrefl/loaders/reduction/test/test_wpolyfit.py
import sys
import numpy as N
        import pylab
from osrefl.loaders.reduction.wsolve import wpolyfit

        for i in xrange(len(p)):
            print "%12.5g  %12.5g %12.5g"%(dp[i],Edp[i],err_dp[i])
        print "-"*39
    assert (err_p<tol).all() and (err_dp<tol).all(),\
        "wsolve %s exceeded tolerance of %g"%(name,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)