from scipy import * """------------------------------------------------ read_pwd_anatomy: args: PATH: string path of desired anatomy file ?include_vision: include vision neurons in result? returns: numpy.array matrix representation of anatomy ------------------------------------------------""" def read_pwd_anatomy(PATH, include_vision=False): INFILE = open(PATH, "r") lines = INFILE.readlines() INFILE.close() if not include_vision: lastVisionNeuron = int((lines[0])[-2:-1]) else: lastVisionNeuron = 0 lines = lines[(lastVisionNeuron+1):] for i in range(len(lines)): lines[i] = map(float, lines[i].split()[lastVisionNeuron:-1]) return(array(lines)) """------------------------------------------------ nodes_near: args: nodes: list of indexes of nodes matrix: numpy.array matrix representation of anatomy maxdist: integer value. depth to search thresh: returns: numpy.array matrix representation of anatomy ------------------------------------------------""" def nodes_near_helper(d, node, dists, matrix): dists[node] = d #print(dists) if d-1 < 0: return i = 0 for connection in matrix[node]: if connection != 0 and dists[i] < d-1: #print("Going to node "+str(i)) nodes_near_helper(d-1, i, dists, matrix) i = i + 1 return def nodes_near(nodes, matrix, maxdist, thresh=0.5): matrix = matrix.tolist() dists = [-2]*len(matrix) for n in nodes: nodes_near_helper(maxdist, n, dists, matrix) ans=0 for d in dists: if d > -2: ans = ans + 1 ans = ans - len(nodes) return ans def main(): m = read_pwd_anatomy("brainAnatomy_62_incept.txt") print("\nTesting read_pwd_anatomy:\n\n"+str(m)+"\n\n") m = [[0, 0, 0.4, 0.4, 0, 0], [1, 0, 0.6, 0.2, 1, 0], [0, 2, 4, 0.1, 0.1, 0.5], [0.1, 0.1, 0.1, 0.1, 0.5, 0.4], [0, 0, 0, 0, 0, 0], [1, 1, 0, 1, 0, 0]] m = array(m) n = nodes_near([0], m, 1) print("\nTesting nodes_near:\n\n"+str(n)+"\n") main()