Example #1
0
def model_genz(modelPar):
    npar = modelPar.shape[0]
    mdim = modelPar.shape[1]
    genzparams = 1. / np.arange(1, mdim + 2)
    #genzparams[1:]=1./(genzparams[1:]+1)
    print genzparams
    modelnames = ['genz_gaus', 'genz_exp']

    nout = len(modelnames)

    output = np.empty((npar, nout))
    for j in range(nout):
        output[:, j] = func(modelPar, modelnames[j], genzparams)

    return output
Example #2
0
def find_error(pts, ndim, model, integ_ex, func_params):
    #Initialize average error to zero
    avg_error = 0
    #Do MC integration 10 times
    for i in range(1, 11):
        #Generate random points to evaluate the function at
        x_mc = np.random.uniform(-1, 1, size=(pts, ndim))
        #Evaluate function
        mc_ypts = func(x_mc, model, func_params)
        #Initialize mc_int (value of monte carlo integration) to zero
        mc_int = 0
        #Average the function values
        for ypt in mc_ypts:
            mc_int += ypt / float(pts)
        #Find error from exact integral
        mc_error = abs(integ_ex - mc_int)
        #Add error/10 to average error
        avg_error += mc_error / 10.
    return avg_error
Example #3
0
#Let the number of sampling points for MC integrations be the same as the total number of quad points
mc_pts = tot_pts

###### Quadrature Integration ######

#list to store quad errors
q_errors = []

#Loop though different values for number of quad points per dimension
for quad_param in num_points:
    #Generate quadrature points
    xpts, wghts = generate_qw(ndim, quad_param)

    #Evaluate the function
    func_params = ones(ndim + 1)  #Genz parameters
    ypts = func(xpts, model, func_params)

    #Quadrature integration
    integ = dot(ypts, wghts)
    #Evaluate its exact integral
    integ_ex = integ_exact(model, func_params)
    #Calculate error in quad integration and add to list
    q_error = abs(integ - integ_ex)
    q_errors.append(q_error)

###### Monte Carlo Integration ######

#Empty list to store MC errors
mc_errors = []
#Let number of sampling points vary
for pts in mc_pts: