示例#1
0
 //Constructor
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="location">The neuron's location.</param>
 /// <param name="analogActivation">The instance of an analog activation function.</param>
 /// <param name="bias">The constant bias.</param>
 /// <param name="firingThreshold">The firing threshold value. It must be GE0 and LT1. Every time the current normalized activation is higher than the normalized past reference activation by at least this threshold, it is evaluated as a firing event.</param>
 /// <param name="firingThresholdMaxRefDeepness">Maximum age of the past activation for the evaluation of the firing event.</param>
 /// <param name="retainmentStrength">The strength of the analog neuron's retainment property. It enables the leaky integrator feature of the neuron.</param>
 /// <param name="predictorsProviderCfg">The configuration of the predictors provider.</param>
 public HiddenNeuron(NeuronLocation location,
                     AFAnalogBase analogActivation,
                     double bias,
                     double firingThreshold,
                     int firingThresholdMaxRefDeepness,
                     double retainmentStrength,
                     PredictorsProviderSettings predictorsProviderCfg
                     )
 {
     Location   = location;
     Statistics = new NeuronStatistics();
     Bias       = bias;
     //Activation check
     if (analogActivation.TypeOfActivation == ActivationType.Spiking)
     {
         throw new ArgumentException($"Wrong type of the activation function.", "analogActivation");
     }
     _activationFn             = analogActivation;
     _analogFiringThreshold    = firingThreshold;
     _histActivationsQueue     = firingThresholdMaxRefDeepness < 2 ? null : new SimpleQueue <double>(firingThresholdMaxRefDeepness);
     _analogRetainmentStrength = retainmentStrength;
     _predictorsProvider       = predictorsProviderCfg != null ? new PredictorsProvider(predictorsProviderCfg) : null;
     OutputData = new NeuronOutputData();
     Reset(false);
     return;
 }
示例#2
0
        /// <summary>
        /// Creates configuration of the group of analog neurons having a TanH activation.
        /// </summary>
        /// <param name="groupName">The name of the group</param>
        /// <param name="relShare">The relative share. It determines how big part of the pool neurons will be occupied by this neuron group.</param>
        private AnalogNeuronGroupSettings CreateTanHGroup(string groupName, double relShare)
        {
            //Each neuron within the group will have its own constant bias
            //selected from the range -0.05 to 0.05 using gaussian (normal) distribution
            RandomValueSettings biasCfg = new RandomValueSettings(-0.05, 0.05, false, new GaussianDistrSettings(0, 1));
            //We want retainment property to be set for every neuron within the group
            const double RetainmentDensity = 1d;
            //Each neuron will have its own constant retainment strength
            //selected from the range 0 to 0.75 using uniform distribution
            URandomValueSettings retainmentStrengthCfg = new URandomValueSettings(0, 0.75);
            RetainmentSettings   retainmentCfg         = new RetainmentSettings(RetainmentDensity, retainmentStrengthCfg);
            //Predictors configuration
            //We will use the Activation and ActivationPower predictors
            PredictorsProviderSettings predictorsCfg = new PredictorsProviderSettings(new PredictorActivationSettings(),
                                                                                      new PredictorActivationPowerSettings()
                                                                                      );



            //Create the neuron group configuration
            AnalogNeuronGroupSettings groupCfg = new AnalogNeuronGroupSettings(groupName,
                                                                               relShare,
                                                                               new AFAnalogTanHSettings(),
                                                                               predictorsCfg,
                                                                               AnalogNeuronGroupSettings.DefaultFiringThreshold,
                                                                               AnalogNeuronGroupSettings.DefaultThresholdMaxRefDeepness,
                                                                               biasCfg,
                                                                               retainmentCfg
                                                                               );

            return(groupCfg);
        }
