示例#1
0
def solve_matrix_eq( matrix_ntries, vector_entries ) :

    ms = []
    mn = []
    for row in matrix_ntries :
        ms_row = []
        mn_row = []
        for col in row :
            ms_row.append( col.s )
            mn_row.append( col.n )
        ms.append( ms_row )
        mn.append( mn_row )

    matrix = unumpy.umatrix( mn, ms )

    vs = []
    vn = []
    for row in vector_entries :
        vn.append( [ row.n ] )
        vs.append( [ row.s ] )

    vector = unumpy.umatrix( vn, vs )
    
    inv_matrix = None
    try :
        inv_matrix = matrix.getI()
    except :
        print 'Failed to invert matrix, aborting'
        return unumpy.umatrix( [ [1]*len(vs) ], [ [0]*len(vs) ] )

    return inv_matrix*vector
示例#2
0
def test_array_comparisons():
    "Test of array and matrix comparisons"

    arr = unumpy.uarray(([1, 2], [1, 4]))
    assert numpy.all((arr == [arr[0], 4]) == [True, False])

    # For matrices, 1D arrays are converted to 2D arrays:
    mat = unumpy.umatrix(([1, 2], [1, 4]))
    assert numpy.all((mat == [mat[0,0], 4]) == [True, False])
示例#3
0
def test_array_comparisons():
    "Test of array and matrix comparisons"

    arr = unumpy.uarray(([1, 2], [1, 4]))
    assert numpy.all((arr == [arr[0], 4]) == [True, False])

    # For matrices, 1D arrays are converted to 2D arrays:
    mat = unumpy.umatrix(([1, 2], [1, 4]))
    assert numpy.all((mat == [mat[0, 0], 4]) == [True, False])
示例#4
0
def test_array_and_matrix_creation():
    "Test of custom array creation"

    arr = unumpy.uarray(([1, 2], [0.1, 0.2]))

    assert arr[1].nominal_value == 2
    assert arr[1].std_dev() == 0.2

    # Same thing for matrices:
    mat = unumpy.umatrix(([1, 2], [0.1, 0.2]))
    assert mat[0,1].nominal_value == 2
    assert mat[0,1].std_dev() == 0.2
示例#5
0
def test_array_and_matrix_creation():
    "Test of custom array creation"

    arr = unumpy.uarray(([1, 2], [0.1, 0.2]))

    assert arr[1].nominal_value == 2
    assert arr[1].std_dev() == 0.2

    # Same thing for matrices:
    mat = unumpy.umatrix(([1, 2], [0.1, 0.2]))
    assert mat[0, 1].nominal_value == 2
    assert mat[0, 1].std_dev() == 0.2
示例#6
0
def umatmean(mat):
    
    sizex, sizey = mat.shape
    nom = np.zeros(mat.shape)
    stdvs = np.zeros(mat.shape)
    
    for i in range(sizex):
        for j in range(sizey):
            nom[i][j] = mat[i][j].n
            stdvs[i][j] = mat[i][j].s
    
    umat = unumpy.umatrix(nom,stdvs)
    
    return umat
示例#7
0
def test_obsolete():
    'Test of obsolete functions'

    # The new and old calls should give the same results:

    # The unusual syntax is here to protect against automatic code
    # update:
    arr_obs = unumpy.uarray.__call__(([1, 2], [1, 4]))  # Obsolete call
    arr = unumpy.uarray([1, 2], [1, 4])
    assert arrays_close(arr_obs, arr)

    # The new and old calls should give the same results:
    
    # The unusual syntax is here to protect against automatic code
    # update:
    mat_obs = unumpy.umatrix.__call__(([1, 2], [1, 4]))  # Obsolete call
    mat = unumpy.umatrix([1, 2], [1, 4])
    assert arrays_close(mat_obs, mat)
