Network :Encdoer to Classifier

Hi !

I want to connect encoder region to classifier region, And I got next errors:

       Network::link -- output bucketIdxOut does not exist on region L1_encoder_context

Can you help me? We use Scalar Sensor. We look examples

     network.link(encoder_name, cl_name, "UniformLink", "", srcOutput="bucketIdxOut", destInput="bucketIdxIn")
    network.link(encoder_name, cl_name, "UniformLink", "", srcOutput="actValueOut", destInput="actValueIn")

But our ScalasSensor has only two output parameters:
encoded
bucket.
We can’t set active value through srcOutput because Scalar Sensor hasn’t same output value.

That’s why I think that we have errors. Maybe you have other approaches?

Thanx a lot,
Sergey

Can you show your full script? Are you following the Nework API quick start?

Of course.

main.py

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()

network.py

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.py

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 .

Sorry. But Have you some idea about my problems?

This is mini -version our code:

        from nupic.engine import Network
        import json
        def encoderToClLinks(network, encoder_name, cl_name):
        	network.link(encoder_name, cl_name, "UniformLink", "", srcOutput="bucketIdxOut", dest ut="bucketIdxIn")
        	network.link(encoder_name, cl_name, "UniformLink", "", srcOutput="actValueOut", destInput="actValueIn")
        	network.link(encoder_name, cl_name, "UniformLink", "", srcOutput="categoryOut", destInput="categoryIn")

        network = Network()

        encoder = network.addRegion(
        	'encoder',
        	'ScalarSensor',
        	json.dumps({
        		'n': 21,
        		'w': 11,
        		'minValue': 0.0,
        		'maxValue': 1.0
        	})
        )

        input_width = encoder.getParameter('n')


        network.addRegion(
        	'sp',
        	'py.SPRegion',
        	json.dumps({
        		'inputWidth': input_width,
        		'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
        	})
        )
        network.regions['sp'].setParameter("learningMode", True)


        network.addRegion(
        	'tm',
        	'py.TMRegion',
        	json.dumps({
        		'inputWidth': input_width,
        		'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
        	})
        )
        network.regions['tm'].setParameter("learningMode", True)
        network.regions['tm'].setParameter("inferenceMode", True)

        ########################
        # LEVEL 1 CL
        ########################
        network.addRegion(
        	'cl',
        	"py.SDRClassifierRegion",
        	json.dumps({
        		'alpha': 0.005,
        		'steps': '1,5',
        		'implementation': 'cpp',
        		'maxCategoryCount': '1000',
        		'verbosity': 0
        	})
        )
        network.regions['cl'].setParameter('inferenceMode', True)
        network.regions['cl'].setParameter('learningMode', True)



        # LINKS from encoder 1 to SP 1
        network.link("encoder", "sp", "UniformLink", "")

        # LINKS from SP 1 to TM 1
        network.link("sp", "tm", "UniformLink", "")

        encoderToClLinks(network, "encoder", 'cl')


        network.run(1)

I’m not that familiar with the Network API. Hopefully @scott or @subutai might be able to help.

Those outputs are available on the RecordSensor Python region. It looks like you are using the C++ regions that may not have them. The simple option is to use the RecordSensor, which internally has a MultiEncoder that includes whichever encoder types you need. Alternatively, you can create your own encoder network with the necessary outputs.