示例#3
0
        /// <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;
        }
        /// <summary>
        /// Creates an initialized instance.
        /// </summary>
        /// <param name="elem">A xml element containing the configuration data.</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
            PredictorsCfg = new PredictorsProviderSettings(settingsElem.Elements("predictors").First());
            Check();
            return;
        }
 //Constructors
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="name">The name of the neuron group.</param>
 /// <param name="relShare">Specifies how big relative portion of pool's neurons is formed by this group of the neurons.</param>
 /// <param name="activationCfg">The common configuration of the neurons' activation function.</param>
 /// <param name="predictorsCfg">The common configuration of the predictors provider.</param>
 /// <param name="homogenousExcitabilityCfg">The configuration of the neurons homogenous excitability.</param>
 /// <param name="biasCfg">The configuration of the constant input bias.</param>
 public SpikingNeuronGroupSettings(string name,
                                   double relShare,
                                   IActivationSettings activationCfg,
                                   PredictorsProviderSettings predictorsCfg,
                                   HomogenousExcitabilitySettings homogenousExcitabilityCfg = null,
                                   RandomValueSettings biasCfg = null
                                   )
 {
     Name                      = name;
     RelShare                  = relShare;
     ActivationCfg             = (IActivationSettings)activationCfg.DeepClone();
     PredictorsCfg             = (PredictorsProviderSettings)predictorsCfg.DeepClone();
     HomogenousExcitabilityCfg = homogenousExcitabilityCfg == null ? new HomogenousExcitabilitySettings() : (HomogenousExcitabilitySettings)homogenousExcitabilityCfg.DeepClone();
     BiasCfg                   = biasCfg == null ? null : (RandomValueSettings)biasCfg.DeepClone();
     Check();
     return;
 }
示例#6
0
        /// <summary>
        /// Creates the configuration of neuron group having the specified spiking activation function.
        /// </summary>
        /// <param name="activationCfg">The activation function configuration.</param>
        /// <param name="predictorsCfg">The predictors provider configuration.</param>
        /// <param name="excitabilityCfg">The configuration of the homogenous excitability.</param>
        /// <param name="steadyBias">The constant bias (0 means no bias).</param>
        private SpikingNeuronGroupSettings CreateSpikingGroup(IActivationSettings activationCfg,
                                                              PredictorsProviderSettings predictorsCfg,
                                                              HomogenousExcitabilitySettings excitabilityCfg,
                                                              double steadyBias = 0d
                                                              )
        {
            //Bias configuration
            RandomValueSettings biasCfg = steadyBias == 0 ? null : new RandomValueSettings(steadyBias, steadyBias);
            //Create neuron group configuration
            SpikingNeuronGroupSettings groupCfg = new SpikingNeuronGroupSettings(BuildNeuronGroupName(activationCfg),
                                                                                 1d,
                                                                                 activationCfg,
                                                                                 predictorsCfg,
                                                                                 excitabilityCfg,
                                                                                 biasCfg
                                                                                 );

            return(groupCfg);
        }
示例#7
0
 //Constructors
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="name">The name of the neuron group.</param>
 /// <param name="relShare">Specifies how big relative portion of pool's neurons is formed by this group of the neurons.</param>
 /// <param name="activationCfg">The common configuration of the neurons' activation function.</param>
 /// <param name="predictorsCfg">The common configuration of the predictors provider.</param>
 /// <param name="firingThreshold">The firing threshold value. Every time the current normalized activation is higher than the normalized past reference activation by at least this threshold, it is evaluated as a firing event.</param>
 /// <param name="thresholdMaxRefDeepness">Maximum age of the past activation for the evaluation of the firing event.</param>
 /// <param name="biasCfg">The configuration of the constant input bias.</param>
 /// <param name="retainmentCfg">The configuration of the neurons' retainment property.</param>
 public AnalogNeuronGroupSettings(string name,
                                  double relShare,
                                  IActivationSettings activationCfg,
                                  PredictorsProviderSettings predictorsCfg,
                                  double firingThreshold           = DefaultFiringThreshold,
                                  int thresholdMaxRefDeepness      = DefaultThresholdMaxRefDeepness,
                                  RandomValueSettings biasCfg      = null,
                                  RetainmentSettings retainmentCfg = null
                                  )
 {
     Name                    = name;
     RelShare                = relShare;
     ActivationCfg           = (IActivationSettings)activationCfg.DeepClone();
     PredictorsCfg           = (PredictorsProviderSettings)predictorsCfg.DeepClone();
     FiringThreshold         = firingThreshold;
     ThresholdMaxRefDeepness = thresholdMaxRefDeepness;
     BiasCfg                 = biasCfg == null ? null : (RandomValueSettings)biasCfg.DeepClone();
     RetainmentCfg           = retainmentCfg == null ? null : (RetainmentSettings)retainmentCfg.DeepClone();
     Check();
     return;
 }
