def plot_instantaneous(self, legstr=""): semilogx(self.E, legend = legstr) xlabel("num_{mcs}") ylabel("instantaneous energy")
def plot_instantaneous(self, legstr=""): semilogx(self.E, legend=legstr) xlabel("num_{mcs}") ylabel("instantaneous energy")
if sim.ID == "bf_mc": prec_bf_mc.append([sim.N, sim.energy]) if sim.ID == "is_mc": prec_is_mc.append([sim.N, sim.energy]) exact = sim.exact_solution; prec_gaulag = np.asarray(prec_gaulag) prec_gauleg = np.asarray(prec_gauleg) prec_is_mc = np.asarray(prec_is_mc) prec_bf_mc = np.asarray(prec_bf_mc) sort_data(prec_gaulag) sort_data(prec_gauleg) sort_data(prec_is_mc) sort_data(prec_bf_mc) figure() semilogx(prec_gaulag[:,0], prec_gaulag[:,1]) hold("all") semilogx(prec_gauleg[:,0], prec_gauleg[:,1]) semilogx(prec_bf_mc[:,0], prec_bf_mc[:,1]) semilogx(prec_is_mc[:,0], prec_is_mc[:,1]) semilogx([1e2, 1e10], [exact, exact], '--') legend("Gauss Laguerre", "Gauss Legendre", "Brute force Monte Carlo", "Importance sampling Monte Carlo", "exact") xlabel("Function evaluations") ylabel("Calculated energy") title("Convergence of the different methods") hold("off"); print "Results with highest resolution for all methods" print "Gauss Legendre: %.8f" % prec_gauleg[len(prec_gauleg)-1, 1], "Evaluations: %g" % prec_gauleg[len(prec_gauleg)-1, 0] print "Gauss Laguerre: %.8f" % prec_gaulag[len(prec_gaulag)-1, 1], "Evaluations: %g" % prec_gaulag[len(prec_gaulag)-1, 0] print "Brute force Monte Carlo: %.8f" % prec_bf_mc[len(prec_bf_mc)-1, 1], "Evaluations: %g" % prec_bf_mc[len(prec_bf_mc)-1, 0]