//Constructors /// <summary> /// The deep copy constructor /// </summary> /// <param name="source">Source instance</param> public NeuralPreprocessorSettings(NeuralPreprocessorSettings source) { //Copy InputConfig = source.InputConfig.DeepClone(); ReservoirInstanceDefinitionCollection = new List <ReservoirInstanceDefinition>(source.ReservoirInstanceDefinitionCollection.Count); foreach (ReservoirInstanceDefinition mapping in source.ReservoirInstanceDefinitionCollection) { ReservoirInstanceDefinitionCollection.Add(mapping.DeepClone()); } return; }
//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; }
//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; }
//Methods /// <summary> /// See the base. /// </summary> public override bool Equals(object obj) { if (obj == null) { return(false); } NeuralPreprocessorSettings cmpSettings = obj as NeuralPreprocessorSettings; if (!Equals(InputConfig, cmpSettings.InputConfig) || ReservoirInstanceDefinitionCollection.Count != cmpSettings.ReservoirInstanceDefinitionCollection.Count ) { return(false); } for (int i = 0; i < ReservoirInstanceDefinitionCollection.Count; i++) { if (!ReservoirInstanceDefinitionCollection[i].Equals(cmpSettings.ReservoirInstanceDefinitionCollection[i])) { return(false); } } return(true); }
/// <summary> /// Creates the deep copy instance of this instance /// </summary> public NeuralPreprocessorSettings DeepClone() { NeuralPreprocessorSettings clone = new NeuralPreprocessorSettings(this); return(clone); }
/// <summary> /// The deep copy constructor. /// </summary> /// <param name="source">The source instance.</param> public NeuralPreprocessorSettings(NeuralPreprocessorSettings source) : this(source.InputEncoderCfg, source.ReservoirStructuresCfg, source.ReservoirInstancesCfg, source.PredictorsReductionRatio, source.PredictorValueMinSpan) { return; }