Skip to content

Commit

Permalink
Revert "Example: use anomaly likelihood from TM"
Browse files Browse the repository at this point in the history
This reverts commit 9c5bd93.
  • Loading branch information
breznak committed Oct 7, 2019
1 parent 9c5bd93 commit 4d3d1f4
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions py/htm/examples/hotgym.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import random
import math

import htm
from htm.bindings.sdr import SDR, Metrics
from htm.encoders.rdse import RDSE, RDSE_Parameters
from htm.encoders.date import DateEncoder
from htm.bindings.algorithms import SpatialPooler
from htm.bindings.algorithms import TemporalMemory
from htm.algorithms.anomaly_likelihood import AnomalyLikelihood
from htm.bindings.algorithms import Predictor

_EXAMPLE_DIR = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -109,17 +109,25 @@ def main(parameters=default_parameters, argv=None, verbose=True):
permanenceDecrement = tmParams["permanenceDec"],
predictedSegmentDecrement = 0.0,
maxSegmentsPerCell = tmParams["maxSegmentsPerCell"],
maxSynapsesPerSegment = tmParams["maxSynapsesPerSegment"],
anomalyMode = htm.bindings.algorithms.ANMode.LIKELIHOOD,
maxSynapsesPerSegment = tmParams["maxSynapsesPerSegment"]
)
tm_info = Metrics( [tm.numberOfCells()], 999999999 )


# setup likelihood, these settings are used in NAB
anParams = parameters["anomaly"]["likelihood"]
probationaryPeriod = int(math.floor(float(anParams["probationaryPct"])*len(records)))
learningPeriod = int(math.floor(probationaryPeriod / 2.0))
anomaly_history = AnomalyLikelihood(learningPeriod= learningPeriod,
estimationSamples= probationaryPeriod - learningPeriod,
reestimationPeriod= anParams["reestimationPeriod"])

predictor = Predictor( steps=[1, 5], alpha=parameters["predictor"]['sdrc_alpha'] )
predictor_resolution = 1

# Iterate through every datum in the dataset, record the inputs & outputs.
inputs = []
anomaly = []
anomalyProb = []
predictions = {1: [], 5: []}
for count, record in enumerate(records):

Expand Down Expand Up @@ -157,7 +165,10 @@ def main(parameters=default_parameters, argv=None, verbose=True):
predictions[n].append( np.argmax( pdf[n] ) * predictor_resolution )
else:
predictions[n].append(float('nan'))

anomalyLikelihood = anomaly_history.anomalyProbability( consumption, tm.anomaly )
anomaly.append( tm.anomaly )
anomalyProb.append( anomalyLikelihood )

predictor.learn(count, tm.getActiveCells(), int(consumption / predictor_resolution))

Expand Down

0 comments on commit 4d3d1f4

Please sign in to comment.