Anomaly Detection

Several relevant threads, but posting in this one because it seems be most relevant.

Using columnForCell seems to only work for a single input. You can get all the columns using mapCellsToColumns().keys()

I’ve posted the TM and anomaly section of my code (based on the algorithms quickstart example) below. Only problem is that it doesn’t match the OPF results with the same (I think) parameters and input. The OPF anomaly score calculation is a little more opaque since it is under the hood, so to speak.

Can someone confirm that this is the right way of using Anomaly.compute()? Or any thoughts on why results might be different for OPF vs this code?

  # Execute Temporal Memory algorithm over active mini-columns.
  if stillLearning==True:
    tm.compute(spActiveColumnIndices, learn=True)
  else:
    tm.compute(spActiveColumnIndices, learn=False)
  tmActiveCells = tm.getActiveCells()
  tmPredictiveCells = tm.getPredictiveCells()
  tmActiveColumnIndices = tm.mapCellsToColumns(tmActiveCells).keys()
  this_tmPredictiveColumnIndices = tm.mapCellsToColumns(tmPredictiveCells).keys()
  
  if counter==1:
    # For the first iteration, there are no T-1 predictions
    last_tmPredictiveColumnIndices = this_tmPredictiveColumnIndices
        
  # Get the anomaly score, likelihood, and log-likelihood for this input
  # Make sure to use the shifted predictive cells since the predictive
  # cells for T should be compared to the active cells for T+1
  anomalyScore = anom.compute(tmActiveColumnIndices,last_tmPredictiveColumnIndices,timestamp=counter)
  anomalyLikelihood = likelihoodHelper.anomalyProbability(sdr,anomalyScore,counter)
  anomalyLogLikelihood = AnomalyLikelihood.computeLogLikelihood(anomalyLikelihood)      
  
  # Store the current predictive cells to use in the next timestep
  last_tmPredictiveColumnIndices = this_tmPredictiveColumnIndices
1 Like