Exemplo n.º 1
0
    def setup(self, load_tuning_prop=False, times={}):

        self.projections = {}
        self.projections['ee'] = []
        self.projections['ei'] = []
        self.projections['ie'] = []
        self.projections['ii'] = []
        if not load_tuning_prop:
            self.tuning_prop_exc = utils.set_tuning_prop(self.params, mode='hexgrid', cell_type='exc')        # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
            self.tuning_prop_inh = utils.set_tuning_prop(self.params, mode='hexgrid', cell_type='inh')        # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
        else:
            self.tuning_prop_exc = np.loadtxt(self.params['tuning_prop_means_fn'])
            self.tuning_prop_inh = np.loadtxt(self.params['tuning_prop_inh_fn'])

        indices, distances = utils.sort_gids_by_distance_to_stimulus(self.tuning_prop_exc, self.params) # cells in indices should have the highest response to the stimulus
        if self.pc_id == 0:
            print "Saving tuning_prop to file:", self.params['tuning_prop_means_fn']
            np.savetxt(self.params['tuning_prop_means_fn'], self.tuning_prop_exc)
            print "Saving tuning_prop to file:", self.params['tuning_prop_inh_fn']
            np.savetxt(self.params['tuning_prop_inh_fn'], self.tuning_prop_inh)
            print 'Saving gids to record to: ', self.params['gids_to_record_fn']
            np.savetxt(self.params['gids_to_record_fn'], indices[:self.params['n_gids_to_record']], fmt='%d')

#        np.savetxt(params['gids_to_record_fn'], indices[:params['n_gids_to_record']], fmt='%d')

        if self.comm != None:
            self.comm.Barrier()
        from pyNN.utility import Timer
        self.timer = Timer()
        self.timer.start()
        self.times = times
        self.times['t_all'] = 0
        # # # # # # # # # # # #
        #     S E T U P       #
        # # # # # # # # # # # #
        (delay_min, delay_max) = self.params['delay_range']
        setup(timestep=0.1, min_delay=delay_min, max_delay=delay_max, rng_seeds_seed=self.params['seed'])
        rng_v = NumpyRNG(seed = sim_cnt*3147 + self.params['seed'], parallel_safe=True) #if True, slower but does not depend on number of nodes
        self.rng_conn = NumpyRNG(seed = self.params['seed'], parallel_safe=True) #if True, slower but does not depend on number of nodes

        # # # # # # # # # # # # # # # # # # # # # # # # #
        #     R A N D O M    D I S T R I B U T I O N S  #
        # # # # # # # # # # # # # # # # # # # # # # # # #
        self.v_init_dist = RandomDistribution('normal',
                (self.params['v_init'], self.params['v_init_sigma']),
                rng=rng_v,
                constrain='redraw',
                boundaries=(-80, -60))

        self.times['t_setup'] = self.timer.diff()
        self.times['t_calc_conns'] = 0
        if self.comm != None:
            self.comm.Barrier()

        self.torus = space.Space(axes='xy', periodic_boundaries=((0., self.params['torus_width']), (0., self.params['torus_height'])))
