def get_num_active_and_super_synapses(dirname, end_trial, trialStep): """ Calculate time sequence of total number of active and super connections in the network """ num_timepoints = end_trial / trialStep + 1 num_active = np.zeros(num_timepoints, np.int32) num_super = np.zeros(num_timepoints, np.int32) current_trial = 0 timepoint = 0 while current_trial <= end_trial: fileActive = os.path.join(dirname, "RA_RA_active_connections_" + str(current_trial) + ".bin") fileSuper = os.path.join(dirname, "RA_RA_super_connections_" + str(current_trial) + ".bin") (_, _, active_synapses) = reading.read_synapses(fileActive) (_, _, super_synapses) = reading.read_synapses(fileSuper) for i in range(len(active_synapses)): num_active[timepoint] += len(active_synapses[i]) num_super[timepoint] += len(super_synapses[i]) timepoint += 1 current_trial += trialStep return num_active, num_super
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 get_networkSize_vs_time(dirname): """ Get network size and time from files in the directory """ files = os.listdir(dirname) time = [] network_size = [] for f in files: if "RA_RA_super_connections" in f: time.append(int(f.split("_")[-1].split(".bin")[0])) (N_RA, _, super_synapses) = reading.read_synapses(os.path.join(dirname, f)) has_input_supersynapse = np.zeros(N_RA, np.bool) #print has_input_supersynapse for i in range(N_RA): for target in super_synapses[i]: has_input_supersynapse[target] = True network_size.append(len(np.where(has_input_supersynapse == True)[0])) return time, network_size
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 plot_activity_of_not_connected(activity_history, training_neurons, dirname, trial_number): """ Plot population firing rate of neurons that do not receive active or super synapses and are not among training set """ num_neurons = activity_history.shape[0] current_trial = trial_number time = [] not_connected_population_firing_rate = [] timepoint = 0 while current_trial >= 0: time.append(current_trial) fileActiveSynapses = os.path.join( dirname, "RA_RA_active_connections_" + str(current_trial) + ".bin") (_, _, active_synapses) = reading.read_synapses(fileActiveSynapses) not_connected_neurons = [] num_active_inputs = np.zeros(num_neurons, np.int32) for i in range(num_neurons): for target in active_synapses[i]: num_active_inputs[target] += 1 for i in range(num_neurons): if num_active_inputs[i] == 0 and i not in training_neurons: not_connected_neurons.append(i) print "trial {0}; num not connected neurons = {1}".format( current_trial, len(not_connected_neurons)) not_connected_population_firing_rate.append( float((activity_history[not_connected_neurons].sum( axis=0))[timepoint * trialStep]) / float(len(not_connected_neurons))) #print activity_history[not_connected_neurons].sum(axis=0)[current_trial] current_trial -= trialStep timepoint += 1 plt.figure() plt.plot(time, not_connected_population_firing_rate) plt.xlabel('time (# of trials)') plt.ylabel('< firing rate of not connected neurons > (Hz)')
burstsNeuron[0]) > 1: first_spike_time_for_fsi.append(burstsNeuron[0][0]) fsi.append(burstsNeuron[0][1] - burstsNeuron[0][0]) else: print "Neuron {0} produced {1} bursts\n".format( id[0], len(burstsNeuron)) plt.figure() plt.scatter(first_spike_time_for_fsi, fsi) plt.xlabel('First spike time (ms)') plt.ylabel('First spike time interval (ms)') ########################################################### # calculate delivery time of the first spike in the burst # ########################################################### (_, _, active_synapses) = reading.read_synapses( os.path.join(dataDir, "RA_RA_active_connections_" + str(trial) + ".bin")) (_, _, super_synapses) = reading.read_synapses( os.path.join(dataDir, "RA_RA_super_connections_" + str(trial) + ".bin")) (_, _, axonal_delays_RA2I) = reading.read_axonal_delays( os.path.join(dataDir, "axonal_delays_RA2I_" + str(trial) + ".bin")) (_, _, axonal_delays_RA2RA) = reading.read_axonal_delays( os.path.join(dataDir, "axonal_delays_RA2RA_" + str(trial) + ".bin")) (_, _, axonal_delays_I2RA) = reading.read_axonal_delays( os.path.join(dataDir, "axonal_delays_I2RA_" + str(trial) + ".bin")) nbins = 50 f = plt.figure() ax = f.add_subplot(111)
trial_number = 11900 fileSpikes = os.path.join(dirname, "test/" + sim_name + "test_spike_times_soma_5.bin") fileConnectionsRA2RA = os.path.join( dirname, sim_name + "RA_RA_super_connections_" + str(trial_number) + ".bin") #fileAxonalDelaysRA2RA = os.path.join(dirname, sim_name + "axonal_delays_RA2RA_" + str(trial_number) + ".bin") (trial_number, simulation_time, spike_times_raw, neuron_fired) = reading.read_time_info(fileSpikes) ( N_RA, _, RA2RA_targets_ID, ) = reading.read_synapses(fileConnectionsRA2RA) #(_, _, axonal_delays_RA2RA) = reading.read_axonal_delays(fileAxonalDelaysRA2RA) print "Number of HVC(RA) neurons = ", N_RA #print neuron_fired threshold = 1.0 all_first_spike_times = np.empty(N_RA, np.float32) all_first_spike_times.fill(-100.0) num_bursts = 0 for n, time in zip(neuron_fired, spike_times_raw): num_bursts += 1
fileWeights = os.path.join(dirname, "weights_" + str(trial_number) + ".bin") fileActiveSynapses = os.path.join( 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]
fileActive = os.path.join( dirname, "RA_RA_active_connections_" + str(trial_number) + ".bin") fileSuper = os.path.join( dirname, "RA_RA_super_connections_" + str(trial_number) + ".bin") fileMature = os.path.join(dirname, "mature_" + str(trial_number) + ".bin") fileSpikes = "/home/eugene/results/immature/clusters/test/matTrans44/test_spike_times_soma_10.bin" #fileSpikes = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test/maturationTransition4/test_spike_times_soma_7.bin" (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) mature_neurons = np.where(mature_indicators == 1)[0] (trial_number, simulation_time, spike_times_raw, neuron_fired) = reading.read_time_info(fileSpikes) (N_RA, _, active_synapses) = reading.read_synapses(fileActive) (N_RA, _, super_synapses) = reading.read_synapses(fileSuper) print "Number of HVC(RA) neurons = ", N_RA #print neuron_fired threshold = 1.0 all_first_spike_times = np.empty(N_RA, np.float32) all_first_spike_times.fill(-100.0) num_bursts = 0 for n, time in zip(neuron_fired, spike_times_raw): num_bursts += 1
network_dir = "/home/eugene/Output/networks/chainGrowth/testGrowthDelays3/" #network_name = "out50_active30_1ms" #sim_name = "ee0.015_ie0.03_newModel_burstOnsets_0_" fileMature = os.path.join(network_dir, "mature_" + str(trial_number) + ".bin") fileActiveSynapses = os.path.join( network_dir, "RA_RA_active_connections_" + str(trial_number) + ".bin") fileAxonalDelaysRA2RA = os.path.join( network_dir, "axonal_delays_RA2RA_" + str(trial_number) + ".bin") fileSpikeTimes = "/home/eugene/Output/networks/chainGrowth/matureTest/test_spike_times_soma_2.bin" #MARGIN_LATE = 0.5 # margin for the burst coming late MARGIN_LATE = 0.0 # margin for the burst coming late (N_RA, _, mature_indicators) = reading.read_mature_indicators(fileMature) (_, _, active_synapses) = reading.read_synapses(fileActiveSynapses) (_, _, axonal_delays_RA2RA) = reading.read_axonal_delays(fileAxonalDelaysRA2RA) print "Number of HVC(RA) neurons = ", N_RA (_, _, spike_times_soma, neuron_fired_soma) = reading.read_time_info(fileSpikeTimes) #print "Dedritic spikes: ", neuron_fired_dend #print "Dendritic spike times: ", spike_times_dend #print "Somatic spikes: ", neuron_fired_soma #print "Somatic spike times: ", spike_times_soma #print ordered_soma_spikes_raw #print ordered_soma_raw
#trial_number = 20600 trial_number = 0 fileConnections = os.path.join( datadir, "RA_RA_super_connections_" + str(trial_number) + ".bin") fileDelaysRA2RA = os.path.join( datadir, "axonal_delays_RA2RA_" + str(trial_number) + ".bin") fileMature = os.path.join(datadir, "mature_" + str(trial_number) + ".bin") fileTraining = os.path.join(datadir, "training_neurons.bin") #fileSpikeTimes = "/home/eugene/results/immature/clusters/test/matTrans40/test_spike_times_soma_10.bin" #fileJitter = "/home/eugene/results/immature/clusters/test/matTrans31/jitter.bin" fileJitter = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/chain_0.5_delay_3.0/jitter.bin" (N_RA, _, super_synapses) = reading.read_synapses(fileConnections) (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) training_neurons = reading.read_training_neurons(fileTraining) # reading spike times of particular trial #(_, _, spike_times_raw, neuron_spiked) = reading.read_time_info(fileSpikeTimes) # reading mean spike times _, num_test_trials, \ probability_soma_spike, average_num_soma_spikes_in_trial, first_spike_times, std_first_soma_spike_time,\ probability_dend_spike, average_num_dend_spikes_in_trial, mean_first_dend_spike_time, std_first_dend_spike_time = reading.read_jitter(fileJitter) print "Number of HVC(RA) neurons = ", N_RA #============================================================================== # first_spike_times = np.empty(N_RA, np.float32)
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
dirname, "RA_RA_active_connections_" + str(trial_number) + ".bin") #fileSpikeTimes = os.path.join(dirname, "spike_times_soma_" + str(trial_number) + ".bin") fileDelaysRA2RA = os.path.join( dirname, "axonal_delays_RA2RA_" + str(trial_number) + ".bin") fileMature = os.path.join(dirname, "mature_" + str(trial_number) + ".bin") fileWeights = os.path.join(dirname, "weights_" + str(trial_number) + ".bin") fileTraining = os.path.join(dirname, "training_neurons.bin") #fileSpikeTimes = "/home/eugene/Output/networks/chainGrowth/passiveDendrite/test/maturationTransition4/test_spike_times_soma_7.bin" #fileSpikeTimes = "/home/eugene/results/immature/clusters/test/matTrans44/test_spike_times_soma_10.bin" fileSpikeTimes = "/mnt/hodgkin/eugene/results/immature/clusters/matTrans54/spike_times_soma_13400.bin" MARGIN_LATE = 0.0 # margin for the burst coming late (N_RA, _, active_synapses) = reading.read_synapses(fileConnections) (_, _, spike_times_raw, neuron_spiked) = reading.read_time_info(fileSpikeTimes) (_, _, axonal_delays_RA2RA) = reading.read_axonal_delays(fileDelaysRA2RA) (_, _, weights) = reading.read_weights(fileWeights) (_, _, mature_indicators) = reading.read_mature_indicators(fileMature) training_neurons = reading.read_training_neurons(fileTraining) print "Number of HVC(RA) neurons = ", N_RA first_spike_times = np.empty(N_RA, np.float32) first_spike_times.fill(-1.0) for n, time in zip(neuron_spiked, spike_times_raw): first_spike_times[n[0]] = time[0] delivered_times_and_id = []
########################################################## N_RA = 1000 source_neuron = 195 ##### find all supersynaptic targets ever existing from source neuron all_supersynapse_targets = set() current_trial = 0 timepoint = 0 while current_trial <= trial_number: fileSuper = os.path.join( dirname, "RA_RA_super_connections_" + str(current_trial) + ".bin") (N, _, super_synapses) = reading.read_synapses(fileSuper) for target_id in super_synapses[source_neuron]: all_supersynapse_targets.add(target_id) timepoint += 1 current_trial += trialStep target_neurons = list(all_supersynapse_targets) print "Target neurons: ", target_neurons for target in target_neurons: print "{0} -> {1} delay = {2}".format( source_neuron, target, axonal_delays_RA2RA[source_neuron][target]) synaptic_weights = utils.get_weight_time_sequence_from_source(
N = 1000 N_I = 200 replaced_neurons = reading.read_replaced_neurons(fileReplaced) replaced_neurons_trial = set(replaced_neurons[starting_trial]) not_replaced_trial = [i for i in range(N) if i not in replaced_neurons_trial] #print replaced_neurons_trial ######### coordinates ############## coordBefore = reading.read_coordinates(fileCoordBefore) coordAfter = reading.read_coordinates(fileCoordAfter) ######### active synapses ############## (_, _, active_synapses_before) = reading.read_synapses(fileActiveBefore) (_, _, active_synapses_after) = reading.read_synapses(fileActiveAfter) ######### super synapses ############### (_, _, super_synapses_before) = reading.read_synapses(fileSuperBefore) (_, _, super_synapses_after) = reading.read_synapses(fileSuperAfter) ############# 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, \
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), np.array(neuron_fired_soma_zeroDelays)) print np.array_equal(np.array(spike_times_interneuron_noDelays), np.array(spike_times_interneuron_zeroDelays))