Exemplo n.º 1
0
 //Constructors
 /// <summary>
 /// Creates an uninitialized instance.
 /// </summary>
 public StateMachineSettings()
 {
     //Default settings
     RandomizerSeek           = 0;
     NeuralPreprocessorConfig = new NeuralPreprocessorSettings();
     ReadoutLayerConfig       = new ReadoutLayerSettings();
     MapperConfig             = null;
     return;
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates the state machine configuration.
        /// </summary>
        private StateMachineSettings CreateStateMachineCfg()
        {
            //Create neural preprocessor configuration
            NeuralPreprocessorSettings neuralPreprocessorCfg = CreatePreprocessorCfg("MainRes", "MainResStruct", "AnalogPool1", "AnalogPool2");
            //Create readout layer configuration.
            //We use test data ratio = 0.1, number of regression attempts = 2 and number of attempt epochs = 1000
            ReadoutLayerSettings readoutCfg = CreateReadoutLayerCfg(0.1d, 2, 1000);
            //Create state machine configuration
            StateMachineSettings stateMachineCfg = new StateMachineSettings(neuralPreprocessorCfg, readoutCfg);

            return(stateMachineCfg);
        }
Exemplo n.º 3
0
 //Constructors
 /// <summary>
 /// Creates an initialized instance
 /// </summary>
 /// <param name="neuralPreprocessorCfg">Configuration of the neural preprocessor</param>
 /// <param name="readoutLayerCfg">Configuration of the readout layer</param>
 /// <param name="mapperCfg">Configuration of mapper of predictors to readout units</param>
 /// <param name="randomizerSeek">Specifies random number generator's initial seek</param>
 public StateMachineSettings(NeuralPreprocessorSettings neuralPreprocessorCfg,
                             ReadoutLayerSettings readoutLayerCfg,
                             MapperSettings mapperCfg = null,
                             int randomizerSeek       = DefaultRandomizerSeek)
 {
     NeuralPreprocessorCfg = neuralPreprocessorCfg == null ? null : (NeuralPreprocessorSettings)neuralPreprocessorCfg.DeepClone();
     ReadoutLayerCfg       = (ReadoutLayerSettings)readoutLayerCfg.DeepClone();
     MapperCfg             = mapperCfg == null ? null : (MapperSettings)mapperCfg.DeepClone();
     RandomizerSeek        = randomizerSeek;
     Check();
     return;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Creates the neural preprocessor configuration.
        /// </summary>
        /// <param name="resInstName">The reservoir instance name.</param>
        /// <param name="resStructName">The reservoir structure configuration name.</param>
        /// <param name="pool1Name">The name of the pool1.</param>
        /// <param name="pool2Name">The name of the pool2.</param>
        NeuralPreprocessorSettings CreatePreprocessorCfg(string resInstName, string resStructName, string pool1Name, string pool2Name)
        {
            //Create input configuration
            InputEncoderSettings inputCfg = CreateInputCfg();
            //Create reservoir structure configuration
            ReservoirStructureSettings resStructCfg = CreateResStructCfg(resStructName, pool1Name, pool2Name);
            //Create reservoir instance configuration
            ReservoirInstanceSettings resInstCfg = CreateResInstCfg(resInstName, resStructName, pool1Name, pool2Name, 0, 1);
            //Create reservoir preprocessor configuration
            NeuralPreprocessorSettings preprocessorCfg = new NeuralPreprocessorSettings(inputCfg,
                                                                                        new ReservoirStructuresSettings(resStructCfg),
                                                                                        new ReservoirInstancesSettings(resInstCfg),
                                                                                        NeuralPreprocessorSettings.DefaultPredictorsReductionRatio
                                                                                        );

            return(preprocessorCfg);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Creates the instance and initializes it from given xml element.
        /// This is the preferred way to instantiate State Machine settings.
        /// </summary>
        /// <param name="elem">
        /// Xml data containing State Machine settings.
        /// Content of xml element is always validated against the xml schema.
        /// </param>
        public StateMachineSettings(XElement elem)
        {
            //Validation
            ElemValidator validator = new ElemValidator();
            Assembly assemblyRCNet = Assembly.GetExecutingAssembly();
            validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.StateMachineSettings.xsd");
            validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
            XElement stateMachineSettingsElem = validator.Validate(elem, "rootElem");
            //Parsing
            //Randomizer seek
            RandomizerSeek = int.Parse(stateMachineSettingsElem.Attribute("randomizerSeek").Value);
            //Neural preprocessor
            NeuralPreprocessorConfig = new NeuralPreprocessorSettings(stateMachineSettingsElem.Descendants("neuralPreprocessor").First());
            //Readout layer
            ReadoutLayerConfig = new ReadoutLayerSettings(stateMachineSettingsElem.Descendants("readoutLayer").First());
            //Mapper
            XElement mapperSettingsElem = stateMachineSettingsElem.Descendants("mapper").FirstOrDefault();
            if(mapperSettingsElem != null)
            {
                //Create mapper object
                MapperCfg = new MapperSettings();
                //Loop through mappings
                foreach(XElement mapElem in mapperSettingsElem.Descendants("map"))
                {
                    //Readout unit name
                    string readoutUnitName = mapElem.Attribute("readoutUnitName").Value;
                    int readoutUnitIdx = -1;
                    for (int i = 0; i < ReadoutLayerConfig.ReadoutUnitCfgCollection.Count; i++)
                    {
                        if(ReadoutLayerConfig.ReadoutUnitCfgCollection[i].Name == readoutUnitName)
                        {
                            readoutUnitIdx = i;
                            break;
                        }
                        else if(i == ReadoutLayerConfig.ReadoutUnitCfgCollection.Count - 1)
                        {
                            throw new Exception($"Name {readoutUnitName} not found among readout units.");
                        }
                    }
                    //Allowed pools
                    List<MapperSettings.AllowedPool> allowedPools = new List<MapperSettings.AllowedPool>();
                    XElement allowedPoolsElem = mapElem.Descendants("allowedPools").FirstOrDefault();
                    if (allowedPoolsElem != null)
                    {
                        foreach (XElement allowedPoolElem in allowedPoolsElem.Descendants("pool"))
                        {
                            //Reservoir instance name
                            string reservoirInstanceName = allowedPoolElem.Attribute("reservoirInstanceName").Value;
                            int reservoirInstanceIdx = -1;
                            for (int i = 0; i < NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection.Count; i++)
                            {
                                if (NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection[i].InstanceName == reservoirInstanceName)
                                {
                                    reservoirInstanceIdx = i;
                                    break;
                                }
                                else if (i == NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection.Count - 1)
                                {
                                    throw new Exception($"Name {reservoirInstanceName} not found among resevoir instances.");
                                }
                            }
                            //Pool name
                            string reservoirCfgName = NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection[reservoirInstanceIdx].Settings.SettingsName;
                            ReservoirSettings reservoirSettings = NeuralPreprocessorConfig.ReservoirInstanceDefinitionCollection[reservoirInstanceIdx].Settings;
                            string poolName = allowedPoolElem.Attribute("poolName").Value;
                            int poolIdx = -1;
                            for (int i = 0; i < reservoirSettings.PoolSettingsCollection.Count; i++)
                            {
                                if (reservoirSettings.PoolSettingsCollection[i].Name == poolName)
                                {
                                    poolIdx = i;
                                    break;
                                }
                                else if (i == reservoirSettings.PoolSettingsCollection.Count - 1)
                                {
                                    throw new Exception($"Name {poolName} not found among resevoir's pools.");
                                }
                            }
                            allowedPools.Add(new MapperSettings.AllowedPool { _reservoirInstanceIdx = reservoirInstanceIdx, _poolIdx = poolIdx });
                        }
                        MapperCfg.PoolsMap.Add(readoutUnitName, allowedPools);
                    }

                    //Allowed routed input fields
                    List<int> allowedRoutedFieldsIdxs = new List<int>();
                    XElement allowedInputFieldsElem = mapElem.Descendants("allowedInputFields").FirstOrDefault();
                    List<string> routedInputFieldNames = NeuralPreprocessorConfig.InputConfig.RoutedFieldNameCollection();
                    if (allowedInputFieldsElem != null)
                    {
                        foreach (XElement allowedInputFieldElem in allowedInputFieldsElem.Descendants("field"))
                        {
                            //Input field name
                            string inputFieldName = allowedInputFieldElem.Attribute("name").Value;
                            int routedFieldIdx = routedInputFieldNames.IndexOf(inputFieldName);
                            if (routedFieldIdx == -1)
                            {
                                throw new Exception($"Name {inputFieldName} not found among input fields allowed to be routed to readout.");
                            }
                            allowedRoutedFieldsIdxs.Add(routedFieldIdx);
                        }
                        MapperCfg.RoutedInputFieldsMap.Add(readoutUnitName, allowedRoutedFieldsIdxs);
                    }

                }
            }
            return;
        }