Ejemplo n.º 1
0
def histogram_test(X0=1, 
                   U=lambda x : np.log(2*np.cosh(0.5*np.pi*x)),
                   gradU=lambda x : 0.5*np.pi*np.tanh(0.5*np.pi*x),
                   d=1,
                   n=int(1e5)):
    model = PotentialProcess(U, gradU, X0, d)
    coeff = PolynomialStep(1/3, 1/3)
    simulation = Euler(model, coeff)
    simulation.run(n)
    nu_x, nu_x2 = simulation.test_functions([0, 1])

    plt.figure()
    plt.hist(x=simulation.invariant_law,
            weights=simulation.weights, 
            bins=20,
            density=True,
            range=(-5, 5),
            )
    x = np.linspace(-10,10,num=1000)
    y = np.exp(-U(x))
    plt.plot(x,y)
    plt.xlabel("x")
    plt.ylabel("density")
    plt.title("Invariant measure with hyperbolic secante potential. X0={},\nnu(x)={:.2f}, nu(x^2)={:.2f}\nn={} ".format(X0, nu_x[0], nu_x2[0],n))
    plt.show()
Ejemplo n.º 2
0
def heatmap(nb_functions=list(range(l)),
            theta=0.5,
            mu=0,
            sigma=1,
            X0=0,
            d=1,
            n=int(1e4),
            alpha_poly_min=0.11,
            alpha_poly_sup=0.5,
            nb_division_alpha=10,
            beta_poly_min=0.11,
            beta_poly_sup=0.5,
            nb_division_beta=10):
    model = OrnsteinUhlenbeck(theta, mu, sigma, X0, d)
    grille_puissance_alpha = np.linspace(alpha_poly_min,
                                         alpha_poly_sup,
                                         num=nb_division_alpha)
    grille_puissance_beta = np.linspace(beta_poly_min,
                                        beta_poly_sup,
                                        num=nb_division_beta)

    def show_heatmap(nth, mean):
        plt.imshow(np.abs(values_list[:, :, nth] - mean))
        plt.colorbar()
        plt.xticks(ticks=[i for i in range(nb_division_beta)],
                   labels=np.round(grille_puissance_beta, 2))
        plt.yticks(ticks=[i for i in range(nb_division_alpha)],
                   labels=np.round(grille_puissance_alpha, 2))
        plt.title(
            "Heatmap with different alpha-beta with the function = {}".format(
                test_collection[nth]))
        plt.show()

    values_list = []
    for alpha in grille_puissance_alpha:
        values_with_same_alpha = []
        for beta in grille_puissance_beta:
            coeff = PolynomialStep(alpha, beta)
            simulation = Euler(model, coeff)
            simulation.run(n)
            values_with_same_alpha.append(simulation.test_functions())
        values_list.append(values_with_same_alpha)
    values_list = np.array(values_list)

    for nb_function in nb_functions:
        show_heatmap(nb_function, 0.0)
Ejemplo n.º 3
0
def limite_law(X0=1, c=0.5, n=int(1e5), M=int(1e3), shift=0):
    model = MultipleInvariantMeasure(X0, c)
    coeff = PolynomialShiftedStep(1 / 3, 1 / 3, shift)
    simulation = Euler(model, coeff)
    means = []
    for i in tqdm(range(M)):
        simulation.run(n)
        means.append(simulation.test_functions([0])[0][0])
    plt.hist(
        x=means,
        bins=20,
        density=True,
    )
    plt.xlabel("x_mean")
    plt.ylabel("density")
    plt.title(
        "Histogram of the mean(x) for n = {}, M={}\n X0={}, c={}, shift={}".
        format(n, M, X0, c, shift))
    plt.show()
Ejemplo n.º 4
0
 def distrib_result(coeff):
     values = []
     phi = test_collection[2]
     simulation = Euler(model, coeff)
     for i in range(M):
         simulation.reset()
         simulation.run(n)
         values.append(simulation.nu_f(phi))
     return np.array(values)
Ejemplo n.º 5
0
def histogram_test(X0=1, c=0.5, n=int(1e5), shift=0):
    model = MultipleInvariantMeasure(X0, c)
    #coeff = PolynomialStep(1/3, 1/3)
    coeff = PolynomialShiftedStep(1 / 3, 1 / 3, shift)
    simulation = Euler(model, coeff)
    simulation.run(n)
    nu_x, nu_x2 = simulation.test_functions([0, 1])

    plt.figure()
    plt.hist(
        x=simulation.invariant_law,
        weights=simulation.weights,
        bins=20,
        density=True,
        range=(-5, 5),
    )
    plt.xlabel("x")
    plt.ylabel("density")
    plt.title(
        "Different invariant measures test. X0={}, c={}\nnu(x)={:.2f}, nu(x^2)={:.2f}\nn={}"
        .format(X0, c, nu_x[0], nu_x2[0], n))
    plt.show()
Ejemplo n.º 6
0
 def run(coeff):
     simulation = Euler(model, coeff)
     simulation.run(n)
     simulation.test_functions(nb_functions, MODE_DISPLAY=True)