/// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="elem">A xml element containing the configuration data.</param>
        public AnalogNeuronGroupSettings(XElement elem)
        {
            //Validation
            XElement settingsElem = Validate(elem, XsdTypeName);

            //Parsing
            //Name
            Name = settingsElem.Attribute("name").Value;
            //Relative share
            RelShare = double.Parse(settingsElem.Attribute("relShare").Value, CultureInfo.InvariantCulture);
            //Activation settings
            ActivationCfg = ActivationFactory.LoadSettings(settingsElem.Elements().First());
            //Firing threshold
            FiringThreshold         = double.Parse(settingsElem.Attribute("firingThreshold").Value, CultureInfo.InvariantCulture);
            ThresholdMaxRefDeepness = int.Parse(settingsElem.Attribute("thresholdMaxRefDeepness").Value, CultureInfo.InvariantCulture);
            //Bias
            XElement biasSettingsElem = settingsElem.Elements("bias").FirstOrDefault();

            BiasCfg = biasSettingsElem == null ? null : new RandomValueSettings(biasSettingsElem);
            //Retainment
            XElement retainmentSettingsElem = settingsElem.Elements("retainment").FirstOrDefault();

            RetainmentCfg = retainmentSettingsElem == null ? null : new RetainmentSettings(retainmentSettingsElem);
            //Predictors
            PredictorsCfg = new PredictorsProviderSettings(settingsElem.Elements("predictors").First());
            Check();
            return;
        }
Beispiel #2
0
            /// <summary>
            /// Creates the instance and initialize it from given xml element.
            /// </summary>
            /// <param name="elem">
            /// Xml data containing settings.
            /// Content of xml element is always validated against the xml schema.
            /// </param>
            public NeuronGroupSettings(XElement elem)
            {
                //Validation
                ElemValidator validator     = new ElemValidator();
                Assembly      assemblyRCNet = Assembly.GetExecutingAssembly();

                validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.Preprocessing.PoolNeuronGroupSettings.xsd");
                validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
                XElement settingsElem = validator.Validate(elem, "rootElem");

                //Parsing
                //Name
                Name = settingsElem.Attribute("name").Value;
                //Role
                Role = CommonEnums.ParseNeuronRole(settingsElem.Attribute("role").Value);
                //Relative share
                RelativeShare = double.Parse(settingsElem.Attribute("relShare").Value, CultureInfo.InvariantCulture);
                //Augmented states
                AugmentedStates = bool.Parse(settingsElem.Attribute("augmentedStates").Value);
                //Activation settings
                ActivationCfg = ActivationFactory.LoadSettings(settingsElem.Descendants().First());
                //Bias
                BiasCfg = new RandomValueSettings(settingsElem.Descendants("bias").First());
                return;
            }
