org.numenta.nupic.network.Inference Java Examples
The following examples show how to use
org.numenta.nupic.network.Inference.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractHTMInferenceOperator.java From flink-htm with GNU Affero General Public License v3.0 | 6 votes |
protected void processInput(Network network, IN record, long timestamp) throws Exception { if(userFunction.reset(record)) { network.reset(); LOG.debug("network reset"); } Object input = convertToInput(record, timestamp); Inference inference = network.computeImmediate(input); if(inference != null) { NetworkInference outputInference = NetworkInference.fromInference(inference); StreamRecord<Tuple2<IN,NetworkInference>> streamRecord = new StreamRecord<>( new Tuple2<>(record, outputInference), timestamp); output.collect(streamRecord); } }
Example #2
Source File: StrictHackathonAlgorithm.java From htm.java-examples with GNU Affero General Public License v3.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void listenToNetwork(Network network) { if(network == null) { throw new IllegalArgumentException("Cannot listen to null Network."); } this.htmNetwork = network; network.observe().subscribe(new Subscriber<Inference>() { @Override public void onCompleted() {} @Override public void onError(Throwable e) {} @Override public void onNext(Inference t) { currentPrediction = subsample( SDR.cellsAsColumnIndices(t.getPredictiveCells(), cellsPerColumn)); semaphore.release(); } }); this.cellsPerColumn = htmNetwork.getHead().getTail().getConnections().getCellsPerColumn(); }
Example #3
Source File: NetworkInference.java From flink-htm with GNU Affero General Public License v3.0 | 5 votes |
public static NetworkInference fromInference(Inference i) { Map<String, Classification<Object>> classifications = new HashMap<>(); for (String field : i.getClassifiers().keys()) { classifications.put(field, i.getClassification(field)); } return new NetworkInference(i.getAnomalyScore(), classifications); }
Example #4
Source File: NetworkAPIDemo.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
/** * Primitive file appender for collecting output. This just demonstrates how to use * {@link Subscriber#onNext(Object)} to accomplish some work. * * @param infer The {@link Inference} object produced by the Network * @param classifierField The field we use in this demo for anomaly computing. */ private void writeToFile(Inference infer, String classifierField) { try { double newPrediction; if(null != infer.getClassification(classifierField).getMostProbableValue(1)) { newPrediction = (Double)infer.getClassification(classifierField).getMostProbableValue(1); } else { newPrediction = predictedValue; } if(infer.getRecordNum() > 0) { double actual = (Double)infer.getClassifierInput() .get(classifierField).get("inputValue"); double error = Math.abs(predictedValue - actual); StringBuilder sb = new StringBuilder() .append(infer.getRecordNum()).append(", ") //.append("classifier input=") .append(String.format("%3.2f", actual)).append(", ") //.append("prediction= ") .append(String.format("%3.2f", predictedValue)).append(", ") .append(String.format("%3.2f", error)).append(", ") //.append("anomaly score=") .append(infer.getAnomalyScore()); pw.println(sb.toString()); pw.flush(); System.out.println(sb.toString()); } else { } predictedValue = newPrediction; }catch(Exception e) { e.printStackTrace(); pw.flush(); } }
Example #5
Source File: SerializerCoreTest.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Test public void testSerializeDeSerialize() { final List<Inference> callVerify = new ArrayList<>(); SerializerCore serializer = Persistence.get().serializer(); Inference inf = new ManualInput() { @SuppressWarnings("unchecked") @Override public <T> T postDeSerialize(T i) { Inference retVal = (Inference)super.postDeSerialize(i); assertNotNull(retVal); assertTrue(retVal != i); // Ensure Objects not same assertTrue(retVal.equals(i)); // However they are still equal! callVerify.add(retVal); assertTrue(callVerify.size() == 1); return (T)retVal; } }; byte[] bytes = serializer.serialize(inf); assertNotNull(bytes); Inference serializedInf = serializer.deSerialize(bytes); assertNotNull(serializedInf); }
Example #6
Source File: NetworkAPIDemoTest.java From htm.java-examples with GNU Affero General Public License v3.0 | 4 votes |
@Test public void testGetSubscriber() { NetworkAPIDemo demo = new NetworkAPIDemo(Mode.MULTIREGION); Subscriber<Inference> s = demo.getSubscriber(); assertNotNull(s); }