示例#8
0
 //Constructor
 /// <summary>
 /// Creates an initialized instance.
 /// </summary>
 /// <param name="location">The neuron's location.</param>
 /// <param name="spikingActivation">The instance of a spiking activation function.</param>
 /// <param name="bias">The constant bias.</param>
 /// <param name="predictorsProviderCfg">The configuration of the predictors provider.</param>
 public HiddenNeuron(NeuronLocation location,
                     AFSpikingBase spikingActivation,
                     double bias,
                     PredictorsProviderSettings predictorsProviderCfg
                     )
 {
     Location   = location;
     Statistics = new NeuronStatistics();
     Bias       = bias;
     //Activation check
     if (spikingActivation.TypeOfActivation == ActivationType.Analog)
     {
         //Spiking
         throw new ArgumentException($"Wrong type of the activation function.", "spikingActivation");
     }
     _activationFn             = spikingActivation;
     _analogFiringThreshold    = 0;
     _histActivationsQueue     = null;
     _analogRetainmentStrength = 0;
     _predictorsProvider       = predictorsProviderCfg != null ? new PredictorsProvider(predictorsProviderCfg) : null;
     OutputData = new NeuronOutputData();
     Reset(false);
     return;
 }
示例#9
0
        /// <summary>
        /// Creates the configuration of neuron group having the specified analog activation function.
        /// </summary>
        /// <param name="activationCfg">The activation function configuration.</param>
        /// <param name="predictorsCfg">The predictors provider configuration.</param>
        /// <param name="maxAbsBias">The maximum absolute value of the bias (0 means no bias).</param>
        /// <param name="maxRetainmentStrength">The maximum retainment strength (0 means no retainment).</param>
        private AnalogNeuronGroupSettings CreateAnalogGroup(IActivationSettings activationCfg,
                                                            PredictorsProviderSettings predictorsCfg,
                                                            double maxAbsBias            = 0d,
                                                            double maxRetainmentStrength = 0d
                                                            )
        {
            //Bias configuration
            RandomValueSettings biasCfg = maxAbsBias == 0 ? null : new RandomValueSettings(-maxAbsBias, maxAbsBias);
            //Retainment configuration
            const double       RetainmentDensity = 1d;
            RetainmentSettings retainmentCfg     = maxRetainmentStrength == 0 ? null : new RetainmentSettings(RetainmentDensity, new URandomValueSettings(0, maxRetainmentStrength));
            //Create neuron group configuration
            AnalogNeuronGroupSettings groupCfg = new AnalogNeuronGroupSettings(BuildNeuronGroupName(activationCfg),
                                                                               1d,
                                                                               activationCfg,
                                                                               predictorsCfg,
                                                                               AnalogNeuronGroupSettings.DefaultFiringThreshold,
                                                                               AnalogNeuronGroupSettings.DefaultThresholdMaxRefDeepness,
                                                                               biasCfg,
                                                                               retainmentCfg
                                                                               );

            return(groupCfg);
        }
