def num_neurons(function_file):
	file = abstractfile.open(function_file, 'r')
	header = file.readline()
	if 'version' in header:
		header = file.readline()
	file.close()
	entries = header.split()
	return int(entries[2])
Beispiel #2
0
def num_neurons(function_file):
    file = abstractfile.open(function_file, 'r')
    header = file.readline()
    if 'version' in header:
        header = file.readline()
    file.close()
    entries = header.split()
    return int(entries[2])
def num_synapses(function_file):
	file = abstractfile.open(function_file, 'r')
	header = file.readline()
	if 'version' in header:
		header = file.readline()
		index = 5
	else:
		index = 4
	file.close()
	entries = header.split()
	return int(entries[index])
Beispiel #4
0
def num_synapses(function_file):
    file = abstractfile.open(function_file, 'r')
    header = file.readline()
    if 'version' in header:
        header = file.readline()
        index = 5
    else:
        index = 4
    file.close()
    entries = header.split()
    return int(entries[index])
    def getRawValue( self, geneName ):
        index = self.schema.getIndex( geneName )
        
        genomePath = os.path.join( self.schema.path_run, 'genome/agents/genome_%d.txt' % self.agentNumber )
        f = abstractfile.open( genomePath )

        for i in range(index+1):
            line = f.readline()

        f.close()

        return int( line )
Beispiel #6
0
    def getRawValue(self, geneName):
        index = self.schema.getIndex(geneName)

        genomePath = os.path.join(
            self.schema.path_run,
            'genome/agents/genome_%d.txt' % self.agentNumber)
        f = abstractfile.open(genomePath)

        for i in range(index + 1):
            line = f.readline()

        f.close()

        return int(line)
def read_anatomy(anatomy_file):
	ga = []
	gp = []

	def __num_input_neurons(header):
		start = header.rfind('-') + 1
		if start > 1:  # new-style anatomy file that has the input neuron info
			return int(header[start:]) + 1  # +1 because the value in the header is a 0-based index, but we need a count
		else:  # old-style anatomy file that doesn't have input neuron info
			# /pwd/run_df8_F30_complexity_0_partial/brain/Recent/0/../../anatomy/brainAnatomy_1_death.txt
			brain_dir = anatomy_file[:anatomy_file.find('Recent')]
			agent_id = anatomy_file.split('_')[-2]
			function_filename = brain_dir + 'function/brainFunction_' + agent_id + '.txt'
			# don't bother with abstractfile since this is an old format
			function_file = open(function_filename, 'r')
			function_header = function_file.readline()
			function_file.close()
			return int(function_header.split(' ')[-2])
	
	file = abstractfile.open(anatomy_file, 'r')
	lines = file.readlines()
	file.close()
	
	header = lines[0].rstrip()  # get rid of the newline
	num_input_neurons = __num_input_neurons(header)

	lines.pop(0) # drop the header line

	for i in range(len(lines)-1):  # -1 to leave out the bias unit
		l = lines[i].split()
		l.remove(';')
		row_a = []
		row_p = []
		for j in range(len(l)-1):  # -1 to leave out the bias links
			if j == i:
				w = float(l[j])
				if w != 0.0:
					print 'self-connection in', anatomy_file, 'i = j =', i, 'w =', w
					w = 0.0
			else:
				w = abs(float(l[j]))
			row_a.append(w)
			if j >= num_input_neurons:
				row_p.append(w)
		ga.append(row_a)  # must agree with neuron-sets and graph-types in common_metric.py
		if i >= num_input_neurons:
			gp.append(row_p)  # must agree with neuron-sets and graph-types in common_metric.py
	
	for i in range(len(ga)):
		for j in range(i):
			temp = ga[i][j]
			ga[i][j] = ga[j][i]
			ga[j][i] = temp
	
	for i in range(len(gp)):
		for j in range(i):
			temp = gp[i][j]
			gp[i][j] = gp[j][i]
			gp[j][i] = temp

	return ga, gp, header
Beispiel #8
0
def read_anatomy(anatomy_file):
	ga = []
	gp = []

	def __num_input_neurons(header):
		start = header.rfind('-') + 1
		if start > 1:  # new-style anatomy file that has the input neuron info
			return int(header[start:]) + 1  # +1 because the value in the header is a 0-based index, but we need a count
		else:  # old-style anatomy file that doesn't have input neuron info
			# /pwd/run_df8_F30_complexity_0_partial/brain/Recent/0/../../anatomy/brainAnatomy_1_death.txt
			brain_dir = anatomy_file[:anatomy_file.find('Recent')]
			agent_id = anatomy_file.split('_')[-2]
			function_filename = brain_dir + 'function/brainFunction_' + agent_id + '.txt'
			# don't bother with abstractfile since this is an old format
			function_file = open(function_filename, 'r')
			function_header = function_file.readline()
			function_file.close()
			return int(function_header.split(' ')[-2])

	def __max_weight(header):
		start = header.find('maxWeight')
		start += header[start:].find('=') + 1
		stop = start + header[start:].find(' ')
		max_weight = float(header[start:stop])
		return max_weight
	
	file = abstractfile.open(anatomy_file, 'r')
	lines = file.readlines()
	file.close()
	
	header = lines[0].rstrip()  # get rid of the newline
	num_input_neurons = __num_input_neurons(header)
	max_weight = __max_weight(header)

	lines.pop(0) # drop the header line

	for i in range(len(lines)-1):  # -1 to leave out the bias unit
		l = lines[i].split()
		l.remove(';')
		row_a = []
		row_p = []
		for j in range(len(l)-1):  # -1 to leave out the bias links
			if j == i:
				w = float(l[j])
				if w != 0.0:
					print 'self-connection in', anatomy_file, 'i = j =', i, 'w =', w
					w = 0.0
			else:
				w = abs(float(l[j]))
			row_a.append(w)
			if j >= num_input_neurons:
				row_p.append(w)
		ga.append(row_a)  # must agree with neuron-sets and graph-types in common_metric.py
		if i >= num_input_neurons:
			gp.append(row_p)  # must agree with neuron-sets and graph-types in common_metric.py
	
	# Transpose the matrixes so g[i][j] describes a connection from i to j (not j to i, as stored)
	for i in range(len(ga)):
		for j in range(i):
			temp = ga[i][j]
			ga[i][j] = ga[j][i]
			ga[j][i] = temp
	
	for i in range(len(gp)):
		for j in range(i):
			temp = gp[i][j]
			gp[i][j] = gp[j][i]
			gp[j][i] = temp

	return ga, gp, max_weight, header