コード例 #1
0
def plots_weights_layer(mu_W,
                        sigma_W,
                        sigma_b,
                        mu_b,
                        ax1,
                        ax2,
                        legend_layer,
                        plot_pdf=1):
    """
        Plot the given weights of the layer
        """
    # For each of the weights we plot them !!
    color = gl.get_color(None)
    if (plot_pdf):
        for i in range(sigma_W.size):
            x_grid, y_val = bMA.gaussian1D_points(mean=mu_W[i],
                                                  std=sigma_W[i],
                                                  std_K=3)

            gl.plot(
                x_grid,
                y_val,
                ax=ax1,
                fill=1,
                alpha=0.15,
                color=color,
                labels=["Bayesian weights", "", "p(w)"],
                alpha_line=0.15  # ,legend = ["W:%i"%(i+1)]
            )  ###legend = ["M: %.2e, std: %.2e"%(mu_W2[i], sigma_W2[i])])

    gl.scatter(mu_W,
               sigma_W,
               ax=ax2,
               labels=["", r"$\mu_w$", r"$\sigma_w$"],
               color=color,
               legend=legend_layer,
               alpha=0.3)
    if (plot_pdf):
        for i in range(sigma_b.size):
            x_grid, y_val = bMA.gaussian1D_points(mean=mu_b[i],
                                                  std=sigma_b[i],
                                                  std_K=3)
            #            color = gl.get_color(None)
            gl.plot(
                x_grid,
                y_val,
                ax=ax1,
                color=color,
                fill=1,
                alpha=0.3,
                alpha_line=0.15,
                AxesStyle="Normal - No xaxis",
                ls="--"
                #                  ,legend = ["b:%i"%(i+1)]
            )  ###legend = ["M: %.2e, std: %.2e"%(mu_W2[i], sigma_W2[i])])
    gl.scatter(mu_b, sigma_b, ax=ax2, color=color, marker="s", alpha=0.3)
コード例 #2
0
ファイル: plotting_func.py プロジェクト: manuwhs/Trapyng
def plots_weights_layer(mu_W, sigma_W,sigma_b, mu_b, ax1, ax2, legend_layer, plot_pdf = 1):
        """
        Plot the given weights of the layer
        """
        # For each of the weights we plot them !!
        color = gl.get_color(None) 
        if (plot_pdf):
            for i in range(sigma_W.size):
                x_grid, y_val = bMA.gaussian1D_points(mean = mu_W[i], std = sigma_W[i],  std_K = 3)
                
                gl.plot(x_grid, y_val, ax = ax1, fill = 1, alpha = 0.15, color = color,
                        labels = ["Bayesian weights","","p(w)"],alpha_line = 0.15   # ,legend = ["W:%i"%(i+1)]
                        )  ###legend = ["M: %.2e, std: %.2e"%(mu_W2[i], sigma_W2[i])])
            
        gl.scatter( mu_W, sigma_W, ax = ax2, labels = ["",r"$\mu_w$",r"$\sigma_w$"], 
                   color = color, legend = legend_layer, alpha = 0.3)
        if (plot_pdf):
            for i in range(sigma_b.size):
                x_grid, y_val = bMA.gaussian1D_points(mean = mu_b[i], std = sigma_b[i],  std_K = 3)
    #            color = gl.get_color(None)
                gl.plot(x_grid, y_val,  ax = ax1, color = color, fill = 1, alpha = 0.3, alpha_line = 0.15, AxesStyle = "Normal - No xaxis", ls = "--"
        #                  ,legend = ["b:%i"%(i+1)]
                          )  ###legend = ["M: %.2e, std: %.2e"%(mu_W2[i], sigma_W2[i])])
        gl.scatter(mu_b, sigma_b, ax = ax2,  color = color, marker = "s", alpha = 0.3)
コード例 #3
0
ファイル: 1.main_EM_1A.py プロジェクト: manuwhs/Trapyng
        labels = ["Convergence of LL with generated data","Iterations","LL"], 
        lw = 2)
        gl.savefig(folder_images +'Likelihood_Evolution_' + clusters_relation+ "_"+str(periods[0])+ '.png', 
               dpi = 100, sizeInches = [12, 6])

if (final_clusters_graph):
    gl.init_figure()
    ax1 = gl.scatter(ret1, np.zeros(ret1.size), alpha = 0.2, color = "k",
               legend = ["Data points %i"%(ret1.size)], labels = ["EM algorithm %i Gaussian fits"%(K),"Return",""])
    
    for k in range(len(theta_list[-1])):
        mu_k = theta_list[-1][k][0]
        std_k = theta_list[-1][k][1]
        model_theta_last = model_theta_list[-1]
        
        x_grid, y_values = bMA.gaussian1D_points(mean = float( mu_k), std = float(np.sqrt(std_k)), std_K = 3.5)
        color = gl.get_color()
        
        if (len(model_theta_last) == 1):
            pi = model_theta_last[0]
            gl.plot(x_grid, y_values, color = color, fill = 1, alpha = 0.1,
                    legend = ["Kg(%i), pi:%.2f"%(k+1,pi[0,k])])  
        else:
            pi = model_theta_last[0]
            A = model_theta_last[1]
            gl.plot(x_grid, y_values, color = color, fill = 1, alpha = 0.1,
                    legend = ["Kg(%i), pi:%.2f, A: %s"%(k+1,pi[0,k], str(A[k,:]))])  
            
    gl.set_fontSizes(ax = [ax1], title = 20, xlabel = 20, ylabel = 20, 
                      legend = 12, xticks = 10, yticks = 10)
    
コード例 #4
0
    ymax = ymax + (ymax - ymin)*0.2
    
    xymin, xymax = [np.min([xmin,ymin]),np.max([xmax,ymax])]
    
    # Plot the marginalization of Y
    x_1_list = np.linspace(-7,2,5)
    
    i1 = 0;
    i2= 1;
    for x_1 in x_1_list:
        # Compute the conditional mu_2 and std_2
        L = (cov[i2,i1]/cov[i1,i1])
        mu_2_cond = mu_2 + L*(x_1 - mu_1)
        sigma_2_cond = np.sqrt(cov[i2,i2] - L*cov[i1,i2])
        
        x_grid, y_val = bMA.gaussian1D_points(mean = mu_2_cond, std  = sigma_2_cond, std_K = std_K) 
        y_val = y_val * (1/np.sqrt(2*np.pi*std_1*std_1))*np.exp(-np.power((x_1 - mu_1),2)/(2*std_1*std_1))
        
        ax3D.plot(x_grid,y_val, xymin, zdir='x')
        ax3D.add_collection3d(plt.fill_between(x_grid,y_val, 0, color='k', alpha=0.3),x_1, zdir='x')

    # Set the visualization limits !
#    ax3D.set_xlim(xmin, xmax)
#    ax3D.set_ylim(ymin, ymax)
    
    ax3D.set_xlim(xymin, xymax)
    ax3D.set_ylim(xymin, xymax)
    ax3D.set_zlim(zmin, zmax)
    
#    ax1.pcolormesh(xx, yy, zz)
#    ax1.imshow(zz, origin='lower', extent=[-3,3,-3,3], cmap="gray")
コード例 #5
0
ファイル: 3.main_gaussian.py プロジェクト: manuwhs/Trapyng
X = []
for i in range(Nx):
    X_i = np.random.randn(Nsam,1)*stds[i] + mus[i]
    X.append(X_i)

X = np.concatenate((X),axis = 1)
Nsim = 1000
x_grid = np.linspace(-6,8,Nsim)

if(distribution_graph):
    ## Plot the 3 distributions ! 
    gl.init_figure()
    for i in range(Nx):
        
        X_i = X[:,[i]]
        x_grid, y_values = bMA.gaussian1D_points(mean = mus[i], std = stds[i],
        x_grid = x_grid)
        
        color = gl.get_color()
        gl.scatter(X_i, np.zeros(X_i.shape), alpha = 0.1, lw = 4, AxesStyle = "Normal",
                   color = color, labels = ["3 independent Gaussian distributions","x","pdf(x)"])
                   
        gl.plot(x_grid, y_values, color = color, fill = 1, alpha = 0.1,
                legend = ["X%i: m:%.1f, std:%.1f"%(i+1,mus[i],stds[i])])  
        
        
        gl.savefig(folder_images +'Gaussians.png', 
           dpi = 100, sizeInches = [18, 10])
           
############################################################
################# PLOT DATA ###############################
############################################################
コード例 #6
0
    ax3D.set_ylim(xymin, xymax)
    ax3D.set_zlim(zmin, zmax)
    

    # Plot the marginalization of Y
    x_1_list = np.linspace(-7,2,5)
    
    i1 = 0;
    i2= 1;
    for x_1 in x_1_list:
        # Compute the conditional mu_2 and std_2
        L = (cov[i2,i1]/cov[i1,i1])
        mu_2_cond = mu_2 + L*(x_1 - mu_1)
        sigma_2_cond = np.sqrt(cov[i2,i2] - L*cov[i1,i2])
        
        x_grid, y_val = bMA.gaussian1D_points(mean = mu_2_cond, std  = sigma_2_cond, std_K = std_K) 
        y_val = y_val * (1/np.sqrt(2*np.pi*std_1*std_1))*np.exp(-np.power((x_1 - mu_1),2)/(2*std_1*std_1))
        
        ax3D.plot(x_grid,y_val, xymin, zdir='x')
        ax3D.add_collection3d(plt.fill_between(x_grid,y_val, 0, color='k', alpha=0.3),x_1, zdir='x')

    # Set the visualization limits !
#    ax3D.set_xlim(xmin, xmax)
#    ax3D.set_ylim(ymin, ymax)
    
    ax3D.set_xlim(xymin, xymax)
    ax3D.set_ylim(xymin, xymax)
    ax3D.set_zlim(zmin, zmax)
    
#    ax1.pcolormesh(xx, yy, zz)
#    ax1.imshow(zz, origin='lower', extent=[-3,3,-3,3], cmap="gray")
コード例 #7
0
ファイル: 2.main_kernel.py プロジェクト: manuwhs/Trapyng
    gl.scatter(ret1,ret2, alpha = 0.5, ax = ax1, lw = 4, AxesStyle = "Normal",
               labels = ["",symbolIDs[0], symbolIDs[1]],
               legend = ["%i points"%ret1.size])
    
    ## X distribution
    ax2 = gl.subplot2grid((4,4), (0,0), rowspan=1, colspan=3, sharex = ax1)

    gl.histogram(X = ret1, ax = ax2, AxesStyle = "Normal - No xaxis", 
                 color = "k", alpha = 0.5)
                 
    x_grid = np.linspace(min(ret1),max(ret1),n_grids)
    y_val = bMA.kde_sklearn(ret1, x_grid, bandwidth=np.std(ret1)/kde_K)  
    gl.plot(x_grid, y_val, color = "k",
            labels = ["","",""], legend = ["M: %.2e, std: %.2e"%(mean[0], cov[0,0])])

    x_grid, y_val = bMA.gaussian1D_points(X = ret1, std_K = 3)
    gl.plot(x_grid, y_val, color = "b",
            labels = ["","",""], legend = ["M: %.2e, std: %.2e"%(mean[0], cov[0,0])])
    
    # Y distribution
    ax3 = gl.subplot2grid((4,4), (1,3), rowspan=3, colspan=1,sharey = ax1,)
    gl.histogram(X = ret2, ax = ax3, orientation = "horizontal", 
                 AxesStyle = "Normal - No yaxis", 
                 color = "k", alpha = 0.5)
    x_grid = np.linspace(min(ret2),max(ret2),n_grids)
    y_val = bMA.kde_sklearn(ret2, x_grid, bandwidth=np.std(ret2)/kde_K) 
    
    gl.plot(y_val, x_grid, color = "k",
            labels = ["","",""], legend = ["M: %.2e, std: %.2e"%(mean[0], cov[1,1])])
    gl.subplots_adjust(left=.09, bottom=.10, right=.90, top=.95, wspace=.01, hspace=0.01)
コード例 #8
0
#    V1_pr= []
#    V2_pr= []
#    
#    for i in range(Y.shape[1]):
#        V1_pr.append([Y[:,i],Y[:,i]- R[0,:].dot(Y[:,i]) * R[0,:]])
#        V2_pr.append([Y[:,i],Y[:,i] - R[1,:].dot(Y[:,i]) * R[1,:]])
#        
#        gl.plot([V1_pr[i][0][0],V1_pr[i][1][0]],[V1_pr[i][0][1],V1_pr[i][1][1]], color = "y")
#        gl.plot([V2_pr[i][0][0],V2_pr[i][1][0]],[V2_pr[i][0][1],V2_pr[i][1][1]], color = "r")
#        gl.plot(V2_pr[i][0],V2_pr[i][1], color = "y")
#    gl.plot([mu[0],n*R[0,0] + mu[0]],[mu[1],n*R[0,1]+ mu[1]],color = "y");
#    gl.plot([mu[0],n*R[1,0] + mu[0]],[mu[1],n*R[1,1]+ mu[1]],color = "y");
    
    ## X distribution
    ax2 = gl.subplot2grid((4,4), (0,0), rowspan=1, colspan=3, sharex = ax1)
    x_grid, y_val = bMA.gaussian1D_points(mean = mu_Y[0], std = SigmaY[0,0], std_K = 3)
    gl.plot(x_grid, y_val, color = "k",
            labels = ["","",""], legend = ["M: %.2e, std: %.2e"%(mu_Y[0], SigmaY[0,0])])
    
    x_grid, y_val = bMA.gaussian1D_points(mean = mu_Z[0], std = SigmaZ[0,0], std_K = 3)
    gl.plot(x_grid, y_val, color = "g",
            labels = ["","",""], legend = ["M: %.2e, std: %.2e"%(mu_Z[0], SigmaZ[0,0])])
    
    # Y distribution
    ax3 = gl.subplot2grid((4,4), (1,3), rowspan=3, colspan=1,sharey = ax1,) 
    x_grid, y_val = bMA.gaussian1D_points(mean = mu_Y[1], std = SigmaY[1,1], std_K = 3)
    gl.plot(y_val, x_grid, color = "k",
            labels = ["","",""], legend = ["M: %.2e, std: %.2e"%(mu_Y[1], SigmaY[1,1])])
    x_grid, y_val = bMA.gaussian1D_points(mean = mu_Z[1], std = SigmaZ[1,1], std_K = 3)
    gl.plot( y_val,x_grid , color = "g",
            labels = ["","",""], legend = ["M: %.2e, std: %.2e"%(mu_Z[1], SigmaZ[1,1])])