示例#10
0
        /// <summary>
        /// Creates the simplified configuration of the state machine following the pure LSM design.
        /// </summary>
        /// <param name="totalSize">The total number of hidden neurons.</param>
        /// <param name="spikingActivationCfg">The configuration of the spiking activation function.</param>
        /// <param name="excitabilityCfg">The homogenous excitability configuration.</param>
        /// <param name="inputConnectionDensity">The density of the input field connections to hidden neurons.</param>
        /// <param name="maxInputDelay">The maximum delay of an input synapse.</param>
        /// <param name="interconnectionDensity">The density of the hidden neurons recurrent interconnection.</param>
        /// <param name="maxInternalDelay">The maximum delay of an internal synapse.</param>
        /// <param name="steadyBias">The constant bias (0 means no bias).</param>
        /// <param name="predictorsProviderCfg">The configuration of the predictors provider.</param>
        public StateMachineSettings CreatePureLSMCfg(int totalSize,
                                                     IActivationSettings spikingActivationCfg,
                                                     HomogenousExcitabilitySettings excitabilityCfg,
                                                     double inputConnectionDensity,
                                                     int maxInputDelay,
                                                     double interconnectionDensity,
                                                     int maxInternalDelay,
                                                     double steadyBias,
                                                     PredictorsProviderSettings predictorsProviderCfg
                                                     )
        {
            //Check NP is not bypassed
            if (BypassedNP)
            {
                throw new InvalidOperationException("Neural preprocessor is bypassed thus LSM design can't be created.");
            }
            //Activation check
            if (ActivationFactory.CreateAF(spikingActivationCfg, new Random()).TypeOfActivation != ActivationType.Spiking)
            {
                throw new ArgumentException("Specified activation must be spiking.", "spikingActivationCfg");
            }
            //One neuron group
            SpikingNeuronGroupSettings grp = CreateSpikingGroup(spikingActivationCfg, predictorsProviderCfg, excitabilityCfg, steadyBias);
            //Simple spiking pool
            PoolSettings poolCfg = new PoolSettings(BuildPoolName(ActivationContent.Spiking, 0),
                                                    new ProportionsSettings(totalSize, 1, 1),
                                                    new NeuronGroupsSettings(grp),
                                                    new InterconnSettings(new RandomSchemaSettings(interconnectionDensity, 0d, false, false))
                                                    );
            //Simple reservoir structure
            ReservoirStructureSettings resStructCfg = new ReservoirStructureSettings(BuildResStructName(ActivationContent.Spiking, 0),
                                                                                     new PoolsSettings(poolCfg)
                                                                                     );
            //Input connections configuration
            List <InputConnSettings> inputConns = new List <InputConnSettings>(InputEncoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection.Count);

            foreach (ExternalFieldSettings fieldCfg in InputEncoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection)
            {
                InputConnSettings inputConnCfg = new InputConnSettings(fieldCfg.Name,
                                                                       poolCfg.Name,
                                                                       inputConnectionDensity,
                                                                       0
                                                                       );
                inputConns.Add(inputConnCfg);
            }
            //Synapse general configuration
            SpikingSourceSTInputSettings      spikingSourceSTInputSettings      = new SpikingSourceSTInputSettings(new URandomValueSettings(0, 1), new PlasticitySTInputSettings(new NonlinearDynamicsSTInputSettings()));
            SpikingSourceSTExcitatorySettings spikingSourceSTExcitatorySettings = new SpikingSourceSTExcitatorySettings(new URandomValueSettings(0, 1), new PlasticitySTExcitatorySettings(new NonlinearDynamicsSTExcitatorySettings()));
            SpikingSourceSTInhibitorySettings spikingSourceSTInhibitorySettings = new SpikingSourceSTInhibitorySettings(new URandomValueSettings(0, 1), new PlasticitySTInhibitorySettings(new NonlinearDynamicsSTInhibitorySettings()));
            SynapseSTInputSettings            synapseSTInputSettings            = new SynapseSTInputSettings(Synapse.SynapticDelayMethod.Random, maxInputDelay, null, spikingSourceSTInputSettings);
            SynapseSTExcitatorySettings       synapseSTExcitatorySettings       = new SynapseSTExcitatorySettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay, 4, null, spikingSourceSTExcitatorySettings);
            SynapseSTInhibitorySettings       synapseSTInhibitorySettings       = new SynapseSTInhibitorySettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay, 1, null, spikingSourceSTInhibitorySettings);
            SynapseSTSettings synapseSTCfg = new SynapseSTSettings(synapseSTInputSettings, synapseSTExcitatorySettings, synapseSTInhibitorySettings);
            SynapseSettings   synapseCfg   = new SynapseSettings(synapseSTCfg, null);

            //Create reservoir instance
            ReservoirInstanceSettings resInstCfg = new ReservoirInstanceSettings(GetResInstName(ResDesign.PureLSM, 0),
                                                                                 resStructCfg.Name,
                                                                                 new InputConnsSettings(inputConns),
                                                                                 synapseCfg
                                                                                 );

            //Build and return SM configuration
            return(new StateMachineSettings(new NeuralPreprocessorSettings(InputEncoderCfg,
                                                                           new ReservoirStructuresSettings(resStructCfg),
                                                                           new ReservoirInstancesSettings(resInstCfg)
                                                                           ),
                                            ReadoutLayerCfg
                                            ));
        }
