Example #1
0
def create_chain_if_net(nunits):

    gpunet = GpuNetwork()

    instream = ConstantInputStream(1.25, 0.020, 1.0)
    gpunet.add_stream(instream)

    num_states = -1
    num_params = -1
    dx = 0.05
    dy = 5e-6
    dz = 5e-6
    for k in range(nunits):
        u = IFUnit()
        u.position = np.array([0.0, k*dx, 0.0])

        num_states = u.num_states
        num_params = u.num_params
        gpunet.add_unit(u)

    u0 = gpunet.units[0]
    gpunet.connect_stream(instream, 0, u0, 1.0)

    for k,u in enumerate(gpunet.units[1:]):
        uprev = gpunet.units[k]
        w = 1.00 / float(k+2)
        #gpunet.connect_stream(instream, 0, u, w)
        gpunet.connect(uprev, u, 10.5)

    return gpunet,num_states,num_params
Example #2
0
def create_cube_if_net(width, height, depth):

    gpunet = GpuNetwork()

    max_cube_width = 1.25
    mcw_half = max_cube_width / 2.0

    dx = max_cube_width / width
    dy = max_cube_width / height
    dz = max_cube_width / depth

    max_len = max_cube_width*np.sqrt( np.sqrt(2*max_cube_width**2)  ) #longest distance in cube between two neurons

    all_units = np.ndarray([width, height, depth], dtype='object')

    #build network
    for x in range(width):
        for y in range(height):
            for z in range(depth):
                u = IFUnit()
                u.position = np.array([mcw_half - x*dx, mcw_half - y*dy, mcw_half - z*dz])
                gpunet.add_unit(u)
                all_units[x, y, z] = u

    #connect units topographically
    print 'Connecting Neurons...'
    for x in range(width):
        for y in range(height):
            for z in range(depth):
                u = all_units[x, y, z]
                for u2 in all_units.ravel():
                    d = np.linalg.norm(u.position - u2.position)
                    p_connect = min(1.0, 1.0 - (d / max_len)*0.2)
                    w = max(np.random.randn(), -0.25)
                    print 'd=%0.6f, p_connect=%0.6f, w=%0.6f' % (d, p_connect, w)
                    if np.random.rand() < p_connect:
                        gpunet.connect(u, u2, np.random.randn())

    #create input streams
    nstreams = 10
    all_streams = []
    for k in range(nstreams):
        rs = RandomInputStream(0.0, 1.5, 0.050, 1000.00, positive=True)
        gpunet.add_stream(rs)
        all_streams.append(rs)

    #connect inputs up
    max_inputs = 5
    for u in all_units[:, :, 0].ravel():
        nin = np.random.randint(max_inputs+1)
        streams_connected = {}
        for k in range(nin):
            rsnum = np.random.randint(nstreams)
            if rsnum not in streams_connected:
                gpunet.connect_stream(all_streams[rsnum], 0, u, 1.0)
                streams_connected[rsnum] = True

    return gpunet