def general_test(): # Levels and repetitions levels = 4 repetitions = [1000, 500, 1000, 1000] MLMCprob = MLMC_Problem(binProblem, samp, lvl_maker) MLMCsolv = MLMC_Solver(MLMCprob, levels, repetitions) estimate = MLMCsolv.solve() print(estimate)
def general_test_serial(): # Levels and repetitions s = time.time() levels = 2 repetitions = [100, 100] MLMCprob = MLMC_Problem(problemClass, samp, lvl_maker) MLMCsolv = MLMC_Solver(MLMCprob, levels, repetitions) estimate, lvls = MLMCsolv.solve() print("Total Time Taken: ", time.time() - s) print(estimate) print(lvls)
def general_test_para(): # Levels and repetitions s = time.time() levels = 2 repetitions = [64, 64] limits = [1, 1] MLMCprob = MLMC_Problem(problemClass, samp, lvl_maker) MLMCsolv = MLMC_Solver(MLMCprob, levels, repetitions, comm=MPI.COMM_WORLD, comm_limits=limits) estimate, lvls = MLMCsolv.solve() if MPI.COMM_WORLD.Get_rank() == 0: print("Total Time Taken: ", time.time() - s) print(estimate) print(list(lvls))
def plotting(): import matplotlib.pyplot as plt xs = np.linspace(0, 1, 1001) g, _ = sampler(None) plt.plot(xs, g(xs), linewidth=0.5) xf, xc = level_maker(0, 1) plt.plot(xc, g(xc), 'x-') plt.plot(xf, g(xf), '+-') plt.show() # Levels and repetitions levels = 3 repetitions = [100, 14, 2] MLMCprob = MLMC_Problem(SimpleProblem, sampler, level_maker) MLMCsolv = MLMC_Solver(MLMCprob, levels, repetitions) estimate = MLMCsolv.solve() print(estimate) reps = levels * repetitions[-1] xf, _ = level_maker(2, -1) prob = SimpleProblem(xf) total = 0 for _ in range(reps): total += prob.solve(sampler(None)[0]) print(total / reps)