How to correct calculate anomaly score in TM?

Hello!

Im seen that in all graphics with anomaly score values lay in 0.0-1.0 range. For example:

Please, can you explain proper way to calculate anomaly score?

In my implementation i sometimes get values greater than one, it seems to me that this is not correct:

learn() {
  this.anomalyScore = 0
  for (const column of this.columns) {
    if (this.isColumnActive(column)) {
      if (this.isColumnPredicted(column)) {
        this.activatePredictedColumn(column)
      } else {
        this.burstColumn(column)
        ++this.anomalyScore
      }
    } else {
      if (this.isColumnPredicted(column)) {
        this.punishWrongPredictions(column)
        ++this.anomalyScore
      }
    }
  }
  this.anomalyScore /= this.spatialPooler.getMaxActiveColumns()
  this.anomalyScore = Math.min(this.anomalyScore, 1.0) // sometimes this.anomalyScore > 1.0
  console.log('anomaly score', this.anomalyScore)
}

The anomaly score is simply the proportion of all columns which burst at the current time step.

So you can calculate it simply as:

(number of predicted active columns / number of active columns)

OR

1 - (number of bursted active columns / number of active columns)

1 Like