Of course.
from network import createNetwork
network = createNetwork()
regions = network.regions
for x in range(20):
regions['L1_encoder_context'].setParameter('sensedValue', float(1.0))
regions['L1_encoder_category'].setParameter('sensedValue', 1)
regions['L1_encoder_case'].setParameter('sensedValue', 1)
regions['L1_encoder_symbol'].setParameter('sensedValue', ord('a'))
network.run(1)
print network.regions['L1_encoder_context'].getParameter('sensedValue')
print network.regions['L1_encoder_context'].spec
print network.regions['L1_encoder_context'].getOutputData('bucket')
print network.regions['L1_encoder_context'].getOutputData('encoded')
exit()
print regions['L1_sp'].getOutputData('topDownOut').nonzero()
print regions['L1_sp'].getOutputData('spatialTopDownOut').nonzero()
print regions['L1_sp'].getOutputData('temporalTopDownOut').nonzero()
print regions['L1_sp'].getOutputData('bottomUpOut').nonzero()
print regions['L1_sp'].getOutputData('anomalyScore').nonzero()
print regions['L1_tm'].getOutputData('lrnActiveStateT').nonzero()
print regions['L1_tm'].getOutputData('activeCells').nonzero()
print regions['L1_tm'].getOutputData('bottomUpOut').nonzero()
print regions['L1_tm'].getOutputData('topDownOut').nonzero()
print regions['L1_tm'].getOutputData('predictedActiveCells').nonzero()
print regions['L1_tm'].getOutputData('anomalyScore').nonzero()
exit()
from nupic.engine import Network
from nupic.encoders import ScalarEncoder
import json
from params import PARAMS
def encoderToClLinks(network, encoder_name, cl_name):
network.link(encoder_name, cl_name, "UniformLink", "", srcOutput="bucketIdxOut", destInput="bucketIdxIn")
network.link(encoder_name, cl_name, "UniformLink", "", srcOutput="actValueOut", destInput="actValueIn")
network.link(encoder_name, cl_name, "UniformLink", "", srcOutput="categoryOut", destInput="categoryIn")
def createNetwork():
# create network
network = Network()
########################
### LEVEL 1
########################
# LEVEL 1 encoders
L1_encoder_context = network.addRegion(
'L1_encoder_context',
'ScalarSensor',
json.dumps(PARAMS['L1']['encoder']['context'])
)
L1_encoder_category = network.addRegion(
'L1_encoder_category',
'ScalarSensor',
json.dumps(PARAMS['L1']['encoder']['category'])
)
L1_encoder_case = network.addRegion(
'L1_encoder_case',
'ScalarSensor',
json.dumps(PARAMS['L1']['encoder']['case'])
)
L1_encoder_symbol = network.addRegion(
'L1_encoder_symbol',
'ScalarSensor',
json.dumps(PARAMS['L1']['encoder']['symbol'])
)
L1_encoder_context_n = L1_encoder_context.getParameter('n')
L1_encoder_category_n = L1_encoder_category.getParameter('n')
L1_encoder_case_n = L1_encoder_case.getParameter('n')
L1_encoder_symbol_n = L1_encoder_symbol.getParameter('n')
input_width = L1_encoder_context_n + L1_encoder_category_n + L1_encoder_case_n + L1_encoder_symbol_n
# LEVEL 1 SP
PARAMS['L1']['sp']['inputWidth'] = input_width
network.addRegion(
'L1_sp',
'py.SPRegion',
json.dumps(PARAMS['L1']['sp'])
)
network.regions['L1_sp'].setParameter("learningMode", True)
# LEVEL 1 TM
PARAMS['L1']['tm']['inputWidth'] = input_width
network.addRegion(
'L1_tm',
'py.TMRegion',
json.dumps(PARAMS['L1']['tm'])
)
network.regions['L1_tm'].setParameter("learningMode", True)
network.regions['L1_tm'].setParameter("inferenceMode", True)
########################
# LEVEL 1 CL
########################
network.addRegion('L1_cl', "py.SDRClassifierRegion", json.dumps(PARAMS['L1']['cl']))
network.regions['L1_cl'].setParameter('inferenceMode', True)
network.regions['L1_cl'].setParameter('learningMode', True)
########################
### LEVEL 1 END
########################
########################
### LEVEL 2
########################
########################
### LEVEL 2 END
########################
########################
### LEVEL 3
########################
########################
### LEVEL 3 END
########################
########################
### LEVEL 4
########################
########################
### LEVEL 4 END
########################
########################
### LINKS
########################
# LEVEL 1 LINKS from encoder 1 to SP 1
network.link("L1_encoder_context", "L1_sp", "UniformLink", "")
network.link("L1_encoder_category", "L1_sp", "UniformLink", "")
network.link("L1_encoder_case", "L1_sp", "UniformLink", "")
network.link("L1_encoder_symbol", "L1_sp", "UniformLink", "")
# LEVEL 1 LINKS from SP 1 to TM 1
network.link("L1_sp", "L1_tm", "UniformLink", "")
encoderToClLinks(network, "L1_encoder_context", 'L1_cl')
return network
PARAMS = {
# LEVEL 1
'L1': {
'encoder': {
'context': {
'n': 21,
'w': 11,
'minValue': 0.0,
'maxValue': 1.0
},
'category': {
'n': 21,
'w': 11,
'minValue': 0.0,
'maxValue': 1.0
},
'case': {
'n': 20,
'w': 5,
'minValue': 0.0,
'maxValue': 3.0
},
'symbol': {
'n': 155,
'w': 5,
'minValue': 0.0,
'maxValue': 105.0
}
},
'sp': {
'spatialImp': 'cpp',
'globalInhibition': 1,
'columnCount': 155,
'numActiveColumnsPerInhArea': 40,
'seed': 1956,
'potentialPct': 0.8,
'synPermConnected': 0.1,
'synPermActiveInc': 0.1,
'synPermInactiveDec': 0.0005,
'boostStrength': 0.0
},
'tm': {
'columnCount': 155,
'cellsPerColumn': 32,
'seed': 1960,
'temporalImp': 'cpp',
'newSynapseCount': 20,
'maxSynapsesPerSegment': 32,
'maxSegmentsPerCell': 128,
'initialPerm': 0.21,
'permanenceInc': 0.1,
'permanenceDec': 0.1,
'globalDecay': 0.0,
'maxAge': 0,
'minThreshold': 9,
'activationThreshold': 12,
'outputType': 'normal',
'pamLength': 3
},
'cl': {
'alpha': 0.005,
'steps': '1,5',
'implementation': 'cpp',
'maxCategoryCount': '1000',
'verbosity': 0
}
}
# LEVEL 2
# LEVEL 3
# LEVEL 4
}
It is our 3 files .