Beispiel #3
0
        /// <summary>
        /// Creates the instance and initialize it from given xml element.
        /// This is the preferred way to instantiate reservoir settings.
        /// </summary>
        /// <param name="elem">
        /// Xml data containing feed forward network settings.
        /// Content of xml element is always validated against the xml schema.
        /// </param>
        public FeedForwardNetworkSettings(XElement elem)
        {
            //Validation
            ElemValidator validator     = new ElemValidator();
            Assembly      assemblyRCNet = Assembly.GetExecutingAssembly();

            validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.FF.FeedForwardNetworkSettings.xsd");
            validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
            XElement feedForwardNetworkSettingsElem = validator.Validate(elem, "rootElem");

            //Parsing
            OutputLayerActivation = ActivationFactory.LoadSettings(feedForwardNetworkSettingsElem.Descendants().First());
            if (!IsAllowedActivation(OutputLayerActivation, out Interval outputRange))
            {
                throw new ApplicationException($"Activation can't be used in FF network. Activation function has to be stateless and has to support derivative calculation.");
            }
            OutputRange      = outputRange;
            RegressionMethod = ParseTrainingMethodType(feedForwardNetworkSettingsElem.Attribute("regressionMethod").Value);
            //Hidden layers
            HiddenLayerCollection = new List <HiddenLayerSettings>();
            XElement hiddenLayersElem = feedForwardNetworkSettingsElem.Descendants("hiddenLayers").FirstOrDefault();

            if (hiddenLayersElem != null)
            {
                foreach (XElement layerElem in hiddenLayersElem.Descendants("layer"))
                {
                    HiddenLayerCollection.Add(new HiddenLayerSettings(layerElem));
                }
            }
            //Trainers
            LinRegrTrainerCfg = null;
            RPropTrainerCfg   = null;
            switch (RegressionMethod)
            {
            case TrainingMethodType.Linear:
                XElement linRegrTrainerElem = feedForwardNetworkSettingsElem.Descendants("linRegrTrainer").FirstOrDefault();
                if (linRegrTrainerElem != null)
                {
                    LinRegrTrainerCfg = new LinRegrTrainerSettings(linRegrTrainerElem);
                }
                else
                {
                    LinRegrTrainerCfg = new LinRegrTrainerSettings();
                }
                break;

            case TrainingMethodType.Resilient:
                XElement resPropTrainerElem = feedForwardNetworkSettingsElem.Descendants("resPropTrainer").FirstOrDefault();
                if (resPropTrainerElem != null)
                {
                    RPropTrainerCfg = new RPropTrainerSettings(resPropTrainerElem);
                }
                else
                {
                    RPropTrainerCfg = new RPropTrainerSettings();
                }
                break;
            }
            return;
        }
Beispiel #4
0
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="elem">Xml element containing the initialization settings.</param>
        public SpikingNeuronGroupSettings(XElement elem)
        {
            //Validation
            XElement settingsElem = Validate(elem, XsdTypeName);

            //Parsing
            //Name
            Name = settingsElem.Attribute("name").Value;
            //Relative share
            RelShare = double.Parse(settingsElem.Attribute("relShare").Value, CultureInfo.InvariantCulture);
            //Activation settings
            ActivationCfg = ActivationFactory.LoadSettings(settingsElem.Elements().First());
            //Homogenous excitability
            XElement homogenousExcitabilityElem = settingsElem.Elements("homogenousExcitability").FirstOrDefault();

            HomogenousExcitabilityCfg = homogenousExcitabilityElem == null ? new HomogenousExcitabilitySettings() : new HomogenousExcitabilitySettings(homogenousExcitabilityElem);
            //Bias
            XElement biasSettingsElem = settingsElem.Elements("bias").FirstOrDefault();

            BiasCfg = biasSettingsElem == null ? null : new RandomValueSettings(biasSettingsElem);
            //Predictors
            XElement predictorsSettingsElem = settingsElem.Elements("predictors").FirstOrDefault();

            if (predictorsSettingsElem != null)
            {
                PredictorsCfg = new PredictorsSettings(predictorsSettingsElem);
            }
            Check();
            return;
        }