示例#8
0
def test_obsolete():
    'Test of obsolete functions'

    # The new and old calls should give the same results:

    # The unusual syntax is here to protect against automatic code
    # update:
    arr_obs = unumpy.uarray.__call__(([1, 2], [1, 4]))  # Obsolete call
    arr = unumpy.uarray([1, 2], [1, 4])
    assert arrays_close(arr_obs, arr)

    # The new and old calls should give the same results:

    # The unusual syntax is here to protect against automatic code
    # update:
    mat_obs = unumpy.umatrix.__call__(([1, 2], [1, 4]))  # Obsolete call
    mat = unumpy.umatrix([1, 2], [1, 4])
    assert arrays_close(mat_obs, mat)
        str(WJ_3) + " $\pm$ " + str(round(err_4, 2)) + " &"
    ]
    dftex_dict['QCD &'] = [
        str(QCD_1) + " $\pm$ " + str(round(err_15, 2)) + " &",
        str(QCD_2) + " $\pm$ " + str(round(err_16, 2)) + " &",
        str(QCD_3) + " $\pm$ " + str(round(err_17, 2)) + " &"
    ]
    dftex_dict['Data $- QCD_{MC}$\\\\ \\hline'] = [
        "-- $\pm$ --" + " \\\\ \\hline",
        str(Data_2 - QCD_2) + " $\pm$ " +
        str(round(sqrt(err_3**2 + err_16**2), 2)) + "  \\\\ \\hline",
        str(Data_3 - QCD_3) + " $\pm$ " +
        str(round(sqrt(err_5**2 + err_17**2), 2)) + "  \\\\"
    ]

    a = unumpy.umatrix([[TTJ_2, WJ_2], [TTJ_3, WJ_3]],
                       [[err_8, err_1], [err_9, err_4]])

    b = unumpy.umatrix(
        [[Data_2 - QCD_2], [Data_3 - QCD_3]],
        [[sqrt(err_3**2 + err_16**2)], [sqrt(err_5**2 + err_17**2)]])

    Y_ = a.I * b
    Y = np.squeeze(np.asarray(unumpy.nominal_values(Y_)))
    Yerr = np.squeeze(np.asarray(unumpy.std_devs(Y_)))
    #print (np.allclose(np.dot(a, Y), b))
    alpha, beta, delta = round(Y[0], 2), round(Y[1], 2), 1.0
    alphaerr, betaerr, deltaerr = round(Yerr[0], 2), round(Yerr[1], 2), 0.0

    # make WJ histogram
    EWK = ROOT.TH1F('EWK', 'EWK', 30, -0.5, 2.5)
    for key in Lp_dict:
