HTM.java network setup for making predictions


#1

I am trying to setup a HTM.java network in order to find out whether I can use it in some practical applications.
So, for now, my goal is to use a scalar/ category encoder and then feed the network with some repetitive data to make sure that the network is able to learn the sequence.

Here is my setup:

Publisher:
this.publisher = Publisher.builder()
.addHeader(“alarm”)
.addHeader(“float”)
.addHeader(“B”)
.build();

Network setup:
Network.create(“Camera Analytics Network”, p)
.add(Network.createRegion(“Region 1”)
.add(Network.createLayer(“Layer 2/3”, p)
.alterParameter(KEY.AUTO_CLASSIFY, Boolean.TRUE)
.add(Anomaly.create())
.add(new TemporalMemory())
.add(new SpatialPooler())
.add(Sensor.create(ObservableSensor::create,
SensorParams.create(
Keys::obs, new Object[] { “Camera Analytics Publisher”, this.publisher })))));

Scalar encoding parameters:
fieldEncodings = setupMap(
null,
500,
21,
1, 1000, 0, 0, Boolean.FALSE, Boolean.FALSE, Boolean.FALSE,
“alarm”, “float”, “ScalarEncoder”);

The rest of HTM parameters are default the parameters.

So far so good!

Now, when I am feeding in with the values: 100.0, 200.0, … 1000.0 in a loop,
after a while I get the following result:

Record Number: 810, input Value: 100.0, anomaly Score: 0.0, predicted value: 1000.0
Record Number: 811, input Value: 200.0, anomaly Score: 0.0, predicted value: 1000.0
Record Number: 812, input Value: 300.0, anomaly Score: 0.0, predicted value: 1000.0
Record Number: 813, input Value: 400.0, anomaly Score: 0.0, predicted value: 1000.0
Record Number: 814, input Value: 500.0, anomaly Score: 0.0, predicted value: 1000.0
Record Number: 815, input Value: 600.0, anomaly Score: 0.0, predicted value: 1000.0
Record Number: 816, input Value: 700.0, anomaly Score: 0.0, predicted value: 1000.0
Record Number: 817, input Value: 800.0, anomaly Score: 0.0, predicted value: 1000.0
Record Number: 818, input Value: 900.0, anomaly Score: 0.0, predicted value: 800.0
Record Number: 819, input Value: 1000.0, anomaly Score: 0.0, predicted value: 1000.0

The anomaly score looks good but the prediced values stay more or less constant, around 1000.0

I found a similar behaviour when I used the SDRCategoryEncoder. After learning, the last value in the list is the predicted value.

Any idea what is wrong with this setup?


#2

Hi @pguler,

Welcome! …and thank you for using HTM.Java!

First can I ask how are you pulling out the predicted value? What does your print out string look like?


#3

Hi @cogmission

Here is my string builder
StringBuilder sb = new StringBuilder()
.append("Record Number: “)
.append(i.getRecordNum()).append(”, input Value: “)
.append(inputValue)
.append(”, anomaly Score: “)
.append(i.getAnomalyScore())
.append(”, predicted value: ")
.append(i.getClassification(“alarm”).getMostProbableValue(1));
System.out.println(sb.toString());

i = Inference
inputValue: double inputValue = (Double)i.getClassifierInput()
.get(“alarm”).get(“inputValue”);

Thank you,
Pavel Guler


#4

Hi @pguler,

Thank you for providing those details of your setup.

These are: min, max, radius, resolution, is periodic, is clipped, is forced …

Right off, your resolution seems off. Since there are 100 increments per bucket, you could try putting 100 here.
making it: ```1, 1000, 0, 100, …

Also you could try a radius of “50” to give it perfect contiguous overlap (experiment with this one).

I am not the most experienced “user” of NuPIC, so I will have to play with it and get back to you. You might also try printing out the parameter settings at the end of your run with ```connections. printParameters()`` - which could be helpful to look at…

Also, if anyone else from Numenta has any ideas please chime in?

In the meantime:
1.) You could try using the configurations used for the DayOfWeek examples which are used quite frequently for testing (see the tests and examples code) - because the inputs are very similar (small limited cyclical set).
2.) Try using the RandomDistributedScalarEncoder which configures w and n automatically. (See the tests which call the setup of the encoder parameters for the RDSE)

…again, I’m going to try running this myself - but I won’t be able to get back to you with my results immediately, but sometime today…

Cheers,
David


Feedback on network setup for anomaly detection
#5

I tried the following configuration but no improvement.