Beispiel #5
0
        /// <summary>
        /// Creates the instance and initialize it from given xml element.
        /// This is the preferred way to instantiate settings.
        /// </summary>
        /// <param name="elem">
        /// Xml data containing settings.
        /// Content of xml element is always validated against the xml schema.
        /// </param>
        public FeedForwardNetworkSettings(XElement elem)
        {
            //Validation
            ElemValidator validator     = new ElemValidator();
            Assembly      assemblyRCNet = Assembly.GetExecutingAssembly();

            validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.FF.FeedForwardNetworkSettings.xsd");
            validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
            XElement settingsElem = validator.Validate(elem, "rootElem");

            //Parsing
            OutputLayerActivation = ActivationFactory.LoadSettings(settingsElem.Descendants().First());
            if (!IsAllowedActivation(OutputLayerActivation, out Interval outputRange))
            {
                throw new ApplicationException($"Activation can't be used in FF network. Activation function has to be stateless and has to support derivative calculation.");
            }
            OutputRange = outputRange;
            //Hidden layers
            HiddenLayerCollection = new List <HiddenLayerSettings>();
            XElement hiddenLayersElem = settingsElem.Descendants("hiddenLayers").FirstOrDefault();

            if (hiddenLayersElem != null)
            {
                foreach (XElement layerElem in hiddenLayersElem.Descendants("layer"))
                {
                    HiddenLayerCollection.Add(new HiddenLayerSettings(layerElem));
                }
            }
            //Trainer configuration
            TrainerCfg = null;
            foreach (XElement candidate in settingsElem.Descendants())
            {
                if (candidate.Name.LocalName == "linRegrTrainer")
                {
                    TrainerCfg = new LinRegrTrainerSettings(candidate);
                }
                else if (candidate.Name.LocalName == "qrdRegrTrainer")
                {
                    TrainerCfg = new QRDRegrTrainerSettings(candidate);
                }
                else if (candidate.Name.LocalName == "ridgeRegrTrainer")
                {
                    TrainerCfg = new RidgeRegrTrainerSettings(candidate);
                }
                else if (candidate.Name.LocalName == "resPropTrainer")
                {
                    TrainerCfg = new RPropTrainerSettings(candidate);
                }
                if (TrainerCfg != null)
                {
                    break;
                }
            }
            if (TrainerCfg == null)
            {
                throw new Exception("Trainer settings not found.");
            }
            return;
        }
Beispiel #6
0
 /// <summary>
 /// Creates the instance and initializes it from given xml element.
 /// </summary>
 /// <param name="elem">
 /// Xml data containing the settings.
 /// </param>
 public HiddenLayerSettings(XElement elem)
 {
     NumOfNeurons = int.Parse(elem.Attribute("neurons").Value);
     Activation   = ActivationFactory.LoadSettings(elem.Descendants().First());
     if (!IsAllowedActivation(Activation, out Interval outputRange))
     {
         throw new ApplicationException($"Activation can't be used in FF network. Activation has to be time independent and has to support derivative.");
     }
     return;
 }
Beispiel #7
0
        /// <summary>
        /// Creates an initialized instance from given xml element.
        /// </summary>
        /// <param name="elem">Xml element containing the settings.</param>
        public HiddenLayerSettings(XElement elem)
        {
            //Validation
            XElement settingsElem = Validate(elem, XsdTypeName);

            //Parsing
            NumOfNeurons  = int.Parse(settingsElem.Attribute("neurons").Value);
            ActivationCfg = ActivationFactory.LoadSettings(settingsElem.Elements().First());
            Check();
            return;
        }
Beispiel #8
0
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="elem">Xml element containing the initialization settings</param>
        public FeedForwardNetworkSettings(XElement elem)
        {
            //Validation
            XElement settingsElem = Validate(elem, XsdTypeName);

            //Parsing
            OutputActivationCfg = ActivationFactory.LoadSettings(settingsElem.Elements().First());
            OutputRange         = ActivationFactory.GetInfo(OutputActivationCfg, out _, out _);
            //Hidden layers
            XElement hiddenLayersElem = settingsElem.Elements("hiddenLayers").FirstOrDefault();

            if (hiddenLayersElem != null)
            {
                HiddenLayersCfg = new HiddenLayersSettings(hiddenLayersElem);
            }
            else
            {
                HiddenLayersCfg = new HiddenLayersSettings();
            }
            //Trainer configuration
            TrainerCfg = null;
            foreach (XElement candidate in settingsElem.Elements())
            {
                if (candidate.Name.LocalName == "qrdRegrTrainer")
                {
                    TrainerCfg = new QRDRegrTrainerSettings(candidate);
                    break;
                }
                else if (candidate.Name.LocalName == "ridgeRegrTrainer")
                {
                    TrainerCfg = new RidgeRegrTrainerSettings(candidate);
                    break;
                }
                else if (candidate.Name.LocalName == "elasticRegrTrainer")
                {
                    TrainerCfg = new ElasticRegrTrainerSettings(candidate);
                    break;
                }
                else if (candidate.Name.LocalName == "resPropTrainer")
                {
                    TrainerCfg = new RPropTrainerSettings(candidate);
                    break;
                }
            }
            Check();
            return;
        }