Exemplo n.º 2
0
    def __init__(self, params, comm=None):
        self.params = params
        self.comm = comm
        self.n_speeds = params["n_speeds"]
        self.n_cycles = params["n_cycles"]
        self.n_directions = params["n_theta"]
        self.n_iterations_total = (
            self.params["n_theta"]
            * self.params["n_speeds"]
            * self.params["n_cycles"]
            * self.params["n_stim_per_direction"]
        )
        self.selected_conns = None
        self.n_time_steps = self.params["t_sim"] / self.params["dt_rate"]

        # distribute units among processors
        if comm != None:
            self.pc_id, self.n_proc = comm.rank, comm.size
            my_units = utils.distribute_n(params["n_exc"], self.n_proc, self.pc_id)
            self.my_units = range(my_units[0], my_units[1])
        else:
            self.my_units = range(self.params["n_exc"])
            self.pc_id, self.n_proc = 0, 1

        try:
            self.tuning_prop = np.loadtxt(self.params["tuning_prop_means_fn"])
        except:
            print "Tuning properties file not found: %s\n Will create new ones" % self.params["tuning_prop_means_fn"]
            self.tuning_prop = utils.set_tuning_prop(self.params, mode="hexgrid", cell_type="exc")
            np.savetxt(self.params["tuning_prop_means_fn"], self.tuning_prop)

        if comm != None:
            comm.barrier()

        self.initial_value = 1e-2  # should be around 1 / n_units per HC, i.e. 1. / (params['N_theta'] * params['N_V']
        self.eps = 0.1 * self.initial_value
        self.normalize = False  # normalize input within a 'hypercolumn'

        all_conns = []
        # distribute connections among processors
        for i in xrange(params["n_exc"]):
            for j in xrange(params["n_exc"]):
                if i != j:
                    all_conns.append((i, j))
        self.my_conns = utils.distribute_list(all_conns, n_proc, pc_id)

        # setup data structures
        self.my_conns = np.array(self.my_conns)
        np.savetxt("delme_my_conns_%d.txt" % self.pc_id, self.my_conns, fmt="%d\t%d")
        self.pre_ids = np.unique(self.my_conns[:, 0])
        self.post_ids = np.unique(self.my_conns[:, 1])
        self.gid_idx_map_pre = {}
        self.gid_idx_map_post = {}
        for i in xrange(self.pre_ids.size):
            self.gid_idx_map_pre[self.pre_ids[i]] = i
        for i in xrange(self.post_ids.size):
            self.gid_idx_map_post[self.post_ids[i]] = i
        self.my_selected_conns = []
Exemplo n.º 3
0
 def prepare_tuning_prop(self):
     tuning_prop = utils.set_tuning_prop(self.params, mode='hexgrid', v_max=self.params['v_max'])        # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
     if self.pc_id == 0:
         print "Creating tuning properties", self.pc_id, self.params['tuning_prop_means_fn']
         print "Saving tuning_prop to file:", self.pc_id, self.params['tuning_prop_means_fn']
         np.savetxt(self.params['tuning_prop_means_fn'], tuning_prop)
         # write inital bias values to file
         np.savetxt(self.params['bias_values_fn_base']+'0.dat', np.zeros(self.params['n_exc']))
     if self.comm != None:
         print 'Pid %d at Barrier in Preparer.prepare_tuning_params' % self.pc_id
         sys.stdout.flush()
         self.comm.barrier()
     return tuning_prop
Exemplo n.º 4
0
            'tau_ei' : 50.,   'tau_ej' : 50., 'tau_eij' : 50.,
            'tau_pi' : 500.,  'tau_pj' : 500., 'tau_pij' : 500.,
            }

PS = simulation_parameters.parameter_storage()
params = PS.params
PS.create_folders()
PS.write_parameters_to_file()

n_cells = params['n_exc']
my_units = utils.distribute_n(n_cells, n_proc, pc_id)

mp = params['motion_params']

# P R E P A R E     T U N I N G    P R O P E R T I E S
tuning_prop = utils.set_tuning_prop(params, mode='hexgrid', v_max=params['v_max'])
np.savetxt(params['tuning_prop_means_fn'],tuning_prop)
#exit(1)

# load
#tuning_prop = np.loadtxt(params['tuning_prop_means_fn'])

# P R E P A R E     I N P U T 
#prepare_input(tuning_prop, params, my_units)
#if comm != None:
#    comm.barrier()
#normalize_input(params)
#times.append(time.time())