示例#10
0
        txtCR3.write("{:<20}{:<20}{:<20}".format(
            otherCR3.GetTitle(),
            round(
                otherCR3.IntegralAndError(0,
                                          otherCR3.GetNbinsX() +
                                          1, err_9), 2), round(err_9, 2)) +
                     "\n")
        TTJ_3 = round(
            otherCR3.IntegralAndError(0,
                                      otherCR3.GetNbinsX() + 1, err_9), 2)

        del otherSR, otherCR1, otherCR2, otherCR3

        import scipy

        a = unumpy.umatrix([[TTJ_2, WJ_2], [TTJ_3, WJ_3]],
                           [[err_8, err_1], [err_9, err_4]])

        b = unumpy.umatrix([[Data_2], [Data_3]], [[err_3], [err_5]])

        #fun = lambda x: np.linalg.norm(np.dot(a,x)-b)
        #Y = minimize(fun, np.zeros(n), method='L-BFGS-B', bounds=[(0.,None) for x in range(n)])
        #Y = Y['x']
        #Y = np.linalg.solve(a,b)
        Y_ = a.I * b
        Y = np.squeeze(np.asarray(unumpy.nominal_values(Y_)))
        Yerr = np.squeeze(np.asarray(unumpy.std_devs(Y_)))

        #print (np.allclose(np.dot(a, Y), b))
        alpha, beta = round(Y[0], 2), round(Y[1], 2)
        alphaerr, betaerr = round(Yerr[0], 2), round(Yerr[1], 2)
        txtalphabetagamma.write(
示例#11
0
            otherCR4.GetTitle(),
            round(
                otherCR4.IntegralAndError(0,
                                          otherCR4.GetNbinsX() +
                                          1, err_14), 2), round(err_14, 2)) +
                     "\n")
        WJ_4 = round(
            otherCR4.IntegralAndError(0,
                                      otherCR4.GetNbinsX() + 1, err_14), 2)

        del otherSR, otherCR1, otherCR2, otherCR3, otherCR4

        import scipy

        a = unumpy.umatrix([[TTl_2, TTll_2, WJ_2], [TTl_3, TTll_3, WJ_3],
                            [TTl_4, TTll_4, WJ_4]],
                           [[err_1, err_2, err_12], [err_4, err_5, err_13],
                            [err_7, err_8, err_14]])

        b = unumpy.umatrix([[Data_2], [Data_3], [Data_4]],
                           [[err_3], [err_6], [err_9]])

        #fun = lambda x: np.linalg.norm(np.dot(a,x)-b)
        #Y = minimize(fun, np.zeros(n), method='L-BFGS-B', bounds=[(0.,None) for x in range(n)])
        #Y = Y['x']
        #Y = np.linalg.solve(a,b)
        Y_ = a.I * b
        Y = np.squeeze(np.asarray(unumpy.nominal_values(Y_)))
        Yerr = np.squeeze(np.asarray(unumpy.std_devs(Y_)))

        #print (np.allclose(np.dot(a, Y), b))
        alpha, beta, gamma = round(Y[0], 2), round(Y[1], 2), round(Y[2], 2)
    txtCR3.write("{:<20}{:<20}{:<20}".format(
        otherCR3.GetTitle(),
        round(otherCR3.IntegralAndError(0,
                                        otherCR3.GetNbinsX() +
                                        1, err_18), 2), round(err_18, 2)) +
                 "\n")
    WJ_3 = round(
        otherCR3.IntegralAndError(0,
                                  otherCR3.GetNbinsX() + 1, err_18), 2)

    del otherSRLDM, otherSRHDM, otherCR1, otherCR2, otherCR3

    import scipy

    a = unumpy.umatrix(
        [[TTl_1, TTll_1, WJ_1], [TTl_2, TTll_2, WJ_2], [TTl_3, TTll_3, WJ_3]],
        [[err_1, err_2, err_16], [err_4, err_5, err_17],
         [err_7, err_8, err_18]])

    b = unumpy.umatrix([[Data_1], [Data_2], [Data_3]],
                       [[err_3], [err_6], [err_9]])

    #fun = lambda x: np.linalg.norm(np.dot(a,x)-b)
    #Y = minimize(fun, np.zeros(n), method='L-BFGS-B', bounds=[(0.,None) for x in range(n)])
    #Y = Y['x']
    #Y = np.linalg.solve(a,b)
    Y_ = a.I * b
    Y = np.squeeze(np.asarray(unumpy.nominal_values(Y_)))
    Yerr = np.squeeze(np.asarray(unumpy.std_devs(Y_)))

    #print (np.allclose(np.dot(a, Y), b))
    alpha, beta, gamma = round(Y[0], 2), round(Y[1], 2), round(Y[2], 2)
示例#13
0
def solve_err(A, dA, b, db):
    A = umatrix(A, dA)
    b = umatrix(b, db).T
    x = A.I*b
    return uval(x), udev(x)
示例#14
0
    ]
    dftex_dict['Data \\\\ \\hline'] = [
        "-- $\pm$ -- \\\\ \\hline",
        str(Data_2) + " $\pm$ " + str(round(err_3, 2)) + " \\\\ \\hline",
        str(Data_3) + " $\pm$ " + str(round(err_6, 2)) + " \\\\ \\hline",
        str(Data_4) + " $\pm$ " + str(round(err_9, 2)) + " \\\\ \\hline",
        str(Data_QCDCR) + " $\pm$ " + str(round(err_22, 2)) + " \\\\"
    ]

    del otherSR, otherCR1, otherCR2, otherCR3, otherCR4

    import scipy

    a = unumpy.umatrix(
        [[TTl_2, TTll_2, WJ_2, QCD_2], [TTl_3, TTll_3, WJ_3, QCD_3],
         [TTl_4, TTll_4, WJ_4, QCD_4],
         [TTl_QCDCR, TTll_QCDCR, WJ_QCDCR, QCD_QCDCR]],
        [[err_1, err_2, err_12, err_16], [err_4, err_5, err_13, err_17],
         [err_7, err_8, err_14, err_18], [err_19, err_20, err_21, err_24]])

    b = unumpy.umatrix([[Data_2], [Data_3], [Data_4], [Data_QCDCR]],
                       [[err_3], [err_6], [err_9], [err_22]])

    #fun = lambda x: np.linalg.norm(np.dot(a,x)-b)
    #Y = minimize(fun, np.zeros(n), method='L-BFGS-B', bounds=[(0.,None) for x in range(n)])
    #Y = Y['x']
    #Y = np.linalg.solve(a,b)
    Y_ = a.I * b
    Y = np.squeeze(np.asarray(unumpy.nominal_values(Y_)))
    Yerr = np.squeeze(np.asarray(unumpy.std_devs(Y_)))

    #print(Y,Yerr)
