示例#1
0
        //Methods
        /// <summary>
        /// See the base.
        /// </summary>
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            ISRUSettings cmpSettings = obj as ISRUSettings;

            if (!Equals(Alpha, cmpSettings.Alpha))
            {
                return(false);
            }
            return(true);
        }
示例#2
0
        /// <summary>
        /// Creates an instance of the activation function according to given settings.
        /// </summary>
        /// <param name="settings">Specific activation function settings </param>
        /// <param name="rand">Random object to be used for randomly generated parameters</param>
        public static IActivationFunction Create(RCNetBaseSettings settings, Random rand)
        {
            IActivationFunction af;
            Type settingsType = settings.GetType();

            if (settingsType == typeof(AdExpIFSettings))
            {
                AdExpIFSettings afs = (AdExpIFSettings)settings;
                af = new AdExpIF(rand.NextDouble(afs.TimeScale),
                                 rand.NextDouble(afs.Resistance),
                                 rand.NextDouble(afs.RestV),
                                 rand.NextDouble(afs.ResetV),
                                 rand.NextDouble(afs.RheobaseV),
                                 rand.NextDouble(afs.FiringThresholdV),
                                 rand.NextDouble(afs.SharpnessDeltaT),
                                 rand.NextDouble(afs.AdaptationVoltageCoupling),
                                 rand.NextDouble(afs.AdaptationTimeConstant),
                                 rand.NextDouble(afs.AdaptationSpikeTriggeredIncrement),
                                 afs.SolverMethod,
                                 afs.SolverCompSteps,
                                 afs.StimuliDuration
                                 );
            }
            else if (settingsType == typeof(BentIdentitySettings))
            {
                af = new BentIdentity();
            }
            else if (settingsType == typeof(ElliotSettings))
            {
                ElliotSettings afs = (ElliotSettings)settings;
                af = new Elliot(rand.NextDouble(afs.Slope));
            }
            else if (settingsType == typeof(ExpIFSettings))
            {
                ExpIFSettings afs = (ExpIFSettings)settings;
                af = new ExpIF(rand.NextDouble(afs.TimeScale),
                               rand.NextDouble(afs.Resistance),
                               rand.NextDouble(afs.RestV),
                               rand.NextDouble(afs.ResetV),
                               rand.NextDouble(afs.RheobaseV),
                               rand.NextDouble(afs.FiringThresholdV),
                               rand.NextDouble(afs.SharpnessDeltaT),
                               afs.RefractoryPeriods,
                               afs.SolverMethod,
                               afs.SolverCompSteps,
                               afs.StimuliDuration
                               );
            }
            else if (settingsType == typeof(GaussianSettings))
            {
                af = new Gaussian();
            }
            else if (settingsType == typeof(IdentitySettings))
            {
                af = new Identity();
            }
            else if (settingsType == typeof(ISRUSettings))
            {
                ISRUSettings afs = (ISRUSettings)settings;
                af = new ISRU(rand.NextDouble(afs.Alpha));
            }
            else if (settingsType == typeof(IzhikevichIFSettings))
            {
                IzhikevichIFSettings afs = (IzhikevichIFSettings)settings;
                af = new IzhikevichIF(rand.NextDouble(afs.RecoveryTimeScale),
                                      rand.NextDouble(afs.RecoverySensitivity),
                                      rand.NextDouble(afs.RecoveryReset),
                                      rand.NextDouble(afs.RestV),
                                      rand.NextDouble(afs.ResetV),
                                      rand.NextDouble(afs.FiringThresholdV),
                                      afs.RefractoryPeriods,
                                      afs.SolverMethod,
                                      afs.SolverCompSteps,
                                      afs.StimuliDuration
                                      );
            }
            else if (settingsType == typeof(AutoIzhikevichIFSettings))
            {
                double randomValue           = rand.NextDouble().Power(2);
                AutoIzhikevichIFSettings afs = (AutoIzhikevichIFSettings)settings;
                //Ranges
                af = new IzhikevichIF(0.02,
                                      0.2,
                                      8 + (-6 * randomValue),
                                      -70,
                                      -65 + (15 * randomValue),
                                      30,
                                      afs.RefractoryPeriods,
                                      afs.SolverMethod,
                                      afs.SolverCompSteps,
                                      afs.StimuliDuration
                                      );
            }
            else if (settingsType == typeof(LeakyIFSettings))
            {
                LeakyIFSettings afs = (LeakyIFSettings)settings;
                af = new LeakyIF(rand.NextDouble(afs.TimeScale),
                                 rand.NextDouble(afs.Resistance),
                                 rand.NextDouble(afs.RestV),
                                 rand.NextDouble(afs.ResetV),
                                 rand.NextDouble(afs.FiringThresholdV),
                                 afs.RefractoryPeriods,
                                 afs.SolverMethod,
                                 afs.SolverCompSteps,
                                 afs.StimuliDuration
                                 );
            }
            else if (settingsType == typeof(LeakyReLUSettings))
            {
                LeakyReLUSettings afs = (LeakyReLUSettings)settings;
                af = new LeakyReLU(rand.NextDouble(afs.NegSlope));
            }
            else if (settingsType == typeof(SigmoidSettings))
            {
                af = new Sigmoid();
            }
            else if (settingsType == typeof(SimpleIFSettings))
            {
                SimpleIFSettings afs = (SimpleIFSettings)settings;
                af = new SimpleIF(rand.NextDouble(afs.Resistance),
                                  rand.NextDouble(afs.DecayRate),
                                  rand.NextDouble(afs.ResetV),
                                  rand.NextDouble(afs.FiringThresholdV),
                                  afs.RefractoryPeriods
                                  );
            }
            else if (settingsType == typeof(SincSettings))
            {
                af = new Sinc();
            }
            else if (settingsType == typeof(SinusoidSettings))
            {
                af = new Sinusoid();
            }
            else if (settingsType == typeof(SoftExponentialSettings))
            {
                SoftExponentialSettings afs = (SoftExponentialSettings)settings;
                af = new SoftExponential(rand.NextDouble(afs.Alpha));
            }
            else if (settingsType == typeof(SoftPlusSettings))
            {
                af = new SoftPlus();
            }
            else if (settingsType == typeof(SQNLSettings))
            {
                af = new SQNL();
            }
            else if (settingsType == typeof(TanHSettings))
            {
                af = new TanH();
            }
            else
            {
                throw new ArgumentException($"Unsupported activation function settings: {settingsType.Name}");
            }
            //*
            //Set random initial membrane potential for spiking activation
            if (!af.Stateless && af.TypeOfActivation == ActivationType.Spiking)
            {
                af.SetInitialInternalState(rand.NextRangedUniformDouble(0.05, 0.95));
            }
            //*/
            return(af);
        }
