def build(d,
          n_cells,
          n_input_cells=32,
          n_output_cells=32,
          wide=0.05,
          sparsity=0.01,
          seed=0):
    """

    Parameters:
    -----------

    n_cells:        Number of cells in the reservoir
    n_input_cells:  Number of cells receiving external input
    n_output_cells: Number of cells sending external output
    n_input:        Number of external input
    n_output:       Number of external output
    sparsity:       Connection rate
    seed:           Seed for the random genrator

    
    """

    #np.random.seed(seed)
    density = np.ones((1000, 1000))
    n = 1000
    for i in range(n):
        ii = i / (n - 1)
        density[:, i] = np.power(((3.6) * ii * (ii - 1) + 1) * np.ones((1, n)),
                                 0.75)  #neurone density
    density_P = density.cumsum(axis=1)
    density_Q = density_P.cumsum(axis=1)
    filename = "autoencoder-second-degree-big.npy"  #"CVT-%d-seed-%d.npy" % (n_cells,seed)

    if not os.path.exists(filename):
        cells_pos = np.zeros((n_cells, 2))
        cells_pos[:, 0] = np.random.uniform(0, 1000, n_cells)
        cells_pos[:, 1] = np.random.uniform(0, 1000, n_cells)
        for i in tqdm.trange(75):
            _, cells_pos = voronoi.centroids(cells_pos, density, density_P,
                                             density_Q)
        np.save(filename, cells_pos)

    cells_pos = np.load(filename)
    cells_in = np.argpartition(cells_pos, +n_input_cells, 0)[:+n_input_cells]
    #cells_out = np.argpartition(cells_pos, -n_output_cells, 0)[-n_output_cells:]
    in_index = cells_in[:, 0]
    in_index = in_index[np.argsort(cells_pos[in_index][:, 1])]

    W = connect(cells_pos, n_input_cells, n_output_cells, d, sigma, wide)
    out_index = visualize(W, cells_pos, cells_in[:, 0], t)

    return cells_pos / 1000, W, in_index, out_index  #cells_out[:,0]#, W_in, W_out, bias
Exemple #2
0
def build(n_cells, n_input_cells=32, n_output_cells=32, sparsity=0.01, seed=0):
    """

    Parameters:
    -----------

    n_cells:        Number of cells in the reservoir
    n_input_cells:  Number of cells receiving external input
    n_output_cells: Number of cells sending external output
    n_input:        Number of external input
    n_output:       Number of external output
    sparsity:       Connection rate
    seed:           Seed for the random genrator

    
    """

    #np.random.seed(seed)
    density = np.ones((1000, 1000))
    n = 1000
    for i in range(n):
        ii = i / (n - 1)
        density[:, i] = np.power((0.9 * ii * (ii - 2) + 1) * np.ones((1, n)),
                                 4)  #neurone density
    density_P = density.cumsum(axis=1)
    density_Q = density_P.cumsum(axis=1)
    filename = "deep_rbm.npy"  #"CVT-%d-seed-%d.npy" % (n_cells,seed)

    if not os.path.exists(filename):
        cells_pos = np.zeros((n_cells, 2))
        cells_pos[:, 0] = np.random.uniform(0, 1000, n_cells)
        cells_pos[:, 1] = np.random.uniform(0, 1000, n_cells)
        for i in tqdm.trange(75):
            _, cells_pos = voronoi.centroids(cells_pos, density, density_P,
                                             density_Q)
        np.save(filename, cells_pos)

    cells_pos = np.load(filename)
    cells_in = np.argpartition(cells_pos, +n_input_cells, 0)[:+n_input_cells]
    cells_out = np.argpartition(cells_pos, -n_output_cells,
                                0)[-n_output_cells:]

    W = connect(cells_pos, n_input_cells, n_output_cells, d, sigma)

    return cells_pos / 1000, W, cells_in[:,
                                         0], cells_out[:,
                                                       0]  #, W_in, W_out, bias
Exemple #3
0
def build(n_cells=1000, n_input_cells = 32, n_output_cells = 32,
          n_input = 3, n_output = 3, sparsity = 0.01, seed=0,l=10):
    """

    Parameters:
    -----------

    n_cells:        Number of cells in the reservoir
    n_input_cells:  Number of cells receiving external input
    n_output_cells: Number of cells sending external output
    n_input:        Number of external input
    n_output:       Number of external output
    sparsity:       Connection rate
    seed:           Seed for the random genrator

    
    """
    
    np.random.seed(seed)
    density    = np.ones((1000,1000))
    n=1000
    for i in range(n):
	    ii=i/(n-1)
	    density[:,i]=np.power(((3.6)*ii*(ii-1)+1)*np.ones((1,n)),0.75) #neurone density
    density_P  = density.cumsum(axis=1)
    density_Q  = density_P.cumsum(axis=1)
    filename = "autoencoder-second-degree-big.npy"#"CVT-%d-seed-%d.npy" % (n_cells,seed)

    if not os.path.exists(filename):
        cells_pos = np.zeros((n_cells,2))
        cells_pos[:,0] = np.random.uniform(0, 1000, n_cells)
        cells_pos[:,1] = np.random.uniform(0, 1000, n_cells)
        for i in tqdm.trange(75):
            _, cells_pos = voronoi.centroids(cells_pos, density, density_P, density_Q)
        np.save(filename, cells_pos)

    cells_pos = np.load(filename)
    cells_pos=split(cells_pos,l)
  
    #X,Y = cells_pos[:,0], cells_pos[:,1]

    
    W=connect(cells_pos, l, n_input_cells, n_output_cells)
    return cells_pos/1000, W#, W_in, W_out, bias
Exemple #4
0
        def update(frame):
            global points
            # Recompute weighted centroids
            regions, points = voronoi.centroids(points, density, density_P, density_Q)

            # Update figure
            Pi = points.astype(int)
            X = np.maximum(np.minimum(Pi[:, 0], density.shape[1]-1), 0)
            Y = np.maximum(np.minimum(Pi[:, 1], density.shape[0]-1), 0)
            sizes = (args.pointsize[0] +
                     (args.pointsize[1]-args.pointsize[0])*density[Y, X])
            scatter.set_offsets(points)
            scatter.set_sizes(sizes)
            bar.update()

            # Save result at last frame
            if (frame == args.n_iter-2 and
                      (not os.path.exists(dat_filename) or args.save)):
                np.save(dat_filename, points)
                plt.savefig(pdf_filename)
                plt.savefig(png_filename)
Exemple #5
0
        def update(frame):
            global points
            # Recompute weighted centroids
            regions, points = voronoi.centroids(points, density, density_P,
                                                density_Q)

            # Update figure
            Pi = points.astype(int)
            X = np.maximum(np.minimum(Pi[:, 0], density.shape[1] - 1), 0)
            Y = np.maximum(np.minimum(Pi[:, 1], density.shape[0] - 1), 0)
            sizes = (args.pointsize[0] +
                     (args.pointsize[1] - args.pointsize[0]) * density[Y, X])
            scatter.set_offsets(points)
            scatter.set_sizes(sizes)
            bar.update()

            # Save result at last frame
            if (frame == args.n_iter - 2
                    and (not os.path.exists(dat_filename) or args.save)):

                tspfileheader = "NAME : " + filename + "\nTYPE : TSP\nCOMMENT: Stipple of " + filename + " with " + str(
                    len(points)) + " points\nDIMENSION: " + str(
                        len(points
                            )) + "\nEDGE_WEIGHT_TYPE: ATT\nNODE_COORD_SECTION"
                nodeindexes = np.arange(1, len(points) + 1)[:, np.newaxis]
                np.savetxt(dat_filename,
                           np.concatenate((nodeindexes, points), axis=1),
                           ['%d', '%d', '%d'],
                           header=tspfileheader,
                           comments='')
                if (args.pdf):
                    plt.savefig(pdf_filename)
                if (args.png):
                    plt.savefig(png_filename)
                if (args.npy):
                    np.save(dat_filename, points)
Exemple #6
0
def plot(ax, points, letter):

    patches = []
    regions, vertices = voronoi.voronoi_finite_polygons_2d(points)
    for region in regions:
        patches.append(Polygon(vertices[region]))
    collection = PatchCollection(
        patches,
        linewidth=0.75,
        facecolor="white",
        edgecolor="black",
    )
    ax.add_collection(collection)
    ax.scatter(points[:, 0],
               points[:, 1],
               s=15,
               facecolor="red",
               edgecolor="none")
    regions, points = voronoi.centroids(points, density, density_P, density_Q)
    ax.scatter(points[:, 0],
               points[:, 1],
               s=50,
               facecolor="none",
               edgecolor="black",
               linewidth=.75)
    ax.text(24,
            ymax - 24,
            letter,
            color="black",
            weight="bold",
            va="top",
            fontsize=24)
    ax.set_xlim(xmin, xmax)
    ax.set_xticks([])
    ax.set_ylim(ymin, ymax)
    ax.set_yticks([])
Exemple #7
0
xmin, xmax = 0, 1024
ymin, ymax = 0, 1024
density = np.ones((xmax - xmin, xmax - xmin))
density_P = density.cumsum(axis=1)
density_Q = density_P.cumsum(axis=1)

# Compute CVT
# -----------
if force:
    points = np.zeros((n, 2))
    points[:, 0] = np.random.uniform(xmin, xmax, n)
    points[:, 1] = np.random.uniform(ymin, ymax, n)

    np.save("data/CVT-initial", points)
    for i in tqdm.trange(75):
        regions, points = voronoi.centroids(points, density, density_P,
                                            density_Q)
    np.save("data/CVT-final.npy", points)

# Display
# -------
plt.figure(figsize=(10, 5))

# ------------------------------------------------------------------ Fig 1. ---
ax = plt.subplot(1, 2, 1, aspect=1)
points = np.load("data/CVT-initial.npy")

patches = []
regions, vertices = voronoi.voronoi_finite_polygons_2d(points)
for region in regions:
    patches.append(Polygon(vertices[region]))
collection = PatchCollection(patches,