コード例 #9
0
               alpha=0.5,
               ax=ax1,
               lw=4,
               AxesStyle="Normal",
               labels=["", symbolIDs[0], symbolIDs[1]],
               legend=["%i points" % ret1.size])

    ## X distribution
    ax2 = gl.subplot2grid((4, 4), (0, 0), rowspan=1, colspan=3, sharex=ax1)
    gl.histogram(X=ret1,
                 ax=ax2,
                 AxesStyle="Normal - No xaxis",
                 color="k",
                 alpha=0.5)

    x_grid, y_val = bMA.gaussian1D_points(X=ret1, std_K=3)
    gl.plot(x_grid,
            y_val,
            color="k",
            labels=["", "", ""],
            legend=["M: %.2e, std: %.2e" % (mean[0], cov[0, 0])])

    # Y distribution
    ax3 = gl.subplot2grid(
        (4, 4),
        (1, 3),
        rowspan=3,
        colspan=1,
        sharey=ax1,
    )
    gl.histogram(X=ret2,
コード例 #10
0
for i in range(Nx):
    X_i = np.random.randn(Nsam, 1) * stds[i] + mus[i]
    X.append(X_i)

X = np.concatenate((X), axis=1)
Nsim = 1000
x_grid = np.linspace(-6, 8, Nsim)

if (distribution_graph):
    ## Plot the 3 distributions !
    gl.init_figure()
    for i in range(Nx):

        X_i = X[:, [i]]
        x_grid, y_values = bMA.gaussian1D_points(mean=mus[i],
                                                 std=stds[i],
                                                 x_grid=x_grid)

        color = gl.get_color()
        gl.scatter(
            X_i,
            np.zeros(X_i.shape),
            alpha=0.1,
            lw=4,
            AxesStyle="Normal",
            color=color,
            labels=["3 independent Gaussian distributions", "x", "pdf(x)"])

        gl.plot(x_grid,
                y_values,
                color=color,
コード例 #11
0
    ax1 = gl.scatter(ret1, np.zeros(ret1.shape), alpha = 0.5, lw = 4, AxesStyle = "Normal",
               labels = ["",symbolIDs[0], ""],
               legend = ["%i points"%ret1.size])
    
    for i in range(int(ret1.size/26)):
        gl.scatter(ret1[i*26:(i+1)*26], np.ones(ret1[i*26:(i+1)*26].shape)*(i+1), alpha = 0.5, lw = 4, AxesStyle = "Normal",
                   legend = ["Day %i"%(i+1)])
    gl.set_zoom(ax = ax1, X = ret1,xlimPad = [0.1,0.8])

    gl.savefig(folder_images +'InitPointsInferenceDays.png', 
               dpi = 100, sizeInches = [10, 4])
    
if (estimation_days_graph):
    gl.init_figure()
    
    x_grid, y_values = bMA.gaussian1D_points(X = ret1, num = 100, std_K = 2, x_grid = None)
    
    ax1 = gl.plot(x_grid, y_values, alpha = 0.1, lw = 4, AxesStyle = "Normal",
               labels = ["",symbolIDs[0], "Distribution"],
               legend = ["%i points"%ret1.size] , color = "k")
              
    for i in range(int(ret1.size/26)):
        D = ret1[i*26:(i+1)*26]
        x_grid, y_values = bMA.gaussian1D_points(X = D, num = 100, std_K = 2, x_grid = None)
        
        color = gl.get_color()
        gl.scatter(D, np.zeros(D.shape), alpha = 0.3, lw = 4, AxesStyle = "Normal",
                   legend = ["Day %i"%(i+1)],color = color)

        gl.plot(x_grid, y_values, color = color, fill = 1, alpha = 0.1)
                   
コード例 #12
0
    gl.init_figure()
    ax1 = gl.scatter(
        ret1,
        np.zeros(ret1.size),
        alpha=0.2,
        color="k",
        legend=["Data points %i" % (ret1.size)],
        labels=["EM algorithm %i Gaussian fits" % (K), "Return", ""])

    for k in range(len(theta_list[-1])):
        mu_k = theta_list[-1][k][0]
        std_k = theta_list[-1][k][1]
        model_theta_last = model_theta_list[-1]

        x_grid, y_values = bMA.gaussian1D_points(mean=float(mu_k),
                                                 std=float(np.sqrt(std_k)),
                                                 std_K=3.5)
        color = gl.get_color()

        if (len(model_theta_last) == 1):
            pi = model_theta_last[0]
            gl.plot(x_grid,
                    y_values,
                    color=color,
                    fill=1,
                    alpha=0.1,
                    legend=["Kg(%i), pi:%.2f" % (k + 1, pi[0, k])])
        else:
            pi = model_theta_last[0]
            A = model_theta_last[1]
            gl.plot(x_grid,