示例#15
0
def solve_err(A, dA, b, db):
    A = umatrix(A, dA)
    b = umatrix(b, db).T
    x = A.I*b
    return uval(x), udev(x)
示例#16
0
        str(QCD_1) + " $\pm$ " + str(round(err_15, 2)) + " &",
        str(QCD_2) + " $\pm$ " + str(round(err_16, 2)) + " &",
        str(QCD_3) + " $\pm$ " + str(round(err_17, 2)) + " &",
        str(QCD_QCDCR) + " $\pm$ " + str(round(err_21, 2)) + " &"
    ]
    dftex_dict['Data \\\\ \\hline'] = [
        "-- $\pm$ --" + " \\\\ \\hline",
        str(Data_2) + " $\pm$ " + str(round(err_3, 2)) + "  \\\\ \\hline",
        str(Data_3) + " $\pm$ " + str(round(err_5, 2)) + "  \\\\ \\hline",
        str(Data_QCDCR) + " $\pm$ " + str(round(err_22, 2)) + " \\\\"
    ]

    import scipy

    a = unumpy.umatrix([[TTJ_2, WJ_2, QCD_2], [TTJ_3, WJ_3, QCD_3],
                        [TTJ_QCDCR, WJ_QCDCR, QCD_QCDCR]],
                       [[err_8, err_1, err_16], [err_9, err_4, err_17],
                        [err_24, err_19, err_21]])

    b = unumpy.umatrix([[Data_2], [Data_3], [Data_QCDCR]],
                       [[err_3], [err_5], [err_22]])

    #fun = lambda x: np.linalg.norm(np.dot(a,x)-b)
    #Y = minimize(fun, np.zeros(n), method='L-BFGS-B', bounds=[(0.,None) for x in range(n)])
    #Y = Y['x']
    #Y = np.linalg.solve(a,b)
    Y_ = a.I * b
    Y = np.squeeze(np.asarray(unumpy.nominal_values(Y_)))
    Yerr = np.squeeze(np.asarray(unumpy.std_devs(Y_)))
    #print (np.allclose(np.dot(a, Y), b))
    alpha, beta, delta = round(Y[0], 2), round(Y[1], 2), round(Y[2], 2)
    alphaerr, betaerr, deltaerr = round(Yerr[0],
示例#17
0
    dftex_dict['Data $- QCD_{MC}$\\\\ \\hline'] = [
        "-- $\pm$ -- \\\\ \\hline",
        str(Data_2 - QCD_2) + " $\pm$ " +
        str(round(sqrt(err_3**2 + err_16**2), 2)) + " \\\\ \\hline",
        str(Data_3 - QCD_3) + " $\pm$ " +
        str(round(sqrt(err_6**2 + err_17**2), 2)) + " \\\\ \\hline",
        str(Data_4 - QCD_4) + " $\pm$ " +
        str(round(sqrt(err_9**2 + err_18**2), 2)) + " \\\\"
    ]

    #del otherSR,otherCR1,otherCR2,otherCR3,otherCR4

    import scipy

    a = unumpy.umatrix(
        [[TTl_2, TTll_2, WJ_2], [TTl_3, TTll_3, WJ_3], [TTl_4, TTll_4, WJ_4]],
        [[err_1, err_2, err_12], [err_4, err_5, err_13],
         [err_7, err_8, err_14]])

    b = unumpy.umatrix(
        [[Data_2 - QCD_2], [Data_3 - QCD_3], [Data_4 - QCD_4]],
        [[sqrt(err_3**2 + err_16**2)], [sqrt(err_6**2 + err_17**2)],
         [sqrt(err_9**2 + err_18**2)]])

    #fun = lambda x: np.linalg.norm(np.dot(a,x)-b)
    #Y = minimize(fun, np.zeros(n), method='L-BFGS-B', bounds=[(0.,None) for x in range(n)])
    #Y = Y['x']
    #Y = np.linalg.solve(a,b)
    Y_ = a.I * b
    Y = np.squeeze(np.asarray(unumpy.nominal_values(Y_)))
    Yerr = np.squeeze(np.asarray(unumpy.std_devs(Y_)))