Pot_NLO = np.empty((Nch, Nch, Ndata, Nconf))
    
    for iconf in range(Nconf):
        tmpPot__LO, tmpPot_NLO = calc_potential_NLO(Pot[:,:,:,:,iconf], 
                                                    Rcr[:,:,:,:,iconf], 
                                                    LpR[:,:,:,:,iconf])
        if (tmpPot__LO is tmpPot_NLO is None):
            quit()
        for idata in range(Ndata):
            for i in range(Nch):
                for j in range(Nch):
                    Pot__LO[i, j, idata, iconf] = tmpPot__LO[i, j, idata]
                    Pot_NLO[i, j, idata, iconf] = tmpPot_NLO[i, j, idata]
    
    output_bin_data(oFbase+"/LN-LN_CCP__LO_t%d"%(time), Pot__LO[0, 0, :, :], xData)
    output_bin_data(oFbase+"/LN-LN_CCP_NLO_t%d"%(time), Pot_NLO[0, 0, :, :], xData)
    output_bin_data(oFbase+"/LN-SN_CCP__LO_t%d"%(time), Pot__LO[0, 1, :, :], xData)
    output_bin_data(oFbase+"/LN-SN_CCP_NLO_t%d"%(time), Pot_NLO[0, 1, :, :], xData)
    output_bin_data(oFbase+"/SN-LN_CCP__LO_t%d"%(time), Pot__LO[1, 0, :, :], xData)
    output_bin_data(oFbase+"/SN-LN_CCP_NLO_t%d"%(time), Pot_NLO[1, 0, :, :], xData)
    output_bin_data(oFbase+"/SN-SN_CCP__LO_t%d"%(time), Pot__LO[1, 1, :, :], xData)
    output_bin_data(oFbase+"/SN-SN_CCP_NLO_t%d"%(time), Pot_NLO[1, 1, :, :], xData)
    
    for i in range(Nch):
        for j in range(Nch):
            for idata in range(Ndata):
                mean0, err0 = make_mean_err(Pot__LO[i, j, idata, :])
                mean1, err1 = make_mean_err(Pot_NLO[i, j, idata, :])
                print("%lf %e %e %e %e" % (xData[idata], mean0, err0, mean1, err1))
            print("\n")
示例#2
0
            Params_perV[0, i] = integrand_1D_PotOpt_DensWS
            Params_perV[1, i] = tmpFunc_perV
            Params_perV[2, i] = tmpParams_perV[:, i]
            Params_perV[3, i] = Params_dens

    #print factor_perV; print Func_perV; print Params_perV; quit()

### Calculation & Output
    if (iFname_orgV is not None):
        Energy_0 = np.empty(Nconf)
        print("#")
        for i in range(Nconf):
            Energy_0[i] = solve_sch_0th_pert(Range, Coeff[:, i], mass,
                                             Func_orgV, Params_orgV[:, i])
            print("# conf = %d: End" % i)

        Mean, Err = make_mean_err(Energy_0)
        print("#\n# E_0 = %1.16f +/- %1.16f" % (Mean, Err))

    Energy_1 = np.empty(Nconf)
    print("#")
    for i in range(Nconf):
        Energy_1[i] = solve_sch_1st_pert(Range, Coeff[:, i], Func_perV,
                                         Params_perV[:, i])
        print("# conf = %d: End" % i)

    Mean, Err = make_mean_err(Energy_1)
    print("#\n# E_1 = %1.16f +/- %1.16f" % (Mean, Err))

    print("#\n# JOB END: elapsed_time = %lf [sec]" % (time.time() - JOB_start))
    print("#.data  = %d" % Ndata)

    xData = np.empty(Ndata)
    eData = np.empty(Ndata)
    yData = np.empty((Ndata, Nfile))

    for idata in range(Ndata):
        xData[idata] = tmpData[idata, 0]
        yData[idata, 0] = tmpData[idata, 1]

    for iarg in range(1, Nfile):
        print("Reading: %s" % iFname[iarg])
        tmpData = input_text_data(iFname[iarg])

        if (len(tmpData[0, :]) != 2):
            print("ERROR: ONLY 2-column text data can be read, exit.")
            quit()

        for idata in range(Ndata):
            yData[idata, iarg] = tmpData[idata, 1]

            if (xData[idata] != tmpData[idata, 0]):
                print("ERROR: x-data are different, exit.")
                quit()

    for idata in range(Ndata):
        eData[idata] = make_mean_err(yData[idata, :])[1]

    print("Writing: %s" % oFname)
    output_bin_data(oFname, yData, xData, eData)
    
    for i in range(Ndata):
        if (xData1[i] != xData2[i] or 
            xData1[i] != xData3[i] or 
            xData1[i] != xData4[i] or 
            xData2[i] != xData3[i] or 
            xData2[i] != xData4[i] or 
            xData3[i] != xData4[i]):
            print("\nERROR: x-data is differ, exit.\n"); quit()
        
        for iconf in range(Nconf):
            V_NLO[i, iconf] = FitFunc(xData1[i], *Params[:, iconf]) / (yData3[i, iconf] - yData4[i, iconf])
            
            tmpV_LO1[iconf] = yData1[i, iconf] - yData3[i, iconf] * V_NLO[i, iconf]
            tmpV_LO2[iconf] = yData2[i, iconf] - yData4[i, iconf] * V_NLO[i, iconf]
            
            # Selection:
            V__LO[i, iconf] =  tmpV_LO1[iconf]
            #V__LO[i, iconf] =  tmpV_LO2[iconf]
            #V__LO[i, iconf] = (tmpV_LO1[iconf] + tmpV_LO2[iconf]) / 2.0
        
        m__LO, e__LO = make_mean_err(V__LO[i, :])
        m_NLO, e_NLO = make_mean_err(V_NLO[i, :])
        # For Debug:
        #m__LO, e__LO = make_mean_err(tmpV_LO1)
        #m_NLO, e_NLO = make_mean_err(tmpV_LO2)
        print("%lf %1.16e %1.16e %1.16e %1.16e" % (xData1[i], m__LO, e__LO, m_NLO, e_NLO))
    
    output_bin_data(oFname__LO, V__LO, xData1)
    output_bin_data(oFname_NLO, V_NLO, xData1)
                                       yData[:, iconf],
                                       sigma=eData,
                                       p0=in_Params,
                                       bounds=LU_bounds)
            #, maxfev=Max_iter)
            #, max_nfev=Max_iter)

            Chisq_dof[iconf] = np.sum(
                ((fit_func(xData, *tmpParams) - yData[:, iconf]) / eData)**
                2) / (Ndata - Nparam)

            for iparam in range(Nparam):
                ResParams[iparam, iconf] = tmpParams[iparam]

        print("# === Fitting Results (%d) ===" % (ires + 1))
        tmp_mean, tmp_err = make_mean_err(Chisq_dof)
        print("# Chisq/dof = %lf +/- %lf" % (tmp_mean, tmp_err))
        print("# Parameters:"),
        for iparam in range(Nparam):
            tmp_mean, tmp_err = make_mean_err(ResParams[iparam, :])
            in_Params[iparam] = tmp_mean
            print("%e" % tmp_mean),
        print

