Hi All,
I am following the example as written in NetworkSetupExample.java (https://gist.github.com/cogmission/26700c261f3ad70c719b110b2e6d04a7) , I want to get anomaly score for the file rec-center-hourly.csv (found inside the resources of htm.java). In order to get anomaly scores i have added a method getExampleNetwork() in the PersistenceAPITest.java and adjust its headers as given below.
private Network getExampleNetwork() {
// This is the loop for inputting data into the network. This could be in another class, process, or thread
though
Parameters p = NetworkTestHarness.getParameters().copy();
p = p.union(NetworkTestHarness.getDayDemoTestEncoderParams());
p.set(KEY.RANDOM, new FastRandom(42));
p.set(KEY.INFERRED_FIELDS, getInferredFieldsMap("consumption", SDRClassifier.class));
Sensor<ObservableSensor<String[]>> sensor = Sensor.create(
ObservableSensor::create, SensorParams.create(Keys::obs, new Object[] {"name",
PublisherSupplier.builder()
.addHeader("timestamp,consumption") // The "headers" are the titles of your comma separated fields; (could be "timestamp,consumption,location" for 3 fields)
.addHeader("datetime,float") // The "Data Type" of the field (see FieldMetaTypes) (could be "datetime,float,geo" for 3 field types corresponding to above)
.addHeader("T,B").build() })); // Special flag. "B" means Blank (see Tests for other examples)
Network network = Network.create("test network", p).add(Network.createRegion("r1")
.add(Network.createLayer("1", p)
.alterParameter(KEY.AUTO_CLASSIFY, true) // <--- Remove this line if doing anomalies and not predictions
.add(Anomaly.create()) // <--- Remove this line if doing predictions and not anomalies
.add(new TemporalMemory())
.add(new SpatialPooler())
.add(sensor)));
return network;
}
And then i have added a test for using this network to get the anomaly score as follow,
@Test
public void setupNetwork() throws FileNotFoundException, IOException {
PrintWriter writer = new PrintWriter("/home/usamafurqan/anomalyscore.txt", "UTF-8");
// Call your network creation method
Network network = getExampleNetwork();
// Subscribes and receives Network Output
network.observe().subscribe(new Observer<Inference>() {
@Override public void onCompleted() { /* Any finishing touches after Network is finished */ }
@Override public void onError(Throwable e) { /* Handle your errors here */ }
@Override public void onNext(Inference inf) {
/* This is the OUTPUT of the network after each input has been "reacted" to. */
writer.println("" + inf.getRecordNum() + ", " + inf.getAnomalyScore());
}
});
Publisher pub = network.getPublisher();
/////////////////////////////////////////////////////////
// Network must be "started" when using a Publisher //
/////////////////////////////////////////////////////////
network.start();
// there should be only one thread pushing data to the network.
String file = "/home/usamafurqan/Desktop/rec-center-hourly.csv";
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String line;
while ((line = br.readLine()) != null) {
// process the line.
pub.onNext(line);
}
}
writer.close();
//while(data.hasNext()) {
// pub.onNext("your,comma-separated,data");
// Sometimes you are entering more than one dataset or group of unrelated data, you will want
// to reset inbetween so the HTM doesn't learn the transistion to the new group.
// network.reset(); //<--- If all your data is related, remove this line
//}
}
For line by line input data stream i have copied the file in another directory and remove the header lines so that i should input only timestamp and float values.
But when i have started the tests the setupNetwork() test failed with the following error,
May be it is simple but due to lack of domain knowledge of inside HTM java programs i am badly stuck,
Any idea how can i resolve this error?
Regards,
@Usama_Furqan