Example #1
0
def create_fullyconnected_net(num_nodes, rescale_frac=0.999, noise_std=0.0, random_initial_state=False,
                              symmetric=False, feedforward=False, connection_rate=1.0):
    
    net = EchoStateNetwork()
    net.noise_std = noise_std
    
    for k in range(num_nodes):
        n = k
        istate = 0.0       
        if random_initial_state:
            istate = np.abs(np.random.randn()) 
        net.create_node(n, initial_state=istate)
    
    W = np.random.randn(num_nodes, num_nodes)
    if symmetric:
        for k1 in range(num_nodes):
            for k2 in range(k1):
                W[k2, k1] = W[k1, k2]
    
    if feedforward:
        for k1 in range(num_nodes):
            for k2 in range(k1+1):
                W[k1, k2] = 0.0
    
    for k1 in range(num_nodes):
        for k2 in range(num_nodes):
            rn = np.random.rand()
            if rn < connection_rate:
                net.connect_nodes(k1, k2, W[k1, k2])
    
    net.rescale_weights(rescale_frac)
    
    return net
Example #2
0
def run_morse_nets(stim_file, net_file, input_gain=1.0, noise_std=0.0, num_trials=1, exp_desc='default', net_keys=None, fixed_seed=None):

    stimset = MorseStimSet()
    stimset.from_hdf5(stim_file)
    f = h5py.File(net_file, 'a')
    
    burn_time = 100
    post_stim_time = 30
    pre_stim_time = 30 
    
    if net_keys is None:
        net_keys = f.keys()
    
    for net_key in net_keys:
        if fixed_seed is not None:
            #use a fixed random seed so each network sees the same set of random stimuli
            print 'Using fixed random seed..'
            np.random.seed(fixed_seed)
            
        print 'Running network %s' % net_key
        net_grp = f[net_key]
        
        #read network weights from hdf5
        net = EchoStateNetwork()
        net.from_hdf5(net_grp)
        net.noise_std = noise_std
        
        #set the input gain
        net.connect_input(0, 0, input_gain)        
        
        #rebuild network and run
        net.compile()        
        net_sims = run_sim(net, stimset.all_stims,
                           burn_time=burn_time,
                           pre_stim_time=pre_stim_time, post_stim_time=post_stim_time,
                           num_trials=num_trials)

        #save experiment to network
        exp_grp = net_grp.create_group(exp_desc)
        exp_grp['noise_std'] = noise_std
        exp_grp['num_stims'] = len(net_sims)
        exp_grp['input_gain'] = input_gain
        
        resp_grp = exp_grp.create_group('responses')

        for stim_key,sim in net_sims.iteritems():
            stim_grp = resp_grp.create_group(stim_key)
            sim.to_hdf5(stim_grp)

    f.close()