{
Spatial: {
learn:true
inputDimensions:[64]
potentialRadius:16
potentialPct:0.5
globalInhibition:false
inhibitionRadius:0
localAreaDensity:-1.0
numActiveColumnsPerInhArea:10.0
stimulusThreshold:0.0
synPermInactiveDec:0.01
synPermActiveInc:0.1
synPermConnected:0.1
synPermBelowStimulusInc:0.01
synPermTrimThreshold:0.5
minPctOverlapDutyCycles:0.001
minPctActiveDutyCycles:0.001
dutyCyclePeriod:1000
maxBoost:10.0
spVerbosity:0
}
Temporal: {
columnDimensions:[2048]
cellsPerColumn:32
activationThreshold:13
learningRadius:2048
minThreshold:10
maxNewSynapseCount:20
initialPermanence:0.21
connectedPermanence:0.5
permanenceIncrement:0.1
permanenceDecrement:0.1
tmVerbosity:0
}
Other: {
random:org.numenta.nupic.util.MersenneTwister@2ed2d9cb
seed:42
n:500
w:21
minVal:0.0
maxVal:1000.0
radius:21.0
resolution:1.0
periodic:false
clipInput:true
forced:false
fieldName:UNSET
fieldType:int
encoderType:ScalarEncoder
fieldEncodings:{alarm={clipInput=false, maxVal=1000.0, fieldName=alarm, minVal=1.0, periodic=false, forced=false, w=21, radius=50.0, resolution=100.0, fieldType=float, n=500, encoderType=ScalarEncoder}}
hasClassifiers:false
}
}


#6

resolution should be 100, I believe…


#7

Not sure which one is used.
I set it in

fieldEncodings:{alarm={clipInput=false, maxVal=1000.0, fieldName=alarm, minVal=1.0, periodic=false, forced=false, w=21, radius=50.0, resolution=100.0, fieldType=float, n=500, encoderType=ScalarEncoder}}


#8

Also, the DayOfWeek examples use smaller column/cell settings and different parameters - I would try the params setup for those: DayEncoding setup <== here instead of “8” use 10 with a resolution of 100??

Give that a try…

I will experiment myself later…

Also, please try asking this question on the NuPIC forum also, because HTM.Java is exactly equivalent and you may get better “usage” responses…


#9

Here is another experiment, but this time I am using SDRCategoryEncoder because it suits better my application.

There are three strings which are fed into the network in a fixed order:

“Dark Side Of The Moon”
“Blowing In The Wind”
“The Piper Of The Gates Of Dawn”

The result is the same as with scalar encoder the network predicts the same value which is the last in the list:

Record Number: 984, input Value: Dark Side Of The Moon, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 985, input Value: Blowing In The Wind, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 986, input Value: The Piper Of The Gates Of Dawn, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 987, input Value: Dark Side Of The Moon, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 988, input Value: Blowing In The Wind, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 989, input Value: The Piper Of The Gates Of Dawn, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 990, input Value: Dark Side Of The Moon, anomaly Score: 1.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 991, input Value: Blowing In The Wind, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 992, input Value: The Piper Of The Gates Of Dawn, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 993, input Value: Dark Side Of The Moon, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 994, input Value: Blowing In The Wind, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 995, input Value: The Piper Of The Gates Of Dawn, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 996, input Value: Dark Side Of The Moon, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 997, input Value: Blowing In The Wind, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 998, input Value: The Piper Of The Gates Of Dawn, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn
Record Number: 999, input Value: Dark Side Of The Moon, anomaly Score: 0.0, predicted value: The Piper Of The Gates Of Dawn

Here are the configuration parameters:

{
Spatial: {
learn:true
inputDimensions:[64]
potentialRadius:16
potentialPct:0.5
globalInhibition:false
inhibitionRadius:0
localAreaDensity:-1.0
numActiveColumnsPerInhArea:10.0
stimulusThreshold:0.0
synPermInactiveDec:0.01
synPermActiveInc:0.1
synPermConnected:0.1
synPermBelowStimulusInc:0.01
synPermTrimThreshold:0.5
minPctOverlapDutyCycles:0.001
minPctActiveDutyCycles:0.001
dutyCyclePeriod:1000
maxBoost:10.0
spVerbosity:0
}
Temporal: {
columnDimensions:[2048]
cellsPerColumn:32
activationThreshold:13
learningRadius:2048
minThreshold:10
maxNewSynapseCount:20
initialPermanence:0.21
connectedPermanence:0.5
permanenceIncrement:0.1
permanenceDecrement:0.1
tmVerbosity:0
}
Other: {
random:org.numenta.nupic.util.MersenneTwister@2ed2d9cb
seed:42
n:500
w:21
minVal:0.0
maxVal:1000.0
radius:21.0
resolution:1.0
periodic:false
clipInput:false
forced:false
fieldName:UNSET
fieldType:int
encoderType:ScalarEncoder
fieldEncodings:{alarm={clipInput=false, maxVal=0.0, fieldName=alarm, minVal=0.0, periodic=false, forced=false, w=21, radius=0.0, resolution=0.0, fieldType=string, n=500, encoderType=SDRCategoryEncoder}}
hasClassifiers:false
}
}

I will ask contact NuPIC forum as you suggested.

Thank you for your time,
Pavel Guler