示例#11
0
        /// <summary>
        /// Creates the simplified configuration of the state machine following the pure ESN design.
        /// </summary>
        /// <param name="totalSize">The total number of hidden neurons.</param>
        /// <param name="maxInputStrength">The max sum of weights of input synapses per an analog hidden neuron (see the constant DefaultAnalogMaxInputStrength).</param>
        /// <param name="inputConnectionDensity">The density of the input field connections to hidden neurons.</param>
        /// <param name="maxInputDelay">The maximum delay of an input synapse.</param>
        /// <param name="interconnectionDensity">The density of the hidden neurons recurrent interconnection.</param>
        /// <param name="maxInternalDelay">The maximum delay of an internal synapse.</param>
        /// <param name="maxAbsBias">The maximum absolute value of the bias (0 means no bias).</param>
        /// <param name="maxRetainmentStrength">The maximum retainment strength (0 means no retainment).</param>
        /// <param name="predictorsProviderCfg">The configuration of the predictors provider.</param>
        public StateMachineSettings CreatePureESNCfg(int totalSize,
                                                     double maxInputStrength,
                                                     double inputConnectionDensity,
                                                     int maxInputDelay,
                                                     double interconnectionDensity,
                                                     int maxInternalDelay,
                                                     double maxAbsBias,
                                                     double maxRetainmentStrength,
                                                     PredictorsProviderSettings predictorsProviderCfg
                                                     )
        {
            //Check NP is not bypassed
            if (BypassedNP)
            {
                throw new InvalidOperationException("Neural preprocessor is bypassed thus ESN design can't be created.");
            }
            //Default ESN activation
            IActivationSettings analogActivationCfg = new AFAnalogTanHSettings();
            //One neuron group
            AnalogNeuronGroupSettings grp = CreateAnalogGroup(analogActivationCfg, predictorsProviderCfg, maxAbsBias, maxRetainmentStrength);
            //Simple analog pool
            PoolSettings poolCfg = new PoolSettings(BuildPoolName(ActivationContent.Analog, 0),
                                                    new ProportionsSettings(totalSize, 1, 1),
                                                    new NeuronGroupsSettings(grp),
                                                    new InterconnSettings(new RandomSchemaSettings(interconnectionDensity))
                                                    );
            //Simple reservoir structure
            ReservoirStructureSettings resStructCfg = new ReservoirStructureSettings(BuildResStructName(ActivationContent.Analog, 0),
                                                                                     new PoolsSettings(poolCfg)
                                                                                     );
            //Input connections configuration
            List <InputConnSettings> inputConns = new List <InputConnSettings>(InputEncoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection.Count);

            foreach (ExternalFieldSettings fieldCfg in InputEncoderCfg.VaryingFieldsCfg.ExternalFieldsCfg.FieldCfgCollection)
            {
                InputConnSettings inputConnCfg = new InputConnSettings(fieldCfg.Name,
                                                                       poolCfg.Name,
                                                                       0,
                                                                       inputConnectionDensity
                                                                       );
                inputConns.Add(inputConnCfg);
            }
            //Synapse general configuration
            SynapseATInputSettings       synapseATInputSettings       = new SynapseATInputSettings(Synapse.SynapticDelayMethod.Random, maxInputDelay, new AnalogSourceSettings(new URandomValueSettings(0d, maxInputStrength)));
            SynapseATIndifferentSettings synapseATIndifferentSettings = new SynapseATIndifferentSettings(Synapse.SynapticDelayMethod.Random, maxInternalDelay);
            SynapseATSettings            synapseATCfg = new SynapseATSettings(SynapseATSettings.DefaultSpectralRadiusNum, synapseATInputSettings, synapseATIndifferentSettings);
            SynapseSettings synapseCfg = new SynapseSettings(null, synapseATCfg);

            //Create reservoir instance
            ReservoirInstanceSettings resInstCfg = new ReservoirInstanceSettings(GetResInstName(ResDesign.PureESN, 0),
                                                                                 resStructCfg.Name,
                                                                                 new InputConnsSettings(inputConns),
                                                                                 synapseCfg
                                                                                 );

            //Build and return SM configuration
            return(new StateMachineSettings(new NeuralPreprocessorSettings(InputEncoderCfg,
                                                                           new ReservoirStructuresSettings(resStructCfg),
                                                                           new ReservoirInstancesSettings(resInstCfg)
                                                                           ),
                                            ReadoutLayerCfg
                                            ));
        }