//Constructors /// <summary> /// Creates an initialized instance. /// </summary> /// <param name="cfg">The state machine configuration.</param> public StateMachine(StateMachineSettings cfg) { Config = (StateMachineSettings)cfg.DeepClone(); //Neural preprocessor instance NP = Config.NeuralPreprocessorCfg == null ? null : new NeuralPreprocessor(Config.NeuralPreprocessorCfg, Config.RandomizerSeek); //Readout layer instance RL = new ReadoutLayer(Config.ReadoutLayerCfg); return; }
//Constructor /// <summary> /// Constructs an instance of State Machine /// </summary> /// <param name="settings">State Machine settings</param> public StateMachine(StateMachineSettings settings) { _settings = settings.DeepClone(); //Neural preprocessor instance NP = new NeuralPreprocessor(settings.NeuralPreprocessorConfig, settings.RandomizerSeek); //Readout layer RL = null; return; }
/// <summary> /// Creates an initialized instance. /// </summary> /// <param name="xmlFileName">The name of xml file where the root element matches the state machine configuration.</param> public StateMachine(string xmlFileName) { XDocument xmlDoc = XDocument.Load(xmlFileName); Config = new StateMachineSettings(xmlDoc.Root); //Neural preprocessor instance NP = Config.NeuralPreprocessorCfg == null ? null : new NeuralPreprocessor(Config.NeuralPreprocessorCfg, Config.RandomizerSeek); //Readout layer instance RL = new ReadoutLayer(Config.ReadoutLayerCfg); return; }
//Constructor /// <summary> /// Constructs an instance of State Machine /// </summary> /// <param name="settings">State Machine settings</param> public StateMachine(StateMachineSettings settings) { _settings = settings.DeepClone(); //Neural preprocessor instance NP = new NeuralPreprocessor(settings.NeuralPreprocessorConfig, settings.RandomizerSeek); NumOfValidPredictors = 0; PredictorGeneralSwitchCollection = null; //Readout layer RL = null; return; }
/// <summary> /// The deep copy constructor /// </summary> /// <param name="source">Source instance</param> public StateMachineSettings(StateMachineSettings source) { //Copy RandomizerSeek = source.RandomizerSeek; InputConfig = source.InputConfig.DeepClone(); ReservoirInstanceDefinitionCollection = new List <ReservoirInstanceDefinition>(source.ReservoirInstanceDefinitionCollection.Count); foreach (ReservoirInstanceDefinition mapping in source.ReservoirInstanceDefinitionCollection) { ReservoirInstanceDefinitionCollection.Add(mapping.DeepClone()); } ReadoutLayerConfig = new ReadoutLayerSettings(source.ReadoutLayerConfig); return; }
//Constructors /// <summary> /// The deep copy constructor /// </summary> /// <param name="source">Source instance</param> public StateMachineSettings(StateMachineSettings source) { //Copy RandomizerSeek = source.RandomizerSeek; NeuralPreprocessorConfig = source.NeuralPreprocessorConfig.DeepClone(); ReadoutLayerConfig = new ReadoutLayerSettings(source.ReadoutLayerConfig); MapperCfg = null; if(source.MapperCfg != null) { MapperCfg = source.MapperCfg.DeepClone(); } return; }
/// <summary> /// The deep copy constructor /// </summary> /// <param name="source">Source instance</param> public StateMachineSettings(StateMachineSettings source) { //Copy TaskType = source.TaskType; RandomizerSeek = source.RandomizerSeek; InputFieldNameCollection = new List <string>(source.InputFieldNameCollection); ReservoirInstanceDefinitionCollection = new List <ReservoirInstanceDefinition>(source.ReservoirInstanceDefinitionCollection.Count); foreach (ReservoirInstanceDefinition mapping in source.ReservoirInstanceDefinitionCollection) { ReservoirInstanceDefinitionCollection.Add(mapping.DeepClone()); } RouteInputToReadout = source.RouteInputToReadout; ReadoutLayerConfig = new ReadoutLayerSettings(source.ReadoutLayerConfig); return; }
//Constructor /// <summary> /// Constructs an instance of State Machine /// </summary> /// <param name="settings">State Machine settings</param> public StateMachine(StateMachineSettings settings) { _settings = settings.DeepClone(); //Internal input generators _internalInputGeneratorCollection = new List <IGenerator>(); foreach (StateMachineSettings.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 = (_settings.RandomizerSeek < 0 ? new Random() : new Random(_settings.RandomizerSeek)); _numOfPredictors = 0; _reservoirCollection = new List <Reservoir>(_settings.ReservoirInstanceDefinitionCollection.Count); foreach (StateMachineSettings.ReservoirInstanceDefinition instanceDefinition in _settings.ReservoirInstanceDefinitionCollection) { Reservoir reservoir = new Reservoir(instanceDefinition, DataRange, rand); _reservoirCollection.Add(reservoir); _numOfPredictors += reservoir.NumOfOutputPredictors; } if (_settings.InputConfig.RouteExternalInputToReadout) { _numOfPredictors += _settings.InputConfig.ExternalFieldCollection.Count; } //Readout layer _readoutLayer = null; return; }
//Methods /// <summary> /// See the base. /// </summary> public override bool Equals(object obj) { if (obj == null) return false; StateMachineSettings cmpSettings = obj as StateMachineSettings; if (RandomizerSeek != cmpSettings.RandomizerSeek || !Equals(NeuralPreprocessorConfig, cmpSettings.NeuralPreprocessorConfig) || !Equals(ReadoutLayerConfig, cmpSettings.ReadoutLayerConfig) || (MapperCfg == null && cmpSettings.MapperCfg != null) || (MapperCfg != null && cmpSettings.MapperCfg == null) || (MapperCfg != null && !Equals(MapperCfg, cmpSettings.MapperCfg)) ) { return false; } return true; }
/// <summary> /// Creates the deep copy instance of this instance /// </summary> public StateMachineSettings DeepClone() { StateMachineSettings clone = new StateMachineSettings(this); return(clone); }
/// <summary> /// The deep copy constructor /// </summary> /// <param name="source">Source instance</param> public StateMachineSettings(StateMachineSettings source) : this(source.NeuralPreprocessorCfg, source.ReadoutLayerCfg, source.MapperCfg, source.RandomizerSeek) { return; }