TM output represented as SDR for clustering on SDRs

I wanted to implement a clustering algorithm on the SDRs output by the Temporal Memory layer. So essentially looking for patterns in the output SDRs (unsupervised). How can I extract these SDRs out from the TM layer ?

Hi @virisha , welcome!

If you’re using the ‘ModelFactory’ method in NuPIC to generate models, you can extract the state of the TM from the TM object held within the model objects, like so:

from nupic.frameworks.opf.model_factory import ModelFactory

model = ModelFactory.create(modelConfig=params["modelConfig"])
model.enableLearning()
model.enableInference(field_modelparams["inferenceArgs"])
...
for new data in stream:
    modelInput = {'field_x': data}
    resultObj = model.run(modelInput)
    TM_obj = model._getTPRegion().getSelf().getAlgorithmInstance()
    TM_CellsCurrentActiveStates = TM_obj._getActiveState()        
    TM_CellsPredStates = TM_obj.getPredictedState()