def get_total_input_weight_time_sequence(dirname, end_trial, trialStep, target_neurons): """ Outputs total excitatory conductance input to target_neurons at different points during simulation """ num_timepoints = end_trial / trialStep + 1 input_weights = np.zeros((len(target_neurons), num_timepoints), np.float32) current_trial = 0 timepoint = 0 while current_trial <= end_trial: fileWeights = os.path.join(dirname, "weights_" + str(current_trial) + ".bin") fileActive = os.path.join(dirname, "RA_RA_active_connections_" + str(current_trial) + ".bin") (N, _, weights) = reading.read_weights(fileWeights) (_, _, active_synapses) = reading.read_synapses(fileActive) for source_id in range(N): for i, target_id in enumerate(target_neurons): if target_id in active_synapses[source_id]: input_weights[i][timepoint] += weights[source_id][target_id] timepoint += 1 current_trial += trialStep return input_weights
def write_pajek_neurons_connected_by_supersynapses(dirname, trial_number): """ Create .net file with locations and supersynaptic connections for HVC-RA neurons connected by supersynapses """ file_RA_xy = os.path.join(dirname, "RA_xy_" + str(trial_number) + ".bin") file_training = os.path.join(dirname, "training_neurons.bin") file_pajek = os.path.join(dirname, "network_" + str(trial_number) + ".net") fileSuperSynapses = os.path.join( dirname, "RA_RA_super_connections_" + str(trial_number) + ".bin") fileWeights = os.path.join(dirname, "weights_" + str(trial_number) + ".bin") coord_RA = reading.read_coordinates(file_RA_xy) training_neurons = reading.read_training_neurons(file_training) (N_RA, _, super_synapses) = reading.read_synapses(fileSuperSynapses) (N_RA, _, weights) = reading.read_weights(fileWeights) network_neurons = set(training_neurons) for i in range(N_RA): for target in super_synapses[i]: network_neurons.add(target) network_neurons = sorted(list(network_neurons)) num_neurons = len(network_neurons) # sort array with neurons and training neurons # training_neurons.sort() with open(file_pajek, 'w') as f: f.write("*Vertices {0}\n".format(num_neurons)) for i, neuron_id in enumerate(network_neurons): if neuron_id in training_neurons: f.write('{0} "{1}" {2} {3} {4} ic Green\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) else: f.write('{0} "{1}" {2} {3} {4} ic Yellow\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) f.write("*Arcs\n") # write targets of HVC(RA) neurons for i, source_id in enumerate(network_neurons): for target_id in super_synapses[source_id]: try: ind = utils.index(network_neurons, target_id) f.write('{0} {1} {2} c Green\n'.format( i + 1, ind + 1, weights[source_id][target_id])) except ValueError: continue
def write_pajek_neurons(dirname, trial_number): """ Create .net file with locations and connections between mature HVC-RA neurons in array """ file_RA_xy = os.path.join(dirname, "RA_xy_" + str(trial_number) + ".bin") file_training = os.path.join(dirname, "training_neurons.bin") file_pajek = os.path.join(dirname, "network_" + str(trial_number) + ".net") fileMature = os.path.join(dirname, "mature_" + str(trial_number) + ".bin") fileSuperSynapses = os.path.join( dirname, "RA_RA_super_connections_" + str(trial_number) + ".bin") fileWeights = os.path.join(dirname, "weights_" + str(trial_number) + ".bin") coord_RA = reading.read_coordinates(file_RA_xy) training_neurons = reading.read_training_neurons(file_training) (N_RA, _, weights) = reading.read_weights(fileWeights) (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) (_, _, super_synapses) = reading.read_synapses(fileSuperSynapses) mature_neurons = np.where(mature_indicators == 1)[0] #print list(mature_neurons) #mature_neurons = range(N_RA) num_neurons = len(mature_neurons) # sort array with neurons and training neurons # training_neurons.sort() mature_neurons.sort() with open(file_pajek, 'w') as f: f.write("*Vertices {0}\n".format(num_neurons)) for i, neuron_id in enumerate(mature_neurons): if neuron_id in training_neurons: f.write('{0} "{1}" {2} {3} {4} ic Green\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) else: f.write('{0} "{1}" {2} {3} {4} ic Yellow\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) f.write("*Arcs\n".format(num_neurons)) # write targets of HVC(RA) neurons for i, source_id in enumerate(mature_neurons): for target_id in super_synapses[source_id]: try: ind = utils.index(mature_neurons, target_id) f.write('{0} {1} {2} c Green\n'.format( i + 1, ind + 1, weights[source_id][target_id])) except ValueError: continue
def update_weights_info(self): """ Updates weight histogram """ (self.N_RA, trial_number, weights) = read.read_weights(self.file_weights) self.mod_time_wgh = os.path.getmtime(self.file_weights) self.weights = [item for sublist in weights for item in sublist] for i in range(len(self.weights)): if self.weights[i] < sys.float_info.epsilon: self.weights[i] = 0 self.hist, self.bin_edges = np.histogram(self.weights, bins=100)
def get_weight_time_sequence(dirname, end_trial, trialStep, source_neurons, target_neuron): """ Outputs excitatory conductance input from source_neurons to target_neuron at different points during simulation """ num_timepoints = end_trial / trialStep + 1 synaptic_weights = np.zeros((len(source_neurons), num_timepoints), np.float32) current_trial = 0 timepoint = 0 while current_trial <= end_trial: fileWeights = os.path.join(dirname, "weights_" + str(current_trial) + ".bin") (_, _, weights) = reading.read_weights(fileWeights) for i, source_id in enumerate(source_neurons): synaptic_weights[i][timepoint] = weights[source_id][target_neuron] timepoint += 1 current_trial += trialStep return synaptic_weights
############# HVC-RA -> HVC-I connections ############# (_, targets_id_RA2I_before, weights_RA2I_before, \ syn_lengths_RA2I_before, axonal_delays_RA2I_before) = reading.read_connections(fileRA2IBefore) (_, targets_id_RA2I_after, weights_RA2I_after, \ syn_lengths_RA2I_after, axonal_delays_RA2I_after) = reading.read_connections(fileRA2IAfter) ############# HVC-I -> HVC-RA connections ############# (_, targets_id_I2RA_before, weights_I2RA_before, \ syn_lengths_I2RA_before, axonal_delays_I2RA_before) = reading.read_connections(fileI2RABefore) (_, targets_id_I2RA_after, weights_I2RA_after, \ syn_lengths_I2RA_after, axonal_delays_I2RA_after) = reading.read_connections(fileI2RAAfter) ############ HVC-RA -> HVC-RA connections ############# (_, _, weights_before) = reading.read_weights(fileWeightsBefore) (_, _, weights_after) = reading.read_weights(fileWeightsAfter) ########## Axonal delays ###################### (_, _, axonal_delays_I2RA_from_delay_file_before ) = reading.read_axonal_delays(fileAxonalDelaysI2RABefore) (_, _, axonal_delays_I2RA_from_delay_file_after ) = reading.read_axonal_delays(fileAxonalDelaysI2RAAfter) (_, _, axonal_delays_RA2RA_from_delay_file_before ) = reading.read_axonal_delays(fileAxonalDelaysRA2RABefore) (_, _, axonal_delays_RA2RA_from_delay_file_after ) = reading.read_axonal_delays(fileAxonalDelaysRA2RAAfter) (_, _, axonal_delays_RA2I_from_delay_file_before
replacement_correct = False print "Super connections from not replaced HVC(RA) neurons to not replaced HVC(RA) neuron changed for neuron {0}".format(i) break else: # for replaced neurons just check if target list is empty if len(targets_ID_after[i]) > 0: replacement_correct = False print "Super connections from replaced HVC(RA) neurons exist for neuron {0}".format(i) break print "HVC(RA) -> HVC(RA) super connections replacement went correctly: ",replacement_correct ######################################### # Check weight replacement ######################################### _, _, weights_before = reading.read_weights(filename_weights_before) _, _, weights_after = reading.read_weights(filename_weights_after) ind_matrix_with_changes = np.where(np.array(weights_before) != np.array(weights_after)) replacement_correct = True for i in range(ind_matrix_with_changes[0].shape[0]): if ind_matrix_with_changes[0][i] in not_replaced: # check if weight changed from not replaced to not replaced neuron if ind_matrix_with_changes[1][i] in not_replaced: replacement_correct = False print "Weight from not replaced HVC(RA) neuron to not HVC(RA) neuron changed for neuron {0}".format(ind_matrix_with_changes[0][i]) break
f = plt.figure() ax1 = f.add_subplot(211) ax1.plot(trial_number, num_active_synapses) ax1.set_ylabel("# active synapses") ax2 = f.add_subplot(212) ax2.plot(trial_number, num_supersynapses) ax2.set_xlabel("Time (# trials)") ax2.set_ylabel("# supersynapses") ############################################## # plot weight distributions ############################################## (_, _, weights_RA2RA) = reading.read_weights( os.path.join(dataDir, "weights_" + str(trial) + ".bin")) (_, targets_ID, weights_RA2I, syn_lengths, axonal_delays) = reading.read_connections( os.path.join(dataDir, "RA_I_connections_" + str(trial) + ".bin")) (_, targets_ID, weights_I2RA, syn_lengths, axonal_delays) = reading.read_connections( os.path.join(dataDir, "I_RA_connections_" + str(trial) + ".bin")) f = plt.figure() ax1 = f.add_subplot(131) ax1.hist([w / A_D for weights in weights_RA2RA for w in weights], bins=50) ax1.set_ylabel("Counts") ax1.set_xlabel("Synaptic weight HVC-RA -> HVC-RA") ax1.set_yscale('log')
dirname, "RA_RA_active_connections_" + str(trial_number) + ".bin") fileSuperSynapses = os.path.join( dirname, "RA_RA_super_connections_" + str(trial_number) + ".bin") fileTraining = os.path.join(dirname, "training_neurons.bin") fileMature = os.path.join(dirname, "mature_" + str(trial_number) + ".bin") fileAxonalDelaysRA2RA = os.path.join( dirname, "axonal_delays_RA2RA_" + str(trial_number) + ".bin") #fileActive = "/home/eugene/Output/networks/chainGrowth/testGrowthDelays3/RA_RA_active_connections_5300.bin" #(_, _, active_synapses) = reading.read_synapses(fileActive) (_, _, axonal_delays_RA2RA) = reading.read_axonal_delays(fileAxonalDelaysRA2RA) (_, _, active_synapses) = reading.read_synapses(fileActiveSynapses) (_, _, super_synapses) = reading.read_synapses(fileSuperSynapses) (_, _, weights) = reading.read_weights(fileWeights) (_, _, mature_indicators) = reading.read_remodeled_indicators(fileMature) training_neurons = reading.read_training_neurons(fileTraining) print "Mature neurons: ", [ i for i in np.where(mature_indicators == 1)[0] if i not in training_neurons ] print "Training neurons: ", training_neurons for i in training_neurons: print "Training neuron {0} has {1} supersynapses : {2}".format( i, len(super_synapses[i]), super_synapses[i]) print axonal_delays_RA2RA[228][231] print weights[228][231]
def update(self): (self.N_RA, w) = read.read_weights(self.file_weights) self.mod_time_RA_RA = os.path.getmtime(filenameRA_RA) self.mod_time_wgh = os.path.getmtime(self.file_weights) self.mod_time_time = os.path.getmtime(self.file_time_soma) self.weights = [item for sublist in w for item in sublist] for i in range(len(self.weights)): if self.weights[i] < sys.float_info.epsilon: self.weights[i] = 0 self.hist, self.bin_edges = np.histogram(self.weights, bins=100) # update mean and std dependences on time sigma = std(self.weights) mu = mean(self.weights) self.mean.append(mu) self.std.append(sigma) # update time pattern of spikes self.trial_number, simulation_time, spike_times_dend, neuronID_dend = read.read_time_info( self.file_time_dend) unused, unused, spike_times_soma, neuronID_soma = read.read_time_info( self.file_time_soma) (unused, RA_super_targets, unused) = read.read_connections(filenameRA_RA_super) # extract strongly connected neurons superTargets = set( [element for sublist in RA_super_targets for element in sublist]) superSources = set([ i for i in xrange(len(RA_super_targets)) if len(RA_super_targets[i]) > 0 ]) stronglyConnected = superTargets | superSources self.time.append(simulation_time / 1000) self.spike_times_soma = [ item for sublist in spike_times_soma for item in sublist ] self.ID_soma = [item for sublist in neuronID_soma for item in sublist] self.spike_times_dend = [ item for sublist in spike_times_dend for item in sublist ] self.ID_dend = [item for sublist in neuronID_dend for item in sublist] # check that spike times are in range if len(self.spike_times_soma) > 1: if min(self.spike_times_soma) < 0: print "Somatic spike time is negative! Min somatic spike = ", min( self.spike_times_soma) if max(self.spike_times_soma) > TRIAL_DURATION: print "Somatic spike time exceeds trial duration!" if len(self.spike_times_dend) > 1: if min(self.spike_times_dend) < 0: print "Dendritic spike time is negative! Min dendritic spike = ", min( self.spike_times_dend) if max(self.spike_times_dend) > TRIAL_DURATION: print "Dendritic spike time exceeds trial duration!" # extract only spikes of strongly connected neurons self.ID_soma_strong = [ i for i in self.ID_soma if i in stronglyConnected ] self.spike_times_soma_strong = [ t for ind, t in enumerate(self.spike_times_soma) if self.ID_soma[ind] in stronglyConnected ] self.ID_dend_strong = [ i for i in self.ID_dend if i in stronglyConnected ] self.spike_times_dend_strong = [ t for ind, t in enumerate(self.spike_times_dend) if self.ID_dend[ind] in stronglyConnected ] self.order_dend() self.order_soma() #ID = range(self.N_RA) #self.spike_times = sorted(spike_times) #temp = sorted(zip(ID, spike_times), key=lambda par:par[1]) #self.ID, self.spike_times = zip(*temp) (unused, self.edges, self.active_weights) = read.get_RA2RA_graph(filenameRA_RA) active_synapses = len(self.active_weights) #print active_synapses #print self.active_weights supersynapses = sum(1 for w in self.active_weights if w > SUPERSYNAPSE_THRESHOLD) #print supersynapses self.active_synapses.append(active_synapses) self.supersynapses.append(supersynapses) #self.weights = map(lambda x: x*10, self.weights) # create new empty graph self.G_temp = nx.DiGraph() self.G_temp.add_nodes_from( self.G.nodes(data=True)) # read nodes from the previous graph self.G = self.G_temp for i in range(len(self.edges)): self.G.add_edge(self.edges[i][0], self.edges[i][1], weight=self.active_weights[i]) self.edgewidth = [d['weight'] for (u, v, d) in self.G.edges(data=True)] self.update_edge_color()
def write_pajek_network_subset(dirname, trial_number, N, fileSpikes): """ Create .net file with locations and connections between mature HVC-RA neurons in array first N mature neurons that spiked are plotted """ file_RA_xy = os.path.join(dirname, "RA_xy_" + str(trial_number) + ".bin") file_training = os.path.join(dirname, "training_neurons.bin") file_pajek = os.path.join(dirname, "network_subset_" + str(trial_number) + ".net") fileMature = os.path.join(dirname, "mature_" + str(trial_number) + ".bin") fileSuperSynapses = os.path.join( dirname, "RA_RA_super_connections_" + str(trial_number) + ".bin") fileWeights = os.path.join(dirname, "weights_" + str(trial_number) + ".bin") coord_RA = reading.read_coordinates(file_RA_xy) training_neurons = reading.read_training_neurons(file_training) (N_RA, _, weights) = reading.read_weights(fileWeights) (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) (_, _, super_synapses) = reading.read_synapses(fileSuperSynapses) #print list(mature_neurons) #mature_neurons = range(N_RA) # sort array with neurons and training neurons # training_neurons.sort() #fileDend = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test/noImmatureOut4/test_spike_times_dend_5.bin" #fileSoma = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test/noImmatureOut4/test_spike_times_soma_5.bin" (_, _, spike_times_soma, neuron_fired_soma) = reading.read_time_info(fileSpikes) ordered_soma_spikes_raw, ordered_soma_raw = zip( *sorted(zip(spike_times_soma, neuron_fired_soma))) first_mature_spiked = [] for spikes, neuron_ids in zip(ordered_soma_spikes_raw, ordered_soma_raw): if len(first_mature_spiked) >= N: break if mature_indicators[neuron_ids[0]] == 1: first_mature_spiked.append(neuron_ids[0]) first_mature_spiked.sort() num_neurons = len(first_mature_spiked) with open(file_pajek, 'w') as f: f.write("*Vertices {0}\n".format(num_neurons)) for i, neuron_id in enumerate(first_mature_spiked): if neuron_id in training_neurons: f.write('{0} "{1}" {2} {3} {4} ic Green\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) else: f.write('{0} "{1}" {2} {3} {4} ic Yellow\n'.format( i + 1, neuron_id, coord_RA[neuron_id][0], coord_RA[neuron_id][1], coord_RA[neuron_id][2])) f.write("*Arcs\n".format(num_neurons)) # write targets of HVC(RA) neurons for i, source_id in enumerate(first_mature_spiked): for target_id in super_synapses[source_id]: try: ind = utils.index(first_mature_spiked, target_id) f.write('{0} {1} {2} c Green\n'.format( i + 1, ind + 1, weights[source_id][target_id])) except ValueError: continue
(_, _, spike_times_dend_noDelays, neuron_fired_dend_noDelays) = reading.read_time_info(fileDend_noDelays) (_, _, spike_times_soma_noDelays, neuron_fired_soma_noDelays) = reading.read_time_info(fileSoma_noDelays) (_, _, spike_times_interneuron_noDelays, interneuron_fired_noDelays) = reading.read_time_info(fileInterneuron_noDelays) (_, _, spike_times_dend_zeroDelays, neuron_fired_dend_zeroDelays) = reading.read_time_info(fileDend_zeroDelays) (_, _, spike_times_soma_zeroDelays, neuron_fired_soma_zeroDelays) = reading.read_time_info(fileSoma_zeroDelays) (_, _, spike_times_interneuron_zeroDelays, interneuron_fired_zeroDelays ) = reading.read_time_info(fileInterneuron_zeroDelays) (_, _, weights_noDelays) = reading.read_weights(fileWeights_noDelays) (_, _, weights_zeroDelays) = reading.read_weights(fileWeights_zeroDelays) (_, _, active_synapses_noDelays) = reading.read_synapses(fileActiveSynapses_noDelays) (_, _, active_synapses_zeroDelays ) = reading.read_synapses(fileActiveSynapses_zeroDelays) print np.array_equal(np.array(spike_times_dend_noDelays), np.array(spike_times_dend_zeroDelays)) print np.array_equal(np.array(neuron_fired_dend_noDelays), np.array(neuron_fired_dend_zeroDelays)) print np.array_equal(np.array(spike_times_soma_noDelays), np.array(spike_times_soma_zeroDelays)) print np.array_equal(np.array(neuron_fired_soma_noDelays),