Pasos básicos para crear una red HTM con Nupic

Esta es una breve descripción sobre como crear una red que simula la actividad neuronal usando el framework nupic.
  1. Importar las clases desde el framework
  2. crear una instancia de una red en blanco
  3. Crear sensores y añadirlos a la red
  4. Crear y añadir regiones a la red
  5. Grabar la red en un archivo XML

Ahora un poco de código tomado del ejemplo Bitworms de Nupic (en Python) comentarios en negritas...


from nupic.network import * #paso 1

def createNetwork(untrainedNetwork,
inputSize = 16,
maxDistance = 0.0,
topNeighbors = 3,
maxGroups = 8): #esta es la definición de la función

net = Network() # paso 2

sensor = CreateNode("VectorFileSensor",
phase=0,
dataOut= inputSize) #Paso 3 (definir el sensor)
net.addElement("Sensor", sensor) #paso 3 (añadir a la red)

categorySensor = CreateNode("VectorFileSensor",
phase = 1,
dataOut=1)
net.addElement("CategorySensor", categorySensor) """#se añade otro tipo de sensor para categorizar datos""

level1Node = CreateNode("Zeta1Node",
phase=1,
spatialPoolerAlgorithm= "gaussian",
symmetricTime=False,
transitionMemory=4,
topNeighbors=topNeighbors,
maxGroupSize=50,
temporalPoolerAlgorithm= "sumProp",
bottomUpOut=maxGroups+1,
maxDistance=maxDistance)
net.addElement("Level1", level1Node) #paso 4

topNode = CreateNode("Zeta1TopNode",
phase=2,
spatialPoolerAlgorithm= "dot",
mapperAlgorithm= "sumProp",
categoriesOut=2)
net.addElement("Level2", topNode) """#paso 4 (es el nodo final de la estructura jearquica de la red)"""


effector = CreateNode("VectorFileEffector", phase = 3)
net.addElement("FileOutput", effector) #esto guarda el resultado en un archivo

net.link("Sensor", "dataOut", "Level1", "bottomUpIn") # se liga el elemento en la red

net.link("Level1", "bottomUpOut", "Level2", "bottomUpIn") """# se liga el elemento anterior con el siguiente nivel"""

net.link("CategorySensor", "dataOut", "Level2", "categoryIn") """# se liga el elemento anterior con el siguiente nivel"""


net.link("Level2", "categoriesOut", "FileOutput", "dataIn")


#--------------------------------------------------------
# Step 3.5 Link Sensor to FileOutput node
# For the Sensor connection, we use PassThrough nodes to avoid a
# level-skipping connection, which would prevent the pipeline scheduler from
# working propertly (advanced)
passThrough1 = CreateNode("PassThroughNode",
phase=1,
realOut=inputSize)
net.addElement("PassThrough1", passThrough1)
passThrough2 = CreateNode("PassThroughNode",
phase=2,
realOut=inputSize)
net.addElement("PassThrough2", passThrough2)
net.link("Sensor", "dataOut", "PassThrough1", "realIn")
net.link("PassThrough1", "realOut", "PassThrough2", "realIn")
net.link("PassThrough2", "realOut", "FileOutput", "dataIn")


net.writeXML(untrainedNetwork) #paso 5


#End of code!!!


Fuente: Getting started with Nupic

Comentarios

Entradas populares