Пример #1
0
        private static void SampleHutter()
        {
            const long timeWindowSize = 10L;

            SigmaEnvironment sigma = SigmaEnvironment.Create("recurrent");

            IDataSource      source    = new MultiSource(new FileSource("enwik8"), new CompressedSource(new MultiSource(new FileSource("enwik8.zip"), new UrlSource("http://mattmahoney.net/dc/enwik8.zip"))));
            IRecordExtractor extractor = new CharacterRecordReader(source, (int)(timeWindowSize + 1), Encoding.ASCII)
                                         .Extractor(new ArrayRecordExtractor <short>(ArrayRecordExtractor <short>
                                                                                     .ParseExtractorParameters("inputs", new[] { 0L }, new[] { timeWindowSize }, "targets", new[] { 0L }, new[] { timeWindowSize }))
                                                    .Offset("targets", 1L))
                                         .Preprocess(new PermutePreprocessor(0, 2, 1))
                                         .Preprocess(new OneHotPreprocessor(0, 255));
            IDataset dataset = new ExtractedDataset("hutter", ExtractedDataset.BlockSizeAuto, false, extractor);

            ITrainer trainer = sigma.CreateTrainer("hutter");

            trainer.Network.Architecture = InputLayer.Construct(256) + RecurrentLayer.Construct(256) + OutputLayer.Construct(256) + SoftMaxCrossEntropyCostLayer.Construct();
            trainer.TrainingDataIterator = new MinibatchIterator(32, dataset);
            trainer.AddNamedDataIterator("validation", new MinibatchIterator(100, dataset));
            trainer.Optimiser = new AdagradOptimiser(baseLearningRate: 0.07);
            trainer.Operator  = new CudaSinglethreadedOperator();

            trainer.AddInitialiser("*.*", new GaussianInitialiser(standardDeviation: 0.05));

            trainer.AddLocalHook(new AccumulatedValueReporter("optimiser.cost_total", TimeStep.Every(1, TimeScale.Iteration), averageValues: true));
            trainer.AddLocalHook(new RunningTimeReporter(TimeStep.Every(10, TimeScale.Iteration)));

            sigma.PrepareAndRun();
        }
Пример #2
0
        public void TestMultiSourceAssignActive()
        {
            string filename = ".unittest" + nameof(TestMultiSourceAssignActive);

            CreateTempFile(filename);

            FileSource  shouldBeActiveSource = new FileSource(filename, Path.GetTempPath());
            MultiSource source = new MultiSource(new FileSource("totallynotexisting"), shouldBeActiveSource);

            Assert.AreSame(shouldBeActiveSource, source.ActiveSource);

            source = new MultiSource(shouldBeActiveSource, new FileSource("totallynotexisting"));

            Assert.AreSame(shouldBeActiveSource, source.ActiveSource);
        }
Пример #3
0
        /**
         * When a packet is to be delivered to this node,
         * this method is called.  This method is public so that
         * we can chain protocols through the node.  For instance,
         * after a packet is handled, it may be a wrapped packet
         * which actually contains another packet inside.  Thus,
         * the unwrapped packet could be "Announced" by the handler
         *
         * One needs to be careful to prevent an infinite loop of
         * a Handler announcing the packet it is supposed to handle.
         */
        protected virtual void Announce(MemBlock b, ISender from)
        {
            //When Subscribe or unsubscribe are called,
            //they make copies of the ArrayList, thus we
            //only need to hold the sync while we are
            //getting the list of handlers.

            /*
             * Note that getting from Hashtable is threadsafe, multiple
             * threads writing is a problem
             */
            MemBlock    payload  = null;
            int         handlers = 0;
            MultiSource ns       = null;
            PType       t        = null;

            try {
                t        = PType.Parse(b, out payload);
                ns       = (MultiSource)DemuxHandler.GetTypeSource(t);
                handlers = ns.Announce(payload, from);

                /**
                 * @todo if no one handled the packet, we might want to send some
                 * ICMP-like message.
                 */
                if (handlers == 0)
                {
                    string p_s = payload.GetString(System.Text.Encoding.ASCII);
                    ProtocolLog.WriteIf(ProtocolLog.Exceptions, String.Format(
                                            "No Handler for packet type: {0} from: {2}\n{1} :: {3}", t, p_s, from, b.ToBase16String()));
                }
            }
            catch (Exception x) {
                ProtocolLog.WriteIf(ProtocolLog.Exceptions, String.Format(
                                        "Packet Handling Exception"));
                string nodeSource = "null";
                if (ns != null)
                {
                    nodeSource = ns.ToString();
                }
                ProtocolLog.WriteIf(ProtocolLog.Exceptions, String.Format(
                                        "Handler: {0}\tEdge: {1}", nodeSource, from));
                ProtocolLog.WriteIf(ProtocolLog.Exceptions, String.Format(
                                        "Exception: {0}", x));
            }
        }
Пример #4
0
        public void TestMultiSourcePrepareRetrieveDispose()
        {
            string filename = ".unittest" + nameof(TestMultiSourceAssignActive);

            CreateTempFile(filename);

            MultiSource source = new MultiSource(new FileSource("totallynotexisting"), new FileSource(filename, Path.GetTempPath()));

            source.Prepare();

            Stream       stream = source.Retrieve();
            StreamReader reader = new StreamReader(stream);

            Assert.AreEqual("5.1,3.5,1.4,0.2,Iris-setosa", reader.ReadLine());

            reader.Dispose();
            source.Dispose();

            DeleteTempFile(filename);
        }