Example #1
0
def ISE(numbeta, Beta_fonc_est, b_learned, T, nb=40, plot_beta=False, resolution=100):
    ise = 0.0
    Tmax = np.max(T)
    Tmin = np.min(T)
    Tgrid = np.linspace(Tmin, Tmax, nb, retstep=True)
    step = Tgrid[1]
    Tgrid = Tgrid[0]
    grille = np.vstack((Tgrid, np.arange(nb)))
    count = 0
    for T_, i in grille.T:
        for t_ in np.arange(0.01, T_, step, float):
            count += 1
            true_b = cg.beta_fonc(t_, T_, numbeta)
            est_b = Beta_fonc_est(*([t_, T_] + list(b_learned[:, 0])))
            ise = ise + (true_b - est_b) ** 2
    ise = ise / count
    print("ISE : " + str(ise))
    if plot_beta:
        x = np.linspace(0.1, np.max(T), num=resolution)
        y = np.linspace(0.1, np.max(T), num=resolution)
        arr = [x, y]
        Grid = cg.expandnp(arr)
        x = Grid[:, 0]
        y = Grid[:, 1]
        arrV = np.zeros(resolution ** 2, float)
        n = 0
        for i in range(resolution):
            for j in range(resolution):
                if j <= i:
                    arrV[n] = Beta_fonc_est[0](x[n], y[n])
                n += 1
        Xfig = x.reshape((resolution, resolution))
        Yfig = y.reshape((resolution, resolution))
        Zfig = arrV.reshape((resolution, resolution))
        fig = plt.figure().add_subplot(111)
        plt.imshow(
            Zfig,
            vmin=Zfig.min(),
            vmax=Zfig.max(),
            origin="lower",
            extent=[Yfig.min(), Yfig.max(), Xfig.min(), Xfig.max()],
        )
        plt.colorbar()
    return ise