I have the learning mode in tmRegion, and spRegion both true, but when I call run(1), tmRegion.getOutputArray(“predictiveCells”).getSDR() is always empty. Here is my code:
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 numpy as np
from Vis import Vis
def main():
encoders = []
spRegion = None
tmRegion = None
config = """
{network: [
{addRegion: {name: "encoder1", type: "ScalarEncoderRegion", params: {"size": 100, "w": 2, "minValue": 0, "maxValue": 100, "periodic": false}}},
{addRegion: {name: "encoder2", type: "ScalarEncoderRegion", params: {"size": 100, "w": 2, "minValue": 0, "maxValue": 100, "periodic": false}}},
{addRegion: {name: "sp", type: "SPRegion", params: {columnCount: 50, learningMode: 1}}},
{addRegion: {name: "tm", type: "TMRegion", params: {numberOfCols: 50, cellsPerColumn: 10, inputWidth: 50, learningMode: true}}},
{addLink: {src: "encoder1.encoded", dest: "sp.bottomUpIn"}},
{addLink: {src: "encoder2.encoded", dest: "sp.bottomUpIn"}},
{addLink: {src: "sp.bottomUpOut", dest: "tm.bottomUpIn"}}
]}"""
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
print(region.getParameters())
vis = Vis()
vis.run()
value = 0
while True:
for enc in encoders:
enc.setParameterReal64("sensedValue", value)
value+=1
if value >= 100:
value = 0
network.run(1)
vis.setRegionData(encoders,spRegion, tmRegion)
# This draws the TMRegion output as a matrix with colors representing cell state using:
# active_cells_sdr = self.tmRegion.getOutputArray("activeCells").getSDR().dense
# predicted_active_cells_sdr = self.tmRegion.getOutputArray("predictedActiveCells").getSDR().dense
# predicted_cells_sdr = self.tmRegion.getOutputArray("predictiveCells").getSDR().dense
input()
if __name__ == '__main__':
main()