Esempio n. 1
0
        //Constructor
        /// <summary>
        /// Constructs an instance of Neural Preprocessor
        /// </summary>
        /// <param name="settings">Neural Preprocessor settings</param>
        /// A value greater than or equal to 0 will always ensure the same initialization of the internal
        /// random number generator and therefore the same network structure, which is good for tuning
        /// network parameters. A value less than 0 causes a fully random initialization when creating a network instance.
        /// <param name="randomizerSeek">
        /// </param>
        public NeuralPreprocessor(NeuralPreprocessorSettings settings, int randomizerSeek)
        {
            _settings = settings.DeepClone();
            _inputNormalizerCollection = null;
            //Internal input generators
            _internalInputGeneratorCollection = new List <IGenerator>();
            foreach (NeuralPreprocessorSettings.InputSettings.InternalField field in _settings.InputConfig.InternalFieldCollection)
            {
                if (field.GeneratorSettings.GetType() == typeof(ConstGeneratorSettings))
                {
                    _internalInputGeneratorCollection.Add(new ConstGenerator((ConstGeneratorSettings)field.GeneratorSettings));
                }
                else if (field.GeneratorSettings.GetType() == typeof(RandomValueSettings))
                {
                    _internalInputGeneratorCollection.Add(new RandomGenerator((RandomValueSettings)field.GeneratorSettings));
                }
                else if (field.GeneratorSettings.GetType() == typeof(SinusoidalGeneratorSettings))
                {
                    _internalInputGeneratorCollection.Add(new SinusoidalGenerator((SinusoidalGeneratorSettings)field.GeneratorSettings));
                }
                else if (field.GeneratorSettings.GetType() == typeof(MackeyGlassGeneratorSettings))
                {
                    _internalInputGeneratorCollection.Add(new MackeyGlassGenerator((MackeyGlassGeneratorSettings)field.GeneratorSettings));
                }
                else
                {
                    throw new Exception($"Unsupported internal signal generator for field {field.Name}");
                }
            }
            //Reservoir instance(s)
            //Random generator used for reservoir structure initialization
            Random rand = (randomizerSeek < 0 ? new Random() : new Random(randomizerSeek));

            PredictorNeuronCollection = new List <Reservoir.PredictorNeuron>();
            NumOfNeurons          = 0;
            NumOfPredictors       = 0;
            NumOfInternalSynapses = 0;
            ReservoirCollection   = new List <Reservoir>(_settings.ReservoirInstanceDefinitionCollection.Count);
            foreach (NeuralPreprocessorSettings.ReservoirInstanceDefinition instanceDefinition in _settings.ReservoirInstanceDefinitionCollection)
            {
                Reservoir reservoir = new Reservoir(instanceDefinition, _dataRange, rand);
                ReservoirCollection.Add(reservoir);
                PredictorNeuronCollection.AddRange(reservoir.PredictorNeuronCollection);
                NumOfNeurons          += reservoir.Size;
                NumOfPredictors       += reservoir.NumOfOutputPredictors;
                NumOfInternalSynapses += reservoir.NumOfInternalSynapses;
            }
            if (_settings.InputConfig.RouteExternalInputToReadout)
            {
                NumOfPredictors += _settings.InputConfig.ExternalFieldCollection.Count;
            }
            return;
        }
Esempio n. 2
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;
        }