示例#3
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public ISRUSettings(ISRUSettings source)
 {
     Alpha = source.Alpha.DeepClone();
     return;
 }
示例#4
0
        /// <summary>
        /// Creates the deep copy instance of this instance
        /// </summary>
        public ISRUSettings DeepClone()
        {
            ISRUSettings clone = new ISRUSettings(this);

            return(clone);
        }
示例#5
0
        /// <summary>
        /// Creates an instance of the activation function according to given settings.
        /// </summary>
        /// <param name="settings">Specific activation function settings </param>
        /// <param name="rand">Random object to be used for randomly generated parameters</param>
        public static IActivationFunction Create(Object settings, Random rand)
        {
            Type settingsType = settings.GetType();

            if (settingsType == typeof(AdExpIFSettings))
            {
                AdExpIFSettings afs = (AdExpIFSettings)settings;
                return(new AdExpIF(afs.StimuliCoeff,
                                   rand.NextDouble(afs.TimeScale),
                                   rand.NextDouble(afs.Resistance),
                                   rand.NextDouble(afs.RestV),
                                   rand.NextDouble(afs.ResetV),
                                   rand.NextDouble(afs.RheobaseV),
                                   rand.NextDouble(afs.FiringThresholdV),
                                   rand.NextDouble(afs.SharpnessDeltaT),
                                   rand.NextDouble(afs.AdaptationVoltageCoupling),
                                   rand.NextDouble(afs.AdaptationTimeConstant),
                                   rand.NextDouble(afs.AdaptationSpikeTriggeredIncrement),
                                   afs.SolverMethod,
                                   afs.SolverCompSteps
                                   ));
            }
            else if (settingsType == typeof(BentIdentitySettings))
            {
                return(new BentIdentity());
            }
            else if (settingsType == typeof(ElliotSettings))
            {
                ElliotSettings afs = (ElliotSettings)settings;
                return(new Elliot(rand.NextDouble(afs.Slope)));
            }
            else if (settingsType == typeof(ExpIFSettings))
            {
                //return new ExpIF((ExpIFSettings)settings, rand);
                ExpIFSettings afs = (ExpIFSettings)settings;
                return(new ExpIF(afs.StimuliCoeff,
                                 rand.NextDouble(afs.TimeScale),
                                 rand.NextDouble(afs.Resistance),
                                 rand.NextDouble(afs.RestV),
                                 rand.NextDouble(afs.ResetV),
                                 rand.NextDouble(afs.RheobaseV),
                                 rand.NextDouble(afs.FiringThresholdV),
                                 rand.NextDouble(afs.SharpnessDeltaT),
                                 afs.RefractoryPeriods,
                                 afs.SolverMethod,
                                 afs.SolverCompSteps
                                 ));
            }
            else if (settingsType == typeof(GaussianSettings))
            {
                return(new Gaussian());
            }
            else if (settingsType == typeof(IdentitySettings))
            {
                return(new Identity());
            }
            else if (settingsType == typeof(ISRUSettings))
            {
                ISRUSettings afs = (ISRUSettings)settings;
                return(new ISRU(rand.NextDouble(afs.Alpha)));
            }
            else if (settingsType == typeof(IzhikevichIFSettings))
            {
                IzhikevichIFSettings afs = (IzhikevichIFSettings)settings;
                return(new IzhikevichIF(afs.StimuliCoeff,
                                        rand.NextDouble(afs.RecoveryTimeScale),
                                        rand.NextDouble(afs.RecoverySensitivity),
                                        rand.NextDouble(afs.RecoveryReset),
                                        rand.NextDouble(afs.RestV),
                                        rand.NextDouble(afs.ResetV),
                                        rand.NextDouble(afs.FiringThresholdV),
                                        afs.RefractoryPeriods,
                                        afs.SolverMethod,
                                        afs.SolverCompSteps
                                        ));
            }
            else if (settingsType == typeof(AutoIzhikevichIFSettings))
            {
                double randomValue           = rand.NextBoundedUniformDouble(0, 1);
                AutoIzhikevichIFSettings afs = (AutoIzhikevichIFSettings)settings;
                if (afs.Role == CommonEnums.NeuronRole.Excitatory)
                {
                    //Excitatory ranges
                    return(new IzhikevichIF(afs.StimuliCoeff,
                                            0.02,
                                            0.2,
                                            8 + (-6 * randomValue.Power(2)),
                                            -70,
                                            -65 + (15 * randomValue.Power(2)),
                                            30,
                                            afs.RefractoryPeriods,
                                            afs.SolverMethod,
                                            afs.SolverCompSteps
                                            ));
                }
                else
                {
                    //Inhibitory ranges
                    return(new IzhikevichIF(afs.StimuliCoeff,
                                            0.02 + 0.08 * randomValue,
                                            0.25 - 0.05 * randomValue,
                                            2,
                                            -70,
                                            -65,
                                            30,
                                            afs.RefractoryPeriods,
                                            afs.SolverMethod,
                                            afs.SolverCompSteps
                                            ));
                }
            }
            else if (settingsType == typeof(LeakyIFSettings))
            {
                LeakyIFSettings afs = (LeakyIFSettings)settings;
                return(new LeakyIF(afs.StimuliCoeff,
                                   rand.NextDouble(afs.TimeScale),
                                   rand.NextDouble(afs.Resistance),
                                   rand.NextDouble(afs.RestV),
                                   rand.NextDouble(afs.ResetV),
                                   rand.NextDouble(afs.FiringThresholdV),
                                   afs.RefractoryPeriods,
                                   afs.SolverMethod,
                                   afs.SolverCompSteps
                                   ));
            }
            else if (settingsType == typeof(LeakyReLUSettings))
            {
                LeakyReLUSettings afs = (LeakyReLUSettings)settings;
                return(new LeakyReLU(rand.NextDouble(afs.NegSlope)));
            }
            else if (settingsType == typeof(SigmoidSettings))
            {
                return(new Sigmoid());
            }
            else if (settingsType == typeof(SimpleIFSettings))
            {
                SimpleIFSettings afs = (SimpleIFSettings)settings;
                return(new SimpleIF(afs.StimuliCoeff,
                                    rand.NextDouble(afs.Resistance),
                                    rand.NextDouble(afs.DecayRate),
                                    rand.NextDouble(afs.ResetV),
                                    rand.NextDouble(afs.FiringThresholdV),
                                    afs.RefractoryPeriods
                                    ));
            }
            else if (settingsType == typeof(SincSettings))
            {
                return(new Sinc());
            }
            else if (settingsType == typeof(SinusoidSettings))
            {
                return(new Sinusoid());
            }
            else if (settingsType == typeof(SoftExponentialSettings))
            {
                SoftExponentialSettings afs = (SoftExponentialSettings)settings;
                return(new SoftExponential(rand.NextDouble(afs.Alpha)));
            }
            else if (settingsType == typeof(SoftPlusSettings))
            {
                return(new SoftPlus());
            }
            else if (settingsType == typeof(TanHSettings))
            {
                return(new TanH());
            }
            else
            {
                throw new ArgumentException($"Unsupported activation function settings: {settingsType.Name}");
            }
        }
示例#6
0
 /// <summary>
 /// Copy constructor
 /// </summary>
 /// <param name="source">Source instance</param>
 public ISRUSettings(ISRUSettings source)
 {
     Alpha = (URandomValueSettings)source.Alpha.DeepClone();
     return;
 }