Ejemplo n.º 1
0
        /**
         * Closes the Region and completes the finalization of its assembly.
         * After this call, any attempt to mutate the structure of a Region
         * will result in an {@link IllegalStateException} being thrown.
         *
         * @return
         */
        public Region Close()
        {
            if (layers.Count < 1)
            {
                LOGGER.Warn("Closing region: " + name + " before adding contents.");
                return(this);
            }

            CompleteAssembly();

            ILayer l = tail;

            do
            {
                l.Close();
            } while ((l = l.GetNext()) != null);

            return(this);
        }
Ejemplo n.º 2
0
        public void TestSerializeLayer()
        {
            Parameters p = NetworkTestHarness.GetParameters().Copy();

            p.SetParameterByKey(Parameters.KEY.RANDOM, new MersenneTwister(42));
            Map <String, Map <String, Object> > settings = NetworkTestHarness.SetupMap(
                null,                     // map
                8,                        // n
                0,                        // w
                0,                        // min
                0,                        // max
                0,                        // radius
                0,                        // resolution
                null,                     // periodic
                null,                     // clip
                true,                     // forced
                "dayOfWeek",              // fieldName
                "darr",                   // fieldType (dense array as opposed to sparse array or "sarr")
                "SDRPassThroughEncoder"); // encoderType

            p.SetParameterByKey(Parameters.KEY.FIELD_ENCODING_MAP, settings);

            Sensor <ObservableSensor <string[]> > sensor = Sensor <ObservableSensor <string[]> > .Create(
                ObservableSensor <string[]> .Create, SensorParams.Create(SensorParams.Keys.Obs, new Object[] { "name",
                                                                                                               PublisherSupplier.GetBuilder()
                                                                                                               .AddHeader("dayOfWeek")
                                                                                                               .AddHeader("darr")
                                                                                                               .AddHeader("B").Build() }));

            ILayer layer = Net.Network.Network.CreateLayer("1", p)
                           .AlterParameter(Parameters.KEY.AUTO_CLASSIFY, true)
                           .Add(new SpatialPooler())
                           .Add(sensor);

            //        Observer obs = new Observer<IInference>() {
            //        @Override public void onCompleted() { }
            //    @Override public void onError(Throwable e) { e.printStackTrace(); }
            //    @Override
            //        public void onNext(Inference spatialPoolerOutput)
            //    {
            //        System.out.println("in onNext()");
            //    }
            //};

            var obs = Observer.Create <IInference>(
                spatialPoolerOutput => { Console.WriteLine("in onNext()"); },
                e => Console.WriteLine(e),
                () => { });

            layer.Subscribe(obs);
            layer.Close();

            SerialConfig    config = new SerialConfig("testSerializeLayer", SerialConfig.SERIAL_TEST_DIR);
            IPersistenceAPI api    = Persistence.Get(config);

            api.Write(layer);

            //Serialize above Connections for comparison with same run but unserialized below...
            ILayer serializedLayer = api.Read <ILayer>();

            Assert.AreEqual(serializedLayer, layer);
            DeepCompare(layer, serializedLayer);

            // Now change one attribute and see that they are not equal
            serializedLayer.ResetRecordNum();
            Assert.AreNotEqual(serializedLayer, layer);
        }