public void TestAutomaticClose() { Parameters p = NetworkTestHarness.GetParameters(); p = p.Union(NetworkTestHarness.GetDayDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42)); Net.Network.Network n = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add((MultiEncoder)MultiEncoder.GetBuilder().Name("").Build()))); //.Close(); // Not necessary due to implicit call during start() or compute() Region r1 = n.Lookup("r1"); r1.Start(); Assert.IsTrue(r1.IsClosed()); try { r1.Add(Net.Network.Network.CreateLayer <IInference>("5", p)); Assert.Fail(); } catch (Exception e) { Assert.IsTrue(e.GetType().IsAssignableFrom(typeof(InvalidOperationException))); Assert.AreEqual("Cannot add Layers when Region has already been closed.", e.Message); } }
public void TestEncoderPassesUpToTopLayer() { Parameters p = NetworkTestHarness.GetParameters(); p = p.Union(NetworkTestHarness.GetDayDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42)); p.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_MODE, Anomaly.Mode.PURE); Net.Network.Network n = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("1", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true)) .Add(Net.Network.Network.CreateLayer <IInference>("2", p) .Add(Anomaly.Create(p))) .Add(Net.Network.Network.CreateLayer <IInference>("3", p) .Add(new TemporalMemory())) .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add(new SpatialPooler()) .Add((MultiEncoder)MultiEncoder.GetBuilder().Name("").Build()))); Region r1 = n.Lookup("r1"); r1.Connect("1", "2").Connect("2", "3").Connect("3", "4"); Assert.IsNotNull(r1.Lookup("1").GetEncoder()); }
public void TestAdd() { Parameters p = NetworkTestHarness.GetParameters(); p = p.Union(NetworkTestHarness.GetDayDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42)); Net.Network.Network n = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add((MultiEncoder)MultiEncoder.GetBuilder().Name("").Build()))); Region r1 = n.Lookup("r1"); ILayer layer4 = r1.Lookup("4"); Assert.IsNotNull(layer4); Assert.AreEqual("r1:4", layer4.GetName()); try { r1.Add(Net.Network.Network.CreateLayer <IInference>("4", p)); Assert.Fail(); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(InvalidOperationException)); Assert.AreEqual("A Layer with the name: 4 has already been added to this Region.", e.Message); } }
/** * Called internally during construction to build the encoders * needed to process the configured field types. */ private void CreateEncoder() { encoder = (MultiEncoder)MultiEncoder.GetBuilder().Name("MultiEncoder").Build(); Map <string, Map <string, object> > encoderSettings; if (localParameters != null && (encoderSettings = (Map <string, Map <string, object> >)localParameters.GetParameterByKey(Parameters.KEY.FIELD_ENCODING_MAP)) != null && encoderSettings.Any()) { InitEncoders(encoderSettings); MakeIndexEncoderMap(); } }
public void TestIsLearn() { Parameters p = NetworkTestHarness.GetParameters().Copy(); p = p.Union(NetworkTestHarness.GetDayDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.COLUMN_DIMENSIONS, new int[] { 30 }); p.SetParameterByKey(Parameters.KEY.SYN_PERM_INACTIVE_DEC, 0.1); p.SetParameterByKey(Parameters.KEY.SYN_PERM_ACTIVE_INC, 0.1); p.SetParameterByKey(Parameters.KEY.SYN_PERM_TRIM_THRESHOLD, 0.05); p.SetParameterByKey(Parameters.KEY.SYN_PERM_CONNECTED, 0.4); p.SetParameterByKey(Parameters.KEY.MAX_BOOST, 10.0); p.SetParameterByKey(Parameters.KEY.DUTY_CYCLE_PERIOD, 7); p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42)); p.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_MODE, Anomaly.Mode.PURE); Net.Network.Network n = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("1", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true)) .Add(Net.Network.Network.CreateLayer <IInference>("2", p) .Add(Anomaly.Create(p))) .Add(Net.Network.Network.CreateLayer <IInference>("3", p) .Add(new TemporalMemory())) .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add(new SpatialPooler()) .Add((MultiEncoder)MultiEncoder.GetBuilder().Name("").Build())) .Connect("1", "2") .Connect("2", "3") .Connect("3", "4")); n.Lookup("r1").Close(); n.SetLearn(false); Assert.IsFalse(n.IsLearn()); Region r1 = n.Lookup("r1"); Assert.IsFalse(n.IsLearn()); ILayer layer = r1.GetTail(); Assert.IsFalse(layer.SetIsLearn()); while (layer.GetNext() != null) { layer = layer.GetNext(); Assert.IsFalse(layer.SetIsLearn()); } }
public void TestInputDimensionsAutomaticallyInferredFromEncoderWidth() { Parameters p = NetworkTestHarness.GetParameters(); p = p.Union(NetworkTestHarness.GetDayDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42)); // Purposefully set this to be wrong p.SetParameterByKey(Parameters.KEY.INPUT_DIMENSIONS, new int[] { 40, 40 }); Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add((MultiEncoder)MultiEncoder.GetBuilder().Name("").Build())) .Close()); // Should correct the above ( {40,40} ) to have only one dimension whose width is 8 ( {8} ) Assert.IsTrue(Arrays.AreEqual(new int[] { 8 }, (int[])p.GetParameterByKey(Parameters.KEY.INPUT_DIMENSIONS))); }
public void TestMultiLayerAssemblyNoSensor() { Parameters p = NetworkTestHarness.GetParameters().Copy(); p = p.Union(NetworkTestHarness.GetDayDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.COLUMN_DIMENSIONS, new int[] { 30 }); p.SetParameterByKey(Parameters.KEY.SYN_PERM_INACTIVE_DEC, 0.1); p.SetParameterByKey(Parameters.KEY.SYN_PERM_ACTIVE_INC, 0.1); p.SetParameterByKey(Parameters.KEY.SYN_PERM_TRIM_THRESHOLD, 0.05); p.SetParameterByKey(Parameters.KEY.SYN_PERM_CONNECTED, 0.4); p.SetParameterByKey(Parameters.KEY.MAX_BOOST, 10.0); p.SetParameterByKey(Parameters.KEY.DUTY_CYCLE_PERIOD, 7); p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42)); p.SetParameterByKey(Parameters.KEY.ANOMALY_KEY_MODE, Anomaly.Mode.PURE); Net.Network.Network n = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("1", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true)) .Add(Net.Network.Network.CreateLayer <IInference>("2", p) .Add(Anomaly.Create(p))) .Add(Net.Network.Network.CreateLayer <IInference>("3", p) .Add(new TemporalMemory())) .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add(new SpatialPooler()) .Add((MultiEncoder)MultiEncoder.GetBuilder().Name("").Build())) .Connect("1", "2") .Connect("2", "3") .Connect("3", "4")); Region r1 = n.Lookup("r1"); r1.Lookup("3").Using(r1.Lookup("4").GetConnections()); // How to share Connections object between Layers //r1.Observe().Subscribe(new Subscriber<Inference>() //{ // public void onCompleted() { } // public void onError(Throwable e) { e.printStackTrace(); } // public void onNext(Inference i) // { // // UNCOMMENT TO VIEW STABILIZATION OF PREDICTED FIELDS // System.Out.println("Day: " + r1.GetInput() + " - predictive cells: " + i.GetPreviousPredictiveCells() + // " - " + Arrays.toString(i.GetFeedForwardSparseActives()) + " - " + // ((int)Math.Rint(((Number)i.GetClassification("dayOfWeek").GetMostProbableValue(1)).doubleValue()))); // } //}); const int NUM_CYCLES = 400; const int INPUT_GROUP_COUNT = 7; // Days of Week Map <String, Object> multiInput = new Map <string, object>(); for (int i = 0; i < NUM_CYCLES; i++) { for (double j = 0; j < INPUT_GROUP_COUNT; j++) { multiInput.Add("dayOfWeek", j); r1.Compute(multiInput); } r1.Reset(); } r1.SetLearn(false); r1.Reset(); // Test that we get proper output after prediction stabilization //r1.Observe().Subscribe(new Subscriber<Inference>() //{ // public void onCompleted() { } // public void onError(Throwable e) { e.printStackTrace(); } // public void onNext(Inference i) // { // int nextDay = ((int)Math.Rint(((Number)i.GetClassification("dayOfWeek").GetMostProbableValue(1)).doubleValue())); // Assert.AreEqual(6, nextDay); // } //}); multiInput.Add("dayOfWeek", 5.0); r1.Compute(multiInput); }