def createNetwork(dataSource):
 network = Network()
 network.addRegion('sensor', 'py.RecordSensor', json.dumps({'verbosity': _VERBOSITY}))
 sensor = network.regions['sensor'].getSelf()
 sensor.encoder = createEncoder()
 sensor.dataSource = dataSource
 SP_PARAMS['inputWidth'] = sensor.encoder.getWidth()
 network.addRegion('spatialPoolerRegion', 'py.SPRegion', json.dumps(SP_PARAMS))
 network.link('sensor', 'spatialPoolerRegion', 'UniformLink', '')
 network.link('sensor', 'spatialPoolerRegion', 'UniformLink', '', srcOutput='resetOut', destInput='resetIn')
 network.link('spatialPoolerRegion', 'sensor', 'UniformLink', '', srcOutput='spatialTopDownOut', destInput='spatialTopDownIn')
 network.link('spatialPoolerRegion', 'sensor', 'UniformLink', '', srcOutput='temporalTopDownOut', destInput='temporalTopDownIn')
 network.addRegion('temporalPoolerRegion', 'py.TPRegion', json.dumps(TP_PARAMS))
 network.link('spatialPoolerRegion', 'temporalPoolerRegion', 'UniformLink', '')
 network.link('temporalPoolerRegion', 'spatialPoolerRegion', 'UniformLink', '', srcOutput='topDownOut', destInput='topDownIn')
 network.addRegion('anomalyLikelihoodRegion', 'py.AnomalyLikelihoodRegion', json.dumps({}))
 network.link('temporalPoolerRegion', 'anomalyLikelihoodRegion', 'UniformLink', '', srcOutput='anomalyScore', destInput='rawAnomalyScore')
 network.link('sensor', 'anomalyLikelihoodRegion', 'UniformLink', '', srcOutput='sourceOut', destInput='metricValue')
 spatialPoolerRegion = network.regions['spatialPoolerRegion']
 spatialPoolerRegion.setParameter('learningMode', True)
 spatialPoolerRegion.setParameter('anomalyMode', False)
 temporalPoolerRegion = network.regions['temporalPoolerRegion']
 temporalPoolerRegion.setParameter('topDownMode', True)
 temporalPoolerRegion.setParameter('learningMode', True)
 temporalPoolerRegion.setParameter('inferenceMode', True)
 temporalPoolerRegion.setParameter('anomalyMode', True)
 return network

def createNetwork ( dataSource ) : network = Network ( ) network . addRegion ( 'sensor' , 'py.RecordSensor' , json . dumps ( { 'verbosity' : _VERBOSITY } ) ) sensor = network . regions [ 'sensor' ] . getSelf ( ) sensor . encoder = createEncoder ( ) sensor . dataSource = dataSource SP_PARAMS [ 'inputWidth' ] = sensor . encoder . getWidth ( ) network . addRegion ( 'spatialPoolerRegion' , 'py.SPRegion' , json . dumps ( SP_PARAMS ) ) network . link ( 'sensor' , 'spatialPoolerRegion' , 'UniformLink' , '' ) network . link ( 'sensor' , 'spatialPoolerRegion' , 'UniformLink' , '' , srcOutput = 'resetOut' , destInput = 'resetIn' ) network . link ( 'spatialPoolerRegion' , 'sensor' , 'UniformLink' , '' , srcOutput = 'spatialTopDownOut' , destInput = 'spatialTopDownIn' ) network . link ( 'spatialPoolerRegion' , 'sensor' , 'UniformLink' , '' , srcOutput = 'temporalTopDownOut' , destInput = 'temporalTopDownIn' ) network . addRegion ( 'temporalPoolerRegion' , 'py.TPRegion' , json . dumps ( TP_PARAMS ) ) network . link ( 'spatialPoolerRegion' , 'temporalPoolerRegion' , 'UniformLink' , '' ) network . link ( 'temporalPoolerRegion' , 'spatialPoolerRegion' , 'UniformLink' , '' , srcOutput = 'topDownOut' , destInput = 'topDownIn' ) network . addRegion ( 'anomalyLikelihoodRegion' , 'py.AnomalyLikelihoodRegion' , json . dumps ( { } ) ) network . link ( 'temporalPoolerRegion' , 'anomalyLikelihoodRegion' , 'UniformLink' , '' , srcOutput = 'anomalyScore' , destInput = 'rawAnomalyScore' ) network . link ( 'sensor' , 'anomalyLikelihoodRegion' , 'UniformLink' , '' , srcOutput = 'sourceOut' , destInput = 'metricValue' ) spatialPoolerRegion = network . regions [ 'spatialPoolerRegion' ] spatialPoolerRegion . setParameter ( 'learningMode' , True ) spatialPoolerRegion . setParameter ( 'anomalyMode' , False ) temporalPoolerRegion = network . regions [ 'temporalPoolerRegion' ] temporalPoolerRegion . setParameter ( 'topDownMode' , True ) temporalPoolerRegion . setParameter ( 'learningMode' , True ) temporalPoolerRegion . setParameter ( 'inferenceMode' , True ) temporalPoolerRegion . setParameter ( 'anomalyMode' , True ) return network
create the network instance .