Hello NuPIC,
I'm trying to incorporate anomaly likelihood in hotgym anomaly tutorial
using modified Subutai example [1]. Here is my code snippet for running
model:
for row in csvReader:
# ipdb.set_trace()
col1 = datetime.datetime.strptime(row[0], DATE_FORMAT) # timestamp
col2 = row[1] #
consumption
result = model.run({
"timestamp": col1,
"kw_energy_consumption": float(col2)
})
shifted_result = shifter.shift(result)
col3 = result.inferences["multiStepBestPredictions"][predictionSteps]
col4 =
shifted_result.inferences["multiStepBestPredictions"][predictionSteps]
col5 = result.inferences['anomalyScore']
# Compute the Anomaly Likelihood
likelihood = anomalyLikelihood.anomalyProbability(col2, col5, col1)
logLikelihood = anomalyLikelihood.computeLogLikelihood(likelihood)
# write to csv
# datetime;consumption;prediction;shifted_prediction;anomaly_score;
row = [col1, col2, col3, col4, col5, likelihood, logLikelihood]
csvWriter.writerow(row)
if Verbose:
if (counter % 100 == 0):
print "Line %i has been written to %s" % (counter, outputFile)
print ';'.join(str(v) for v in row)
print
"################################################################"
if VeryVerbose:
if (counter % 100 == 0):
print "Line %i has been written to %s" % (counter, outputFile)
print result
print
"################################################################"
counter += 1
inputFH.close()
outputFH.close()
Above codes ends up with "TypeError: cannot perform reduce with flexible
type"
Last three rows that are writtent to output CSV are:
2010-07-26
21:00:00,35.8,4.887570520503047,44.76003339041138,0.025000000000000001,0.5,0.0301029996658834
2010-07-26
22:00:00,5.1,15.743889021255345,4.887570520503047,0.050000000000000003,0.5,0.0301029996658834
2010-07-26
23:00:00,4.9,15.743889021255345,15.743889021255345,0.050000000000000003,0.5,0.0301029996658834
Input csv is same as in hotgym anomaly tuorial. Here is snipet around
the location where error occurres
7/26/10 21:00,35.8
7/26/10 22:00,5.1
7/26/10 23:00,4.9
7/27/10 0:00,21.6
7/27/10 1:00,15.6
7/27/10 2:00,4.8
Values causing error passed to anomalyLikelihood.anomalyProbability
(founded via debugger):
ipdb> col2
'21.6'
ipdb> col5
0.0
ipdb> col1
datetime.datetime(2010, 7, 27, 0, 0)
PS: As you can see I am using both shifted and unshifted inferences
(col3 and col4). Should I pass anomalyScore from (un)shifted to
anomalyProbability?
PPS: I've not found any anomalyProbability() specification so I'm
passing arguments as I've seen in Matt or Subutai codes, is this OK?
Thank you
[1]
https://github.com/subutai/nupic.subutai/blob/master/run_anomaly/run_anomaly.py