### Print Results ###
    print("#\n# === Fitting Results (Final) ===")
    tmp_mean, tmp_err = make_mean_err(Chisq_dof)
    print("# Chisq/dof = %lf +/- %lf" % (tmp_mean, tmp_err))
    tmpParams = np.empty(Nparam)
    for iparam in range(Nparam):
        tmpParams[iparam], tmp_err = make_mean_err(ResParams[iparam, :])
                                                  (1.0, 1.0)), Params_dens)
                else:
                    Results_Coul_woF = Fpot_C(r_fpot, Integrand_1D,
                                              fitfunc_Coulomb,
                                              np.array(
                                                  (1.0, 1.0)), Params_dens)
                    Results_Coul_w_F = Fpot_C(r_fpot, Integrand_1D,
                                              fitfunc_Coulomb_wF,
                                              np.array(
                                                  (1.0, 1.0)), Params_dens)

                #print("%lf %1.16lf %1.16lf" % (r_fpot, Results_Coul_woF, Results_Coul_w_F))
                #Results += Results_Coul_woF
                Results += Results_Coul_w_F

            Mean, Err = make_mean_err(Results)

            print("%lf %1.16e %1.16e" % (r_fpot, Mean, Err))

            #print("%lf" % r_fpot), # For all configurations
            #for iconf in range(Nconf):
            #    print(" %e" % Results[iconf]),
            #print

    else:
        if (dens_type != 'Gaussian'):
            print(
                "\nERROR: The density-type '%s' cannot be converted, exit.\n" %
                dens_type)
            quit()
        if (re.match('^[1-9]G$', FuncName_pot) is None):
    yData2, xData2, Dummy = input_bin_data(iFname2)
    if (xData2 is yData2 is Dummy is None):
        quit()

    if (len(xData1) != len(xData2)):
        print("ERROR: The lengths of each file are differ, exit.\n")
        quit()

    Ndata = len(xData1)

    for i in range(Ndata):
        if (xData1[i] != xData2[i]):
            print("ERROR: The x-data of each file are differ, exit.\n")
            quit()

    Nconf = len(yData1[0, :])
    tmp_d = empty(Nconf)

    for iconf in range(Nconf):
        tmp_d[iconf] = 0.0

    for idata in range(Ndata):
        for iconf in range(Nconf):
            tmp_d[iconf] = yData1[idata, iconf] - yData2[idata, iconf]
            #tmp_d[iconf] += abs(yData1[idata, iconf] - yData2[idata, iconf])
        mean, err = make_mean_err(tmp_d)
        print("%lf %1.16lf %1.16lf" % (xData1[idata], mean, err))

    mean, err = make_mean_err(tmp_d)
    print("#Dif: %1.16lf +/- %1.16lf" % (mean, err))
    print
    quit()


def set_args(ARGC, ARGV):
    global iFname

    iFname = ARGV[1].strip()


###### Main part
if __name__ == "__main__":
    argv = sys.argv
    argc = len(argv)

    if (argc != 2):
        usage(argv)

    set_args(argc, argv)

    yData, xData, eData = input_bin_data(iFname)
    if (xData is yData is eData is None):
        quit()

    for idata in range(len(xData)):
        mean, err = make_mean_err(yData[idata, :])
        print("%lf %1.16e %1.16e" % (xData[idata], mean, err)),
        for iconf in range(len(yData[idata, :])):
            print(" %1.16e" % yData[idata, iconf]),
        print
示例#9
0
###### Main part
if __name__ == "__main__":
    from numpy import empty

    argv = sys.argv
    argc = len(argv)

    if (argc == 1 or argc > 3):
        usage(argv)

    set_args(argc, argv)
    print("# r_max = %lf" % r_max)

    yData, xData, Dummy = input_bin_data(iFname)
    if (xData is yData is Dummy is None):
        quit()

    Nconf = len(yData[0, :])
    Ndata = len(yData[:, 0])

    r2V = empty(Nconf)

    for iconf in range(Nconf):
        r2V[iconf] = 0.0
        for idata in range(Ndata):
            if (r_max > xData[idata]):
                r2V[iconf] += yData[idata, iconf] * xData[idata]**2

    mean, err = make_mean_err(r2V)
    print("r2V: %1.16lf +/- %1.16lf" % (mean, err))