Beispiel #9
0
            /// <summary>
            /// Creates the instance and initialize it from given xml element.
            /// </summary>
            /// <param name="elem">
            /// Xml data containing settings.
            /// Content of xml element is always validated against the appropriate xml schema.
            /// </param>
            /// <param name="activationType">Specifies sub-type of the neuron group</param>
            public NeuronGroupSettings(XElement elem, ActivationType activationType)
            {
                //Validation
                ElemValidator validator     = new ElemValidator();
                Assembly      assemblyRCNet = Assembly.GetExecutingAssembly();

                if (activationType == ActivationType.Analog)
                {
                    validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.Preprocessing.PoolAnalogNeuronGroupSettings.xsd");
                }
                else
                {
                    validator.AddXsdFromResources(assemblyRCNet, "RCNet.Neural.Network.SM.Preprocessing.PoolSpikingNeuronGroupSettings.xsd");
                }
                validator.AddXsdFromResources(assemblyRCNet, "RCNet.RCNetTypes.xsd");
                XElement settingsElem = validator.Validate(elem, "rootElem");

                ActivationType = activationType;
                //Parsing
                //Name
                Name = settingsElem.Attribute("name").Value;
                //Role
                Role = NeuronCommon.ParseNeuronRole(settingsElem.Attribute("role").Value);
                //Relative share
                RelativeShare = double.Parse(settingsElem.Attribute("relShare").Value, CultureInfo.InvariantCulture);
                //Readout neurons density
                ReadoutNeuronsDensity = double.Parse(settingsElem.Attribute("readoutDensity").Value, CultureInfo.InvariantCulture);
                //Activation settings
                ActivationCfg = ActivationFactory.LoadSettings(settingsElem.Descendants().First());
                //Bias
                XElement cfgElem = settingsElem.Descendants("bias").FirstOrDefault();

                BiasCfg = cfgElem == null ? null : new RandomValueSettings(cfgElem);
                //Spiking sub-type
                if (activationType == ActivationType.Spiking)
                {
                    SignalingRestriction     = NeuronCommon.NeuronSignalingRestrictionType.SpikingOnly;
                    AnalogFiringThreshold    = 0;
                    RetainmentNeuronsDensity = 0;
                    RetainmentStrengthCfg    = null;
                }
                else
                {
                    //Analog sub-type
                    //Output signaling restriction
                    SignalingRestriction = NeuronCommon.ParseNeuronSignalingRestriction(settingsElem.Attribute("signalingRestriction").Value);
                    //Analog firing threshold
                    cfgElem = settingsElem.Descendants("firingThreshold").FirstOrDefault();
                    AnalogFiringThreshold = cfgElem == null ? DefaultAnalogFiringThreshold : double.Parse(cfgElem.Attribute("value").Value, CultureInfo.InvariantCulture);
                    //Retainment
                    cfgElem = settingsElem.Descendants("retainment").FirstOrDefault();
                    RetainmentNeuronsDensity = 0;
                    RetainmentStrengthCfg    = null;
                    if (cfgElem != null)
                    {
                        RetainmentNeuronsDensity = double.Parse(cfgElem.Attribute("density").Value, CultureInfo.InvariantCulture);
                        RetainmentStrengthCfg    = new RandomValueSettings(cfgElem.Descendants("strength").First());
                        if (RetainmentNeuronsDensity == 0 || (RetainmentStrengthCfg.Min == 0 && RetainmentStrengthCfg.Max == 0))
                        {
                            RetainmentNeuronsDensity = 0;
                            RetainmentStrengthCfg    = null;
                        }
                    }
                }
                //Predictors
                XElement predictorsElem = settingsElem.Descendants("predictors").FirstOrDefault();

                if (predictorsElem != null)
                {
                    PredictorsCfg = new HiddenNeuronPredictorsSettings(predictorsElem);
                }
                return;
            }