#exit(1)
    def setup(self, load_tuning_prop=False, times={}):

        self.projections = {}
        self.projections["ee"] = []
        self.projections["ei"] = []
        self.projections["ie"] = []
        self.projections["ii"] = []
        if not load_tuning_prop:
            self.tuning_prop_exc = utils.set_tuning_prop(
                self.params, mode="hexgrid", cell_type="exc"
            )  # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
            self.tuning_prop_inh = utils.set_tuning_prop(
                self.params, mode="hexgrid", cell_type="inh"
            )  # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
        else:
            self.tuning_prop_exc = np.loadtxt(self.params["tuning_prop_means_fn"])
            self.tuning_prop_inh = np.loadtxt(self.params["tuning_prop_inh_fn"])

        indices, distances = utils.sort_gids_by_distance_to_stimulus(
            self.tuning_prop_exc, self.params["motion_params"], self.params
        )  # cells in indices should have the highest response to the stimulus
        if self.pc_id == 0:
            print "Saving tuning_prop to file:", self.params["tuning_prop_means_fn"]
            np.savetxt(self.params["tuning_prop_means_fn"], self.tuning_prop_exc)
            print "Saving tuning_prop to file:", self.params["tuning_prop_inh_fn"]
            np.savetxt(self.params["tuning_prop_inh_fn"], self.tuning_prop_inh)
            print "Saving gids to record to: ", self.params["gids_to_record_fn"]
            np.savetxt(self.params["gids_to_record_fn"], indices[: self.params["n_gids_to_record"]], fmt="%d")

        #        np.savetxt(params['gids_to_record_fn'], indices[:params['n_gids_to_record']], fmt='%d')

        if self.comm != None:
            self.comm.Barrier()
        from pyNN.utility import Timer

        self.timer = Timer()
        self.timer.start()
        self.times = times
        self.times["t_all"] = 0
        # # # # # # # # # # # #
        #     S E T U P       #
        # # # # # # # # # # # #
        (delay_min, delay_max) = self.params["delay_range"]
        setup(timestep=0.1, min_delay=delay_min, max_delay=delay_max, rng_seeds_seed=self.params["seed"])
        rng_v = NumpyRNG(
            seed=sim_cnt * 3147 + self.params["seed"], parallel_safe=True
        )  # if True, slower but does not depend on number of nodes
        self.rng_conn = NumpyRNG(
            seed=self.params["seed"], parallel_safe=True
        )  # if True, slower but does not depend on number of nodes

        # # # # # # # # # # # # # # # # # # # # # # # # #
        #     R A N D O M    D I S T R I B U T I O N S  #
        # # # # # # # # # # # # # # # # # # # # # # # # #
        self.v_init_dist = RandomDistribution(
            "normal",
            (self.params["v_init"], self.params["v_init_sigma"]),
            rng=rng_v,
            constrain="redraw",
            boundaries=(-80, -60),
        )

        self.times["t_setup"] = self.timer.diff()
        self.times["t_calc_conns"] = 0
        if self.comm != None:
            self.comm.Barrier()

        self.torus = space.Space(
            axes="xy", periodic_boundaries=((0.0, self.params["torus_width"]), (0.0, self.params["torus_height"]))
        )
Exemplo n.º 6
0
PS.create_folders()
PS.write_parameters_to_file()

# not yet required 
#try:
#    from mpi4py import MPI
#    USE_MPI = True
#    comm = MPI.COMM_WORLD
#    pc_id, n_proc = comm.rank, comm.size
#    print "USE_MPI:", USE_MPI, 'pc_id, n_proc:', pc_id, n_proc
#except:
#    USE_MPI = False
#    pc_id, n_proc, comm = 0, 1, None
#    print "MPI not used"

tuning_prop_exc = utils.set_tuning_prop(params, mode='hexgrid', cell_type='exc')        # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
print "Saving tuning_prop to file:", params['tuning_prop_means_fn']
np.savetxt(params['tuning_prop_means_fn'], tuning_prop_exc)


print 'Calculating gids to record...'
mp = params['motion_params']
indices, distances = utils.sort_gids_by_distance_to_stimulus(tuning_prop_exc, mp, params) # cells in indices should have the highest response to the stimulus
n = params['n_gids_to_record']
np.savetxt(params['gids_to_record_fn'], indices[:n], fmt='%d')
print 'Saving gids to record to: ', params['gids_to_record_fn']

