public void TestProcessReset() { Header header = new Header(GetTestHeaderOff()); List <string[]> lines = GetLines(ResourceLocator.Path(typeof(Resources), "rec-center-hourly-4period.csv")); foreach (string[] line in lines) { header.Process(line); Assert.IsFalse(header.IsReset()); Assert.IsTrue(header.IsLearn()); } header = new Header(GetTestHeaderReset()); lines = GetLines(ResourceLocator.Path(typeof(Resources), "rec-center-hourly-4reset.csv")); int idx = 0; foreach (string[] line in lines) { string[] shifted = new string[line.Length + 1]; Array.Copy(line, 0, shifted, 1, line.Length); shifted[0] = idx.ToString(); header.Process(shifted); if (line[2].Equals("1")) { Assert.IsTrue(header.IsReset()); } else { Assert.IsFalse(header.IsReset()); } idx++; } }
private IObservable <string> makeFileObservable() { FileInfo f = new FileInfo(ResourceLocator.Path(typeof(Resources), "rec-center-hourly.csv")); try { List <string> arr = new List <string>(); using (StreamReader sr = new StreamReader(f.OpenRead())) { string line = null; while (!sr.EndOfStream) { arr.Add(sr.ReadLine()); } } //Observable <?> o = Observable.from(Files.lines(f.toPath(), Charset.forName("UTF-8")).toArray()); return(arr.ToObservable()); } catch (Exception e) { Console.WriteLine(e); } return(null); }
public void TestProcessCategories() { object[] n = { "some name", ResourceLocator.Path(typeof(Resources), "rec-center-hourly-4period-cat.csv") }; Sensor <FileInfo> sensor2 = Sensor <FileInfo> .Create( FileSensor.Create, SensorParams.Create(SensorParams.Keys.Path, n)); Header header = new Header(sensor2.GetMetaInfo()); Assert.AreEqual("[T, B, C]", Arrays.ToString(header.GetFlags().ToArray())); }
public void TestCategoryEncoderCreation() { Sensor <FileInfo> sensor = Sensor <FileInfo> .Create( FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "rec-center-hourly-4period-cat.Csv"))); // Cast the ValueList to the more complex type (Header) HTMSensor <FileInfo> htmSensor = (HTMSensor <FileInfo>)sensor; Header meta = (Header)htmSensor.GetMetaInfo(); Assert.IsTrue(meta.GetFieldTypes().TrueForAll( l => l.Equals(FieldMetaType.DateTime) || l.Equals(FieldMetaType.Float) || l.Equals(FieldMetaType.List))); Assert.IsTrue(meta.GetFieldNames().TrueForAll( l => l.Equals("timestamp") || l.Equals("consumption") || l.Equals("type"))); Assert.IsTrue(meta.GetFlags().TrueForAll( l => l.Equals(SensorFlags.T) || l.Equals(SensorFlags.B) || l.Equals(SensorFlags.C))); // Set the parameters on the sensor. // This enables it to auto-configure itself; a step which will // be done at the Region level. Encoder <object> multiEncoder = htmSensor.GetEncoder(); Assert.IsNotNull(multiEncoder); Assert.IsTrue(multiEncoder is MultiEncoder); // Set the Local parameters on the Sensor htmSensor.InitEncoder(GetCategoryEncoderParams()); List <EncoderTuple> encoders = multiEncoder.GetEncoders(multiEncoder); Assert.AreEqual(3, encoders.Count); DateEncoder dateEnc = (DateEncoder)encoders[1].GetEncoder(); SDRCategoryEncoder catEnc = (SDRCategoryEncoder)encoders[2].GetEncoder(); Assert.AreEqual("[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0]", Arrays.ToString(catEnc.Encode("ES"))); // Now test the encoding of an input row Map <string, object> d = new Map <string, object>(); d.Add("timestamp", dateEnc.Parse("7/12/10 13:10")); d.Add("consumption", 35.3); d.Add("type", "ES"); int[] output = multiEncoder.Encode(d); int[] expected = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0 }; Debug.WriteLine(Arrays.ToString(expected)); Debug.WriteLine(Arrays.ToString(output)); Assert.IsTrue(Arrays.AreEqual(expected, output)); }
public void TestSensorTerminalOperationDetection() { Sensor <FileInfo> sensor = Sensor <FileInfo> .Create( FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "rec-center-hourly-small.Csv"))); HTMSensor <FileInfo> htmSensor = (HTMSensor <FileInfo>)sensor; // We haven't done anything with the stream yet, so it should not be terminal Assert.IsFalse(htmSensor.IsTerminal()); ((BatchedCsvStream <string[]>)htmSensor.GetInputStream()).ForEach(l => Console.WriteLine(Arrays.ToString((string[])l))); // Should now be terminal after operating on the stream Assert.IsTrue(htmSensor.IsTerminal()); }
public void testMetaFormation_NO_HEADER_FLAGS() { Sensor <FileInfo> sensor = Sensor <FileInfo> .Create( FileSensor.Create, SensorParams.Create(SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "rec-center-hourly-small-noheaderflags.Csv"))); // Cast the ValueList to the more complex type (Header) Header meta = (Header)sensor.GetMetaInfo(); Assert.IsTrue(meta.GetFieldTypes().TrueForAll( l => l.Equals(FieldMetaType.DateTime) || l.Equals(FieldMetaType.Float))); Assert.IsTrue(meta.GetFieldNames().TrueForAll( l => l.Equals("timestamp") || l.Equals("consumption"))); Assert.IsTrue(meta.GetFlags().TrueForAll( l => l.Equals(SensorFlags.B))); }
public void TestSensorMultipleStreamCreation() { Sensor <FileInfo> sensor = Sensor <FileInfo> .Create( FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "rec-center-hourly-small.Csv"))); HTMSensor <FileInfo> htmSensor = (HTMSensor <FileInfo>)sensor; htmSensor.InitEncoder(GetTestEncoderParams()); // Ensure that the HTMSensor's output stream can be retrieved more than once. IStream <int[]> outputStream = htmSensor.GetOutputStream(); IStream <int[]> outputStream2 = htmSensor.GetOutputStream(); IStream <int[]> outputStream3 = htmSensor.GetOutputStream(); // Check to make sure above multiple retrieval doesn't flag the underlying stream as operated upon Assert.IsFalse(htmSensor.IsTerminal()); Assert.AreEqual(17, outputStream.Count()); //After the above we cannot request a new stream, so this will fail //however, the above streams that were already requested should be unaffected. Assert.IsTrue(htmSensor.IsTerminal(), "Terminal sensor stream expected"); try { //@SuppressWarnings("unused") IStream <int[]> outputStream4 = (Stream <int[]>)htmSensor.GetOutputStream(); Assert.Fail(); } catch (Exception e) { Assert.AreEqual("Stream is already \"terminal\" (operated upon or empty)", e.Message); } //These Streams were created before operating on a stream Assert.AreEqual(17, outputStream2.Count()); Assert.AreEqual(17, outputStream3.Count()); // Verify that different streams are retrieved. Assert.IsFalse(outputStream.GetHashCode() == outputStream2.GetHashCode()); Assert.IsFalse(outputStream2.GetHashCode() == outputStream3.GetHashCode()); }
public void TestHTMSensor_HotGym() { Object[] n = { "some name", ResourceLocator.Path("rec-center-hourly-small.csv") }; HTMSensor <FileInfo> sensor = (HTMSensor <FileInfo>) Sensor <FileInfo> .Create( FileSensor.Create, SensorParams.Create(SensorParams.Keys.Path, n)); sensor.InitEncoder(GetTestEncoderParams()); SerialConfig config = new SerialConfig("testHTMSensor_HotGym"); IPersistenceAPI api = Persistence.Get(config); byte[] bytes = api.Write(sensor); Assert.IsNotNull(bytes); Assert.IsTrue(bytes.Length > 0); HTMSensor <FileInfo> serializedSensor = api.Read <HTMSensor <FileInfo> >(bytes); bool b = serializedSensor.IsDeepEqual(sensor); DeepCompare(serializedSensor, sensor); Assert.IsTrue(b); }
public void TestInputIntegerArray() { Publisher manual = Publisher.GetBuilder() .AddHeader("sdr_in") .AddHeader("sarr") .AddHeader("B") .Build(); Sensor <ObservableSensor <string[]> > sensor = Sensor <ObservableSensor <string[]> > .Create( ObservableSensor <string[]> .Create, SensorParams.Create(SensorParams.Keys.Obs, new Object[] { "name", manual })); int i = 0; var t = new Task(() => { BatchedCsvStream <string[]> iStream = (BatchedCsvStream <string[]>)sensor.GetInputStream(); Stream <string[]> oStream = (Stream <string[]>)iStream._contentStream; Assert.AreEqual(2, ((string[])oStream.First()).Length); }); //(t = new Thread() { // int i = 0; // public void run() // { // assertEquals(2, ((String[])sensor.getInputStream().findFirst().get()).length); // } //}).start(); int[][] ia = getArrayFromFile(ResourceLocator.Path(typeof(Resources), "1_100.csv")); manual.OnNext(Arrays.ToString(ia[0]).Trim()); t.Start(); try { t.Wait(); } catch (Exception e) { Console.WriteLine(e); Assert.Fail(); } }
public void TestHTMSensor_DaysOfWeek() { Object[] n = { "some name", ResourceLocator.Path("days-of-week.csv") }; HTMSensor <FileInfo> sensor = (HTMSensor <FileInfo>) Sensor <FileInfo> .Create( FileSensor.Create, SensorParams.Create(SensorParams.Keys.Path, n)); Parameters p = GetParameters(); p = p.Union(NetworkTestHarness.GetDayDemoTestEncoderParams()); sensor.InitEncoder(p); SerialConfig config = new SerialConfig("testHTMSensor_DaysOfWeek", SerialConfig.SERIAL_TEST_DIR); IPersistenceAPI api = Persistence.Get(config); byte[] bytes = api.Write(sensor); HTMSensor <FileInfo> serializedSensor = api.Read <HTMSensor <FileInfo> >(bytes); bool b = serializedSensor.IsDeepEqual(sensor); DeepCompare(serializedSensor, sensor); Assert.IsTrue(b); }
public void TestFileSensorCreation() { object[] n = { "some name", ResourceLocator.Path(typeof(Resources), "rec-center-hourly.csv") }; SensorParams parms = SensorParams.Create(SensorParams.Keys.Path, n); Sensor <FileInfo> sensor = Sensor <FileInfo> .Create(FileSensor.Create, parms); Assert.IsNotNull(sensor); Assert.IsNotNull(sensor.GetSensorParams()); SensorParams sp = sensor.GetSensorParams(); Assert.AreEqual("some name", sp.Get("FILE")); Assert.AreEqual(null, sp.Get("NAME")); Assert.AreEqual(ResourceLocator.Path(typeof(Resources), "rec-center-hourly.csv"), sp.Get("PATH")); Sensor <FileInfo> sensor2 = Sensor <FileInfo> .Create(FileSensor.Create, SensorParams.Create(SensorParams.Keys.Path, n)); Assert.IsNotNull(sensor2); Assert.IsNotNull(sensor2.GetSensorParams()); sp = sensor2.GetSensorParams(); Assert.AreEqual("some name", sp.Get("FILE")); Assert.AreEqual(null, sp.Get("NAME")); Assert.AreEqual(ResourceLocator.Path(typeof(Resources), "rec-center-hourly.csv"), sp.Get("PATH")); }
public void TestInternalEncoderCreation() { Sensor <FileInfo> sensor = Sensor <FileInfo> .Create( FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "rec-center-hourly.Csv"))); // Cast the ValueList to the more complex type (Header) HTMSensor <FileInfo> htmSensor = (HTMSensor <FileInfo>)sensor; Header meta = (Header)htmSensor.GetMetaInfo(); Assert.IsTrue(meta.GetFieldTypes().TrueForAll( l => l.Equals(FieldMetaType.DateTime) || l.Equals(FieldMetaType.Float))); Assert.IsTrue(meta.GetFieldNames().TrueForAll( l => l.Equals("timestamp") || l.Equals("consumption"))); Assert.IsTrue(meta.GetFlags().TrueForAll( l => l.Equals(SensorFlags.T) || l.Equals(SensorFlags.B))); // Set the parameters on the sensor. // This enables it to auto-configure itself; a step which will // be done at the Region level. Encoder <object> multiEncoder = htmSensor.GetEncoder(); Assert.IsNotNull(multiEncoder); Assert.IsTrue(multiEncoder is MultiEncoder); // Set the Local parameters on the Sensor htmSensor.InitEncoder(GetTestEncoderParams()); List <EncoderTuple> encoders = multiEncoder.GetEncoders(multiEncoder); Assert.AreEqual(2, encoders.Count); // Test date specific encoder configuration // // All encoders in the MultiEncoder are accessed in a particular // order (the alphabetical order their corresponding fields are in), // so alphabetically "consumption" proceeds "timestamp" // so we need to ensure that the proper order is preserved (i.E. exists at index 1) DateEncoder dateEnc = (DateEncoder)encoders[1].GetEncoder(); try { dateEnc.ParseEncode("7/12/10 13:10"); dateEnc.ParseEncode("7/12/2010 13:10"); // Should fail here due to conflict with configured format dateEnc.ParseEncode("--13:10 7-12-10"); Assert.Fail(); } catch (Exception e) { Assert.IsInstanceOfType(e, typeof(FormatException)); //Assert.AreEqual("Invalid format: \"13:10 7/12/10\" is malformed at \":10 7/12/10\"", e.Message); } RandomDistributedScalarEncoder rdse = (RandomDistributedScalarEncoder)encoders[0].GetEncoder(); int[] encoding = rdse.Encode(35.3); Console.WriteLine(Arrays.ToString(encoding)); // Now test the encoding of an input row Map <string, object> d = new Map <string, object>(); d.Add("timestamp", dateEnc.Parse("7/12/10 13:10")); d.Add("consumption", 35.3); int[] output = multiEncoder.Encode(d); int[] expected = { 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; Console.WriteLine(Arrays.ToString(expected)); Console.WriteLine(Arrays.ToString(output)); Assert.IsTrue(Arrays.AreEqual(expected, output)); }
public void TestAlgorithmRepetitionDetection() { Parameters p = NetworkTestHarness.GetParameters(); p = p.Union(NetworkTestHarness.GetDayDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42)); // -- No overlap Net.Network.Network n = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("2/3", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true) .Add(new TemporalMemory())) .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add(Sensor <FileSensor> .Create(FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "days-of-week.Csv")))) .Add(new SpatialPooler())) .Connect("2/3", "4")); Region r = n.Lookup("r1"); Assert.IsTrue(r.layersDistinct); LayerMask flags = r.flagAccumulator; flags ^= LayerMask.SpatialPooler; flags ^= LayerMask.TemporalMemory; flags ^= LayerMask.ClaClassifier; Assert.AreEqual(LayerMask.None, flags); Assert.AreEqual(r.Lookup("2/3").GetMask(), (LayerMask.TemporalMemory | LayerMask.ClaClassifier)); Assert.AreEqual(r.Lookup("4").GetMask(), LayerMask.SpatialPooler); // -- Test overlap detection n = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer <IInference>("2/3", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true) .Add(new TemporalMemory())) .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add(Sensor <FileSensor> .Create(FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "days-of-week.Csv")))) .Add(new TemporalMemory()) .Add(new SpatialPooler())) .Connect("2/3", "4")); r = n.Lookup("r1"); Assert.IsFalse(r.layersDistinct); Assert.AreEqual(r.Lookup("2/3").GetMask(), (LayerMask.TemporalMemory | LayerMask.ClaClassifier)); Assert.AreEqual(r.Lookup("4").GetMask(), (LayerMask.SpatialPooler | LayerMask.TemporalMemory)); }
public void Test2LayerAssemblyWithSensor() { 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>("2/3", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true) .Add(new TemporalMemory())) .Add(Net.Network.Network.CreateLayer <IInference>("4", p) .Add(Sensor <FileSensor> .Create(FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "days-of-week.Csv")))) .Add(new SpatialPooler())) .Connect("2/3", "4")); int[][] inputs = new int[7][]; inputs[0] = new[] { 1, 1, 0, 0, 0, 0, 0, 1 }; inputs[1] = new[] { 1, 1, 1, 0, 0, 0, 0, 0 }; inputs[2] = new[] { 0, 1, 1, 1, 0, 0, 0, 0 }; inputs[3] = new[] { 0, 0, 1, 1, 1, 0, 0, 0 }; inputs[4] = new[] { 0, 0, 0, 1, 1, 1, 0, 0 }; inputs[5] = new[] { 0, 0, 0, 0, 1, 1, 1, 0 }; inputs[6] = new[] { 0, 0, 0, 0, 0, 1, 1, 1 }; Region r1 = n.Lookup("r1"); // Observe the top layer r1.Lookup("4").Observe().Subscribe( // next i => { Console.WriteLine("onNext() called (4)"); Assert.IsTrue(Arrays.AreEqual(inputs[idx0++], i.GetEncoding())); }, //error e => { Console.WriteLine(e); }, //completed () => { Console.WriteLine("onCompleted() called (4)"); } ); //r1.Lookup("4").Observe().Subscribe(new Subscriber<Inference>() //{ // public void onCompleted() { } // public void onError(Throwable e) { e.printStackTrace(); } // public void onNext(Inference i) // { // Assert.IsTrue(Arrays.equals(inputs[idx0++], i.GetEncoding())); // } //}); // Observe the bottom layer r1.Lookup("2/3").Observe().Subscribe( // next i => { Console.WriteLine("onNext() called (2/3)"); Assert.IsTrue(Arrays.AreEqual(inputs[idx1++], i.GetEncoding())); }, //error e => { Console.WriteLine(e); }, //completed () => { Console.WriteLine("onCompleted() called (2/3)"); } ); //r1.Lookup("2/3").Observe().Subscribe(new Subscriber<Inference>() { // public void onCompleted() { } // public void onError(Throwable e) { e.printStackTrace(); } // public void onNext(Inference i) // { // Assert.IsTrue(Arrays.equals(inputs[idx1++], i.GetEncoding())); // } //}); // Observe the Region output r1.Observe().Subscribe( // next i => { Console.WriteLine("onNext() called (out)"); Assert.IsTrue(Arrays.AreEqual(inputs[idx2++], i.GetEncoding())); }, //error e => { Console.WriteLine(e); }, //completed () => { Console.WriteLine("onCompleted() called (out)"); } ); //r1.Observe().Subscribe(new Subscriber<Inference>() { // public void onCompleted() { } // public void onError(Throwable e) { e.printStackTrace(); } // public void onNext(Inference i) // { // Assert.IsTrue(Arrays.equals(inputs[idx2++], i.GetEncoding())); // } //}); r1.Start(); try { r1.Lookup("4").GetLayerThread().Wait(); } catch (Exception e) { Console.WriteLine(e); } Assert.AreEqual(7, idx0); Assert.AreEqual(7, idx1); Assert.AreEqual(7, idx2); }
public void TestHalt() { 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(Sensor <FileSensor> .Create(FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "days-of-week.csv")))) .Add(new SpatialPooler())) .Connect("1", "2") .Connect("2", "3") .Connect("3", "4")); Region r1 = n.Lookup("r1"); int seq = 0; r1.Observe().Subscribe( // next i => { if (seq == 2) { isHalted = true; } seq++; }, //error e => { Console.WriteLine(e); }, //completed () => { Console.WriteLine("onCompleted() called"); } ); //r1.Observe().Subscribe(new Subscriber<Inference>() { // int seq = 0; // public void onCompleted() // { // // System.Out.println("onCompleted() called"); // } // public void onError(Throwable e) { e.printStackTrace(); } // public void onNext(Inference i) // { // if (seq == 2) // { // isHalted = true; // } // seq++; // // System.Out.println("output: " + i.GetSDR()); // } //}); new Thread(() => { while (!isHalted) { try { Thread.Sleep(1); } catch (Exception e) { Console.WriteLine(e); } } r1.Halt(); }).Start(); // (new Thread() // { // public void run() // { // while (!isHalted) // { // try { Thread.Sleep(1); } catch (Exception e) { e.printStackTrace(); } // } // r1.Halt(); // } //}).Start(); r1.Start(); try { r1.Lookup("4").GetLayerThread().Wait(); } catch (Exception e) { Console.WriteLine(e); } }
public void TestInputIntegerArray() { Sensor <FileInfo> sensor = Sensor <FileInfo> .Create(FileSensor.Create, SensorParams.Create(SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "1_100.Csv"))); HTMSensor <FileInfo> htmSensor = (HTMSensor <FileInfo>)sensor; htmSensor.InitEncoder(GetArrayTestParams()); // Ensure that the HTMSensor's output stream can be retrieved more than once. FanOutStream <int[]> outputStream = (FanOutStream <int[]>)htmSensor.GetOutputStream(); Assert.AreEqual(884, ((int[])outputStream.First()).Length); }
/** * Creates a {@link Network} containing 2 {@link Region}s with multiple * {@link PALayer}s in each. * * @return a multi-region Network */ internal Network.Network CreateMultiRegionNetwork() { Parameters p = NetworkDemoHarness.GetParameters(); p = p.Union(NetworkDemoHarness.GetNetworkDemoTestEncoderParams()); return(Network.Network.Create("Network API Demo", p) .Add(Network.Network.CreateRegion("Region 1") .Add(Network.Network.CreateLayer("Layer 2/3", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true) .Add(Anomaly.Create()) .Add(new TemporalMemory())) .Add(Network.Network.CreateLayer("Layer 4", p) .Add(new PASpatialPooler())) .Connect("Layer 2/3", "Layer 4")) .Add(Network.Network.CreateRegion("Region 2") .Add(Network.Network.CreateLayer("Layer 2/3", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true) .Add(Anomaly.Create()) .Add(new TemporalMemory()) .Add(new PASpatialPooler())) .Add(Network.Network.CreateLayer("Layer 4", p) .Add(Sensor <FileInfo> .Create(FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "rec-center-15m.csv"))))) .Connect("Layer 2/3", "Layer 4")) .Connect("Region 1", "Region 2")); }
private Net.Network.Network GetLoadedHotGymHierarchy() { Parameters p = NetworkTestHarness.GetParameters(); p = p.Union(NetworkTestHarness.GetNetworkDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42)); Net.Network.Network network = Net.Network.Network.Create("test network", p) .Add(Net.Network.Network.CreateRegion("r1") .Add(Net.Network.Network.CreateLayer("2", p) .Add(Anomaly.Create()) .Add(new TemporalMemory())) .Add(Net.Network.Network.CreateLayer("3", p) .Add(new SpatialPooler())) .Connect("2", "3")) .Add(Net.Network.Network.CreateRegion("r2") .Add(Net.Network.Network.CreateLayer("1", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true) .Add(new TemporalMemory()) .Add(new SpatialPooler()) .Add(FileSensor.Create(Net.Network.Sensor.FileSensor.Create, SensorParams.Create( SensorParams.Keys.Path, "", ResourceLocator.Path("rec-center-hourly.csv")))))) .Connect("r1", "r2"); return(network); }
/** * Creates a basic {@link Network} with 1 {@link Region} and 1 {@link PALayer}. However * this basic network contains all algorithmic components. * * @return a basic Network */ internal Network.Network CreateBasicNetwork() { Parameters p = NetworkDemoHarness.GetParameters(); p = p.Union(NetworkDemoHarness.GetNetworkDemoTestEncoderParams()); p.SetParameterByKey(Parameters.KEY.MIN_THRESHOLD, 22); // 22 18 p.SetParameterByKey(Parameters.KEY.ACTIVATION_THRESHOLD, 16); // 18 p.SetParameterByKey(Parameters.KEY.STIMULUS_THRESHOLD, 0.0); // 0.0 p.SetParameterByKey(Parameters.KEY.CELLS_PER_COLUMN, 1); // 1 Region r = Network.Network.CreateRegion("Region 1"); PALayer <IInference> l = new PALayer <IInference>("Layer 2/3", null, p); l.SetPADepolarize(0.0); // 0.25 l.SetVerbosity(0); PASpatialPooler sp = new PASpatialPooler(); string infile = "rec-center-15m.csv"; // This is how easy it is to create a full running Network! return(Network.Network.Create("Network API Demo", p) .Add(r.Add(l.AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true) .Add(Anomaly.Create()) .Add(new TemporalMemory()) .Add(sp) .Add(Sensor <FileInfo> .Create(FileSensor.Create, SensorParams.Create(SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), infile))))))); }
/** * Creates a basic {@link Network} with 1 {@link Region} and 1 {@link PALayer}. However * this basic network contains all algorithmic components. * * @return a basic Network */ internal Network.Network CreateBasicNetwork() { Parameters p = NetworkDemoHarness.GetParameters(); p = p.Union(NetworkDemoHarness.GetNetworkDemoTestEncoderParams()); // This is how easy it is to create a full running Network! return(Network.Network.Create("Network API Demo", p) .Add(Network.Network.CreateRegion("Region 1") .Add(Network.Network.CreateLayer("Layer 2/3", p) .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true) .Add(Anomaly.Create()) .Add(new TemporalMemory()) .Add(new Algorithms.SpatialPooler()) .Add(Sensor <FileInfo> .Create(FileSensor.Create, SensorParams.Create(SensorParams.Keys.Path, "", ResourceLocator.Path(typeof(Resources), "b2b_2014_output.csv"))))))); }