-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnarc.py
executable file
·159 lines (140 loc) · 6.08 KB
/
narc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
"""
Neural Cognitive Architecture
"""
from models.fact import Fact
from models.rule import Rule
class NeuralCognitiveArchitecture:
def __init__(self,
exe,
rulesService,
rulesRepository,
neuronRepository,
internRepository,
factGroupRepository,
factRepository,
assertionsRepository,
primeRepository,
linksRepository,
generator,
topology,
baseService,
propertyService,
relationshipService,
connectionService):
self.exe = exe
self.__rulesService = rulesService
self.__rulesRepository = rulesRepository
self.neuronRepository = neuronRepository
self.__internRepository = internRepository
self.__primeRepository = primeRepository
self.__linksRepository = linksRepository
self.factGroupRepository = factGroupRepository
self.factRepository = factRepository
self.__assertionsRepository = assertionsRepository
self.__generator = generator
self.__topology = topology
self.__baseService = baseService
self.__propertyService = propertyService
self.__relationshipService = relationshipService
self.connectionService = connectionService
def apply(self):
# generate network
self.__rulesService.applyRulesToFacts(self.__generator)
# build neurons
self.exe.apply()
def addFact(self, name, attributes, active = True):
return self.factRepository.addFact(Fact(name, attributes), active)
def getFact(self, group, attributes):
return self.factRepository.getFact(Fact(group, attributes))
def addRule(self, name, ifs, thens):
self.__rulesRepository.addRule(Rule(name, ifs, thens))
def __printCa(self, data, pop, caIndex):
start = (caIndex-pop.fromIndex)*10
end = start + 10
for n in range(start, end):
st = data.segments[0].spiketrains[n]
if(len(st) > 0):
for s in st.magnitude:
print("{} {}".format(n, s))
def printSpikes(self):
neuronData = self.get_neuron_data()
caData = self.get_ca_data()
assertions = self.__assertionsRepository.get()
for a in assertions:
assertion = assertions[a]
pop = self.exe.getPopulationFromNeuron(assertion.neuronIndex)
d = neuronData[pop.pop.label]
st = d.segments[0].spiketrains[assertion.neuronIndex-pop.fromIndex]
print("(Assertion: {})".format(a))
if(len(st) > 0):
for s in st.magnitude:
print("{} {}".format(assertion.neuronIndex, s))
primes = self.__primeRepository.get()
for p in primes:
print("(Prime: {})".format(p))
prime = primes[p]
pop = self.exe.getPopulationFromCA(prime.caIndex)
d = caData[pop.pop.label]
self.__printCa(d, pop, prime.caIndex)
links = self.__linksRepository.get()
for linkTo in links:
linkGroup = links[linkTo]
for linkType in linkGroup:
linkTypes = linkGroup[linkType]
for unit in linkTypes:
print("(Link: {}, {}, {})".format(linkTo, unit, linkType))
link = linkTypes[unit]
pop = self.exe.getPopulationFromCA(link.caIndex)
d = caData[pop.pop.label]
self.__printCa(d, pop, link.caIndex)
interns = self.__internRepository.get()
for a in interns:
pop = self.exe.getPopulationFromNeuron(a.neuronIndex)
d = neuronData[pop.pop.label]
st = d.segments[0].spiketrains[a.neuronIndex-pop.fromIndex]
print("(Intern: {})".format(a.neuronIndex))
if(len(st) > 0):
for s in st.magnitude:
print("{} {}".format(a.neuronIndex, s))
groups = self.factGroupRepository.get()
for g in groups:
for f in groups[g]:
print("(f-{} - {} {})".format(f.caIndex, f.group, f.attributes))
pop = self.exe.getPopulationFromCA(f.caIndex)
d = caData[pop.pop.label]
self.__printCa(d, pop, f.caIndex)
if(self.__topology):
inheritanceData = self.__topology.neuralHierarchyTopology.cells.get_data()
baseStructure = self.__baseService.getInheritance()
for u in baseStructure.units:
print("(Base: {})".format(u))
index = baseStructure.getUnitNumber(u)
for n in range(index*10,(index*10)+10):
st = inheritanceData.segments[0].spiketrains[n]
if(len(st) > 0):
for s in st.magnitude:
print("{} {}".format(n, s))
propertyStructure = self.__propertyService.getStructure()
propertyData = self.__topology.propertyCells.get_data()
for u in propertyStructure.units:
print("(Property: {})".format(u))
index = propertyStructure.getUnitNumber(u)
for n in range(index*10,(index*10)+10):
st = propertyData.segments[0].spiketrains[n]
if(len(st) > 0):
for s in st.magnitude:
print("{} {}".format(n, s))
relationshipStructure = self.__relationshipService.getStructure()
relationshipData = self.__topology.relationCells.get_data()
for u in relationshipStructure.units:
print("(Relationship: {})".format(u))
index = relationshipStructure.getUnitNumber(u)
for n in range(index*10,(index*10)+10):
st = relationshipData.segments[0].spiketrains[n]
if(len(st) > 0):
for s in st.magnitude:
print("{} {}".format(n, s))
def get_ca_data(self):
return self.exe.get_ca_data()
def get_neuron_data(self):
return self.exe.get_neuron_data()