def obtainNewView(img, disp): H, W, C = img.shape NewView = np.zeros((H, W, C)) for i in range(H): for j in range(W): disp_value = disp[i, j] id = j + disp_value id0 = int(math.floor(id)) id1 = id0 + 1 weight1 = 1 - (id - id0) weight2 = id - id0 id0 = index(id0, W) id1 = index(id1, W) NewView[i, j] = weight1 * img[i, id0] + weight2 * img[i, id1] return NewView
def get_utxo_pool(self): """ get chain loop transaction get output transactions that has public key of client :return: """ self.total_number_messages += len(self.peers) if self.name == 0: # return as it is original client has no pool and no check log( "PERFORMANCE", f'Original client total number of message sent = {self.total_number_messages} messages' ) return blockchain = Blockchain() blockchain = consensus(blockchain, self.peers) self.total_number_messages += len(self.peers) * 2 log("get_utxo_pool", f'blockchain chain: {blockchain.chain}') log( "PERFORMANCE", f'Average number of message sent per block for client {self.name} = {self.total_number_messages / len(blockchain.chain)} messages/block' ) self.utxo_pool = [] for block in blockchain.chain: for tx in block.transactions: if contains_in_list(tx.recipients, self.public_key): i = index(tx.recipients, self.public_key) new_UTXO = UTXO(tx.hash, i, tx.values[i], tx.recipients[i]) self.utxo_pool.append(new_UTXO) inputs = tx.inputs for utxo_input in inputs: if contains_in_list(self.utxo_pool, utxo_input): self.utxo_pool = delete(self.utxo_pool, utxo_input)
def get_utxo_pool(self, sender): """ get chain loop transaction get output transactions that has public key of client :return: """ #TODO check race condition of all APIs utxo_pool = [] for block in self.blockchain.chain: for tx in block.transactions: log("get_utxo_pool", f"checking transaction {tx.__dict__}") log("get_utxo_pool", f"is sender in recipients list? {contains_in_list(tx.recipients, sender)}") if contains_in_list(tx.recipients, sender): i = index(tx.recipients, sender) if i == -1: raise Exception("public key is not found!!") log("get_utxo_pool", f"index of sender is found at {i}") new_UTXO = UTXO(tx.hash, i, tx.values[i], tx.recipients[i]) utxo_pool.append(new_UTXO) inputs = tx.inputs log("get_utxo_pool", f"check transaction input") for utxo_input in inputs: log("get_utxo_pool", f"check utxo input {utxo_input.__dict__}") log("get_utxo_pool", f"is input in utxo pool? {contains_in_list(utxo_pool, utxo_input)}") if contains_in_list(utxo_pool, utxo_input): log("get_utxo_pool", f"remove input utxo from utxo pool") utxo_pool = delete(utxo_pool, utxo_input) log("get_utxo_pool", f"utxo pool resulted: {utxo_pool}") return utxo_pool
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 obtainNewDisp(disp, interp): H, W, C = disp.shape NewDisp = np.zeros((H, W)) for i in range(H): for j in range(W): disp_value = disp[i, j, 0] new_disp_value = disp_value * interp # ??? inew = int(j - new_disp_value) inew = index(inew, W) NewDisp[i, inew] = new_disp_value return NewDisp.astype(np.uint8)
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 simple_obtainNewDisp(disp, interp, semantic): H, W, C = disp.shape NewDisp = np.zeros((H, W)) pMask = np.zeros((H, W), np.uint8) for i in range(H): for j in range(W): disp_value = disp[i, j, 0] new_disp_value = disp_value * interp # ??? inew = int(j - new_disp_value) inew = index(inew, W) NewDisp[i, inew] = new_disp_value if semantic[i, j] != 0: pMask[i, inew] = 1 disp = Image.fromarray(NewDisp.astype(np.uint8)) NewDisp = simple_insert(NewDisp, pMask) disp_1 = Image.fromarray(NewDisp.astype(np.uint8)) NewDisp = insertDepth(NewDisp) disp_2 = Image.fromarray(NewDisp.astype(np.uint8)) return NewDisp.astype(np.uint8), pMask
def get_utxo_pool(self, sender): """ get chain loop transaction get output transactions that has public key of client :return: """ #TODO check race condition of all APIs utxo_pool = [] for block in self.chain: for tx in block.transactions: if contains_in_list(tx.recipients, sender): i = index(tx.recipients, sender) if i == -1: raise Exception("public key is not found!!") new_UTXO = UTXO(tx.hash, i, tx.values[i], tx.recipients[i]) utxo_pool.append(new_UTXO) inputs = tx.inputs for utxo_input in inputs: if contains_in_list(utxo_pool, utxo_input): utxo_pool = delete(utxo_pool, utxo_input) return utxo_pool
1] #print synch_neurons #print "Center time: ",center_time #print first_spike_times[synch_neurons] all_inputs = set() # all inputs received by synchronous neurons inputs_to_synch = [] for n in synch_neurons: inputs = set() for k in range(N_RA): try: ind = utils.index(super_synapses[k], n) inputs.add(k) all_inputs.add(k) except ValueError: continue inputs_to_synch.append(inputs) shared_inputs = set.intersection(*inputs_to_synch) fraction_of_all_inputs = [ float(len(inp)) / float(len(all_inputs)) for inp in inputs_to_synch ] fraction_shared_window.append(
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
OPTIONAL { ?s tb:juniper-infusion ?inf. } }''' accounts = {} for (s, inf, herb, districtn) in sparqllib.query_for_rows(query): inf = (inf == 'true') already_juniper = accounts.get(s, (None, False, None))[1] accounts[s] = (inf, already_juniper or herb == JUNIPER, districtn) accounts = [(districtn, (0.75 + (0.25 if inf else 0)) if juniper else 0) for (inf, juniper, districtn) in accounts.values()] district_index = utils.index(accounts) from pprint import pprint # pprint(district_index) district_to_value = { name: utils.average(points) for (name, points) in district_index.items() } for (district_name) in sparqllib.query_for_list(district_query): if district_name not in district_to_value: district_to_value[district_name] = None # means: no data pprint(district_to_value) themap = config.make_map_from_cli_args(map_type='choropleth')