def testDefaultArgs(self): fs = FunctionSource(dataFunction, state=None, resetFieldName=None, sequenceIdFieldName=None) self.assertIsNotNone(fs) r = fs.getNextRecordDict() self.assertIsNotNone(r)
def testResetAndSequenceFields(self): fs = FunctionSource(dataFunction, state=None, resetFieldName="reset", sequenceIdFieldName="sequence") self.assertIsNotNone(fs) r = fs.getNextRecordDict() self.assertIsNotNone(r)
def testState(self): state = dict(val=100) fs = FunctionSource(dataFunction, state=state, resetFieldName="reset", sequenceIdFieldName="sequence") self.assertIsNotNone(fs) r = fs.getNextRecordDict() self.assertIsNotNone(r) r = fs.getNextRecordDict() r = fs.getNextRecordDict() self.assertEqual(103, state["val"])
def testPickle(self): state = dict(val=100) fs = FunctionSource(dataFunction, state=state, resetFieldName="reset", sequenceIdFieldName="sequence") self.assertIsNotNone(fs) r = fs.getNextRecordDict() self.assertIsNotNone(r) pkl = pickle.dumps(fs) self.assertIsNotNone(pkl) fs2 = pickle.loads(pkl) self.assertIsNotNone(fs2) r = fs2.getNextRecordDict() r = fs2.getNextRecordDict() self.assertEqual(103, fs2.state["val"])
def getDescription(datasets): encoder = MultiEncoder() encoder.addEncoder("date", DateEncoder(timeOfDay=3)) encoder.addEncoder("amount", LogEncoder(name="amount", maxval=1000)) for i in xrange(0, nRandomFields): s = ScalarEncoder(name="scalar", minval=0, maxval=randomFieldWidth, resolution=1, w=3) encoder.addEncoder("random%d" % i, s) dataSource = FunctionSource( generateFunction, dict(nRandomFields=nRandomFields, randomFieldWidth=randomFieldWidth)) inputShape = (1, encoder.getWidth()) # Layout the coincidences vertically stacked on top of each other, each # looking at the entire input field. coincidencesShape = (nCoincidences, 1) # TODO: why do we need input border? inputBorder = inputShape[1] / 2 if inputBorder * 2 >= inputShape[1]: inputBorder -= 1 nodeParams = dict() spParams = dict( commonDistributions=0, inputShape=inputShape, inputBorder=inputBorder, coincidencesShape=coincidencesShape, coincInputRadius=inputShape[1] / 2, coincInputPoolPct=0.75, gaussianDist=0, localAreaDensity=0.10, # localAreaDensity = 0.04, numActivePerInhArea=-1, dutyCyclePeriod=1000, stimulusThreshold=5, synPermInactiveDec=0.08, # synPermInactiveDec=0.02, synPermActiveInc=0.02, synPermActiveSharedDec=0.0, synPermOrphanDec=0.0, minPctDutyCycleBeforeInh=0.05, # minPctDutyCycleAfterInh = 0.1, # minPctDutyCycleBeforeInh = 0.05, minPctDutyCycleAfterInh=0.05, # minPctDutyCycleAfterInh = 0.4, seed=1, ) otherParams = dict( disableTemporal=1, trainingStep='spatial', ) nodeParams.update(spParams) nodeParams.update(otherParams) def mySetupCallback(experiment): print "Setup function called" description = dict( options=dict(logOutputsDuringInference=False, ), network=dict(sensorDataSource=dataSource, sensorEncoder=encoder, CLAType="py.CLARegion", CLAParams=nodeParams, classifierType=None, classifierParams=None), # step spTrain=dict( name="phase1", setup=mySetupCallback, iterationCount=5000, #iter=displaySPCoincidences(100), finish=printSPCoincidences()), tpTrain=None, # same format as sptrain if non-empty infer=None, # same format as sptrain if non-empty ) return description