I created a simple network using the htmcore’s regions in python. It counts from 0 to 10, but the columns continue to burst because it thinks that the sequence is never ending. How can I reset the network every start of the sequence? It looks like resetIn is the answer, but can’t get it to work.
Here is my code:
{network: [
{addRegion: {name: "encoder1", type: "ScalarEncoderRegion", params: {"size": 12, "w": 2, "minValue": 0, "maxValue": 10, "periodic": true}}},
{addRegion: {name: "sp", type: "SPRegion", params: {
columnCount: 20,
potentialRadius: 1,
potentialPct: 1,
globalInhibition: true,
localAreaDensity: 0,
numActiveColumnsPerInhArea: 3,
stimulusThreshold: 0,
synPermInactiveDec: 0.008000,
synPermActiveInc: 0.050000,
synPermConnected: 0.100000,
minPctOverlapDutyCycles: 0.001000,
dutyCyclePeriod: 1000,
boostStrength: 0.000000,
seed: 25,
spVerbosity: 0,
wrapAround: false,
learningMode: 1,
spatialImp: null
}}},
{addRegion: {name: "tm", type: "TMRegion", params: {
numberOfCols: 20,
cellsPerColumn: 5,
activationThreshold: 1,
initialPermanence: 0.21,
connectedPermanence: 0.500000,
minThreshold: 1,
maxNewSynapseCount: 1,
permanenceIncrement: 0.100000,
permanenceDecrement: 0.100000,
predictedSegmentDecrement: 0.100000,
maxSegmentsPerCell: 255,
maxSynapsesPerSegment: 255,
seed: 42,
learningMode: true,
activeOutputCount: 3,
anomaly: -1.000000,
orColumnOutputs: false
}}},
{addLink: {src: "encoder1.encoded", dest: "sp.bottomUpIn"}},
{addLink: {src: "sp.bottomUpOut", dest: "tm.bottomUpIn"}}
]}
import json
from htm.bindings.sdr import SDR
from htm.bindings.algorithms import SpatialPooler, TemporalMemory
from htm.bindings.encoders import ScalarEncoder
from htm.bindings.engine_internal import Network, Region
import htm.bindings.engine_internal as engine
import numpy as np
import time
from Vis import Vis
def main():
resetInput = None
encoders = []
spRegion = None
tmRegion = None
with open('params', 'r') as file:
content = file.read()
config = content.replace('\n', '')
network = Network() # Note: can't call Network().configure()
network.configure(config)
regions = network.getRegions()
# Get a handle on the regions
for name, region in regions:
region_type = region.getType()
if region_type == 'ScalarEncoderRegion':
encoders.append(region)
elif region_type == 'SPRegion':
spRegion = region
elif region_type == 'TMRegion':
tmRegion = region
# resetInput = SDR(region.getParameterUInt32("numberOfCols"))
# resetInput.dense = [1] * region.getParameterUInt32("numberOfCols")
# resetInput = engine.Array(resetInput, True)
# region.setParameterArray("resetIn", resetInput)
input()
# Instantiate and start the visualization
vis = Vis()
vis.run()
# Calculate the value
value = 0
while True:
if value >= 11:
value = 0
print(tmRegion)
# tmRegion.setParameterArray("resetIn", engine.Array(resetInput, True))
print("Value:",value)
# Set the values by passing them into the encoders
for enc in encoders:
enc.setParameterReal64("sensedValue", value)
network.run(1)
# Pass the state to the visualization
vis.setRegionData(encoders,spRegion, tmRegion)
# Increment the value
value+=1
# Pause
# time.sleep(.2)
input()
if __name__ == '__main__':
main()```