Пример #1
0
        //Constructor
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="preprocessorCfg">The configuration of the neural preprocessor.</param>
        /// <param name="randomizerSeek">The random number generator initial seek.</param>
        public NeuralPreprocessor(NeuralPreprocessorSettings preprocessorCfg, int randomizerSeek)
        {
            _preprocessorCfg        = (NeuralPreprocessorSettings)preprocessorCfg.DeepClone();
            TotalNumOfHiddenNeurons = 0;
            ///////////////////////////////////////////////////////////////////////////////////
            //Input encoder
            _inputEncoder = new InputEncoder(_preprocessorCfg.InputEncoderCfg);
            ///////////////////////////////////////////////////////////////////////////////////
            //Reservoir instance(s)
            BootCycles = 0;
            //Random generator used for reservoir structure initialization
            Random rand = (randomizerSeek < 0 ? new Random() : new Random(randomizerSeek));

            ReservoirCollection = new List <ReservoirInstance>(_preprocessorCfg.ReservoirInstancesCfg.ReservoirInstanceCfgCollection.Count);
            int reservoirInstanceID = 0;
            int defaultBootCycles   = 0;

            foreach (ReservoirInstanceSettings reservoirInstanceCfg in _preprocessorCfg.ReservoirInstancesCfg.ReservoirInstanceCfgCollection)
            {
                ReservoirStructureSettings structCfg = _preprocessorCfg.ReservoirStructuresCfg.GetReservoirStructureCfg(reservoirInstanceCfg.StructureCfgName);
                ReservoirInstance          reservoir = new ReservoirInstance(reservoirInstanceID++,
                                                                             structCfg,
                                                                             reservoirInstanceCfg,
                                                                             _inputEncoder,
                                                                             rand
                                                                             );
                ReservoirCollection.Add(reservoir);
                TotalNumOfHiddenNeurons += reservoir.Size;
                defaultBootCycles        = Math.Max(defaultBootCycles, reservoir.GetDefaultBootCycles());
            }
            //Boot cycles setup
            if (_preprocessorCfg.InputEncoderCfg.FeedingCfg.FeedingType == InputEncoder.InputFeedingType.Continuous)
            {
                FeedingContinuousSettings feedingCfg = (FeedingContinuousSettings)preprocessorCfg.InputEncoderCfg.FeedingCfg;
                BootCycles = feedingCfg.BootCycles == FeedingContinuousSettings.AutoBootCyclesNum ? defaultBootCycles : feedingCfg.BootCycles;
            }
            else
            {
                BootCycles = 0;
            }
            //Output features
            _totalNumOfReservoirsPredictors      = 0;
            _predictorsTimePointSlicesPlan       = null;
            PredictorDescriptorCollection        = null;
            OutputFeatureGeneralSwitchCollection = null;
            NumOfActivePredictors = 0;
            return;
        }
Пример #2
0
        //Methods
        /// <summary>
        /// Creates input part of the neural preprocessor's configuration.
        /// </summary>
        private InputEncoderSettings CreateInputCfg()
        {
            //Definition of input external fields
            //In this example we will use three of available input fields: "High" price, "Low" price and "Adj Close" price.
            //We want to route input fields to readout layer together with other predictors
            const bool RouteToReadout = true;
            //All 3 input fields are real numbers and thus they should be standardly normalized and standardized.
            RealFeatureFilterSettings realFeatureFilterCfg = new RealFeatureFilterSettings(true, true);
            //Input fields collection
            ExternalFieldSettings  extFieldHighCfg     = new ExternalFieldSettings("High", realFeatureFilterCfg, RouteToReadout);
            ExternalFieldSettings  extFieldLowCfg      = new ExternalFieldSettings("Low", realFeatureFilterCfg, RouteToReadout);
            ExternalFieldSettings  extFieldAdjCloseCfg = new ExternalFieldSettings("Adj Close", realFeatureFilterCfg, RouteToReadout);
            ExternalFieldsSettings externalFieldsCfg   = new ExternalFieldsSettings(extFieldHighCfg, extFieldLowCfg, extFieldAdjCloseCfg);
            //Definition of the continuous input feeding
            //We use FeedingContinuousSettings.AutoBootCyclesNum so necessary number of boot cycles will be automatically determined
            //based on neural preprocessor structure
            FeedingContinuousSettings feedingContinuousCfg = new FeedingContinuousSettings(FeedingContinuousSettings.AutoBootCyclesNum);

            //Create and return input configuration
            return(new InputEncoderSettings(feedingContinuousCfg, new VaryingFieldsSettings(externalFieldsCfg, null, null, RouteToReadout)));
        }