tuning_prop_inh= utils.set_tuning_prop(params, mode='hexgrid', cell_type='inh')        # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
print "Saving tuning_prop to file:", params['tuning_prop_inh_fn']
np.savetxt(params['tuning_prop_inh_fn'], tuning_prop_inh)
ps = simulation_parameters.parameter_storage()
params = ps.params


# ===================================
#    G E T   P A R A M E T E R S 
# ===================================
x0, y0 = params['motion_params'][0:2]
sim_cnt = int(sys.argv[1])
mp = float(sys.argv[2]), float(sys.argv[3]), float(sys.argv[4]), float(sys.argv[5])

from pyNN.utility import Timer
timer = Timer()
timer.start()
times = {} # stores time stamps
tuning_prop = utils.set_tuning_prop(params, mode='hexgrid')
time = np.arange(0, params['t_stimulus'], params['dt_rate'])

#print 'Prepare spike trains'
#L_input = np.zeros((params['n_exc'], time.shape[0]))
#for i_time, time_ in enumerate(time):
#    if (i_time % 100 == 0):
#        print "t:", time_
#    L_input[:, i_time] = utils.get_input(tuning_prop, params, time_/params['t_sim'])
#    L_input[:, i_time] *= params['f_max_stim']

# ===============
#    S E T U P 
# ===============
(delay_min, delay_max) = params['delay_range']
setup(timestep=0.1, min_delay=delay_min, max_delay=delay_max, rng_seeds_seed=sim_cnt)
Exemplo n.º 8
0
    re_calculate = False

else:
    print '\nPlotting the default parameters give in simulation_parameters.py\n'
    # load simulation parameters
    ps = simulation_parameters.parameter_storage()  # network_params class containing the simulation parameters
    params = ps.load_params()                       # params stores cell numbers, etc as a dictionary
    re_calculate = True # could be False, too, if you want


cell_type = 'exc'

if re_calculate: # load 
    print '\nCalculating the tuning prop'
    ps.create_folders()
    d = utils.set_tuning_prop(params, mode='hexgrid', cell_type=cell_type)        # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
else:
    fn = params['tuning_prop_means_fn']
    print '\nLoading from', fn
    d = np.loadtxt(fn)



n_cells = d[:, 0].size
if cell_type == 'exc':
    n_rf = params['N_RF_X'] * params['N_RF_Y']
    n_units = params['N_RF_X'] * params['N_RF_Y'] * params['N_theta'] * params['N_V']
else:
    n_rf = params['N_RF_X_INH'] * params['N_RF_Y_INH']
    n_units = params['N_RF_X_INH'] * params['N_RF_Y_INH'] * params['N_theta_inh'] * params['N_V_INH']
Exemplo n.º 9
0
try:
    from mpi4py import MPI
    USE_MPI = True
    comm = MPI.COMM_WORLD
    pc_id, n_proc = comm.rank, comm.size
    print "USE_MPI:", USE_MPI, 'pc_id, n_proc:', pc_id, n_proc
except:
    USE_MPI = False
    pc_id, n_proc, comm = 0, 1, None
    print "MPI not used"

#my_units = utils.distribute_n(params['n_exc'], n_proc, pc_id)

for j_, blur_x in enumerate(blur_x_range):
    L_input = np.zeros((n_cells, time.shape[0]))
    params['blur_X'], params['blur_V'] = blur_x, blur_v
    print 'Blur', params['blur_X'], params['blur_V']
    tuning_prop = utils.set_tuning_prop(params, mode='hexgrid', v_max=params['v_max'])        # set the tuning properties of exc cells: space (x, y) and velocity (u, v)
    for i_time, time_ in enumerate(time):
        if (i_time % 100 == 0):
            print "t:", time_
        L_input[:, i_time] = utils.get_input(tuning_prop, params, time_/params['t_sim'])
#        L_input[:, i_time] = utils.get_input(tuning_prop[my_units, :], params, time_/params['t_sim'])
#        L_input[:, i_time] *= params['f_max_stim']
    for cell in xrange(n_cells):
        L_net[j_, cell+2] = L_input[cell, :].sum()

L_net_output_fn = 'L_net.dat'
np.savetxt(L_net_output_fn, L_net)