Example #1
0
 /// <summary>
 /// The copy constructor.
 /// </summary>
 /// <param name="source">The source instance.</param>
 public AFSpikingExpIFSettings(AFSpikingExpIFSettings source)
 {
     TimeScale         = (URandomValueSettings)source.TimeScale.DeepClone();
     Resistance        = (URandomValueSettings)source.Resistance.DeepClone();
     RestV             = (RandomValueSettings)source.RestV.DeepClone();
     ResetV            = (RandomValueSettings)source.ResetV.DeepClone();
     RheobaseV         = (RandomValueSettings)source.RheobaseV.DeepClone();
     FiringThresholdV  = (RandomValueSettings)source.FiringThresholdV.DeepClone();
     SharpnessDeltaT   = (URandomValueSettings)source.SharpnessDeltaT.DeepClone();
     RefractoryPeriods = source.RefractoryPeriods;
     SolverMethod      = source.SolverMethod;
     SolverCompSteps   = source.SolverCompSteps;
     StimuliDuration   = source.StimuliDuration;
     return;
 }
Example #2
0
        /// <summary>
        /// Creates the instance of the activation function.
        /// </summary>
        /// <param name="cfg">The configuration.</param>
        /// <param name="rand">A random object to be used for randomly generated parameters.</param>
        public static IActivation CreateAF(IActivationSettings cfg, Random rand)
        {
            IActivation af;
            Type        settingsType = cfg.GetType();

            if (settingsType == typeof(AFSpikingAdExpIFSettings))
            {
                AFSpikingAdExpIFSettings afs = (AFSpikingAdExpIFSettings)cfg;
                af = new AFSpikingAdExpIF(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,
                                          rand.NextRangedUniformDouble(MinInitialVRatio, MaxInitialVRatio)
                                          );
            }
            else if (settingsType == typeof(AFAnalogBentIdentitySettings))
            {
                af = new AFAnalogBentIdentity();
            }
            else if (settingsType == typeof(AFAnalogElliotSettings))
            {
                AFAnalogElliotSettings afs = (AFAnalogElliotSettings)cfg;
                af = new AFAnalogElliot(rand.NextDouble(afs.Slope));
            }
            else if (settingsType == typeof(AFSpikingExpIFSettings))
            {
                AFSpikingExpIFSettings afs = (AFSpikingExpIFSettings)cfg;
                af = new AFSpikingExpIF(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,
                                        rand.NextRangedUniformDouble(MinInitialVRatio, MaxInitialVRatio)
                                        );
            }
            else if (settingsType == typeof(AFAnalogGaussianSettings))
            {
                af = new AFAnalogGaussian();
            }
            else if (settingsType == typeof(AFAnalogIdentitySettings))
            {
                af = new AFAnalogIdentity();
            }
            else if (settingsType == typeof(AFAnalogISRUSettings))
            {
                AFAnalogISRUSettings afs = (AFAnalogISRUSettings)cfg;
                af = new AFAnalogISRU(rand.NextDouble(afs.Alpha));
            }
            else if (settingsType == typeof(AFSpikingIzhikevichIFSettings))
            {
                AFSpikingIzhikevichIFSettings afs = (AFSpikingIzhikevichIFSettings)cfg;
                af = new AFSpikingIzhikevichIF(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,
                                               rand.NextRangedUniformDouble(MinInitialVRatio, MaxInitialVRatio)
                                               );
            }
            else if (settingsType == typeof(AFSpikingAutoIzhikevichIFSettings))
            {
                double randomValue = rand.NextDouble().Power(2);
                AFSpikingAutoIzhikevichIFSettings afs = (AFSpikingAutoIzhikevichIFSettings)cfg;
                //Ranges
                af = new AFSpikingIzhikevichIF(0.02,
                                               0.2,
                                               8 + (-6 * randomValue),
                                               -70,
                                               -65 + (15 * randomValue),
                                               30,
                                               afs.RefractoryPeriods,
                                               afs.SolverMethod,
                                               afs.SolverCompSteps,
                                               afs.StimuliDuration,
                                               rand.NextRangedUniformDouble(MinInitialVRatio, MaxInitialVRatio)
                                               );
            }
            else if (settingsType == typeof(AFSpikingLeakyIFSettings))
            {
                AFSpikingLeakyIFSettings afs = (AFSpikingLeakyIFSettings)cfg;
                af = new AFSpikingLeakyIF(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,
                                          rand.NextRangedUniformDouble(MinInitialVRatio, MaxInitialVRatio)
                                          );
            }
            else if (settingsType == typeof(AFAnalogLeakyReLUSettings))
            {
                AFAnalogLeakyReLUSettings afs = (AFAnalogLeakyReLUSettings)cfg;
                af = new AFAnalogLeakyReLU(rand.NextDouble(afs.NegSlope));
            }
            else if (settingsType == typeof(AFAnalogSigmoidSettings))
            {
                af = new AFAnalogSigmoid();
            }
            else if (settingsType == typeof(AFSpikingSimpleIFSettings))
            {
                AFSpikingSimpleIFSettings afs = (AFSpikingSimpleIFSettings)cfg;
                af = new AFSpikingSimpleIF(rand.NextDouble(afs.Resistance),
                                           rand.NextDouble(afs.DecayRate),
                                           rand.NextDouble(afs.ResetV),
                                           rand.NextDouble(afs.FiringThresholdV),
                                           afs.RefractoryPeriods,
                                           rand.NextRangedUniformDouble(MinInitialVRatio, MaxInitialVRatio)
                                           );
            }
            else if (settingsType == typeof(AFAnalogSincSettings))
            {
                af = new AFAnalogSinc();
            }
            else if (settingsType == typeof(AFAnalogSinusoidSettings))
            {
                af = new AFAnalogSinusoid();
            }
            else if (settingsType == typeof(AFAnalogSoftExponentialSettings))
            {
                AFAnalogSoftExponentialSettings afs = (AFAnalogSoftExponentialSettings)cfg;
                af = new AFAnalogSoftExponential(rand.NextDouble(afs.Alpha));
            }
            else if (settingsType == typeof(AFAnalogSoftMaxSettings))
            {
                af = new AFAnalogSoftMax();
            }
            else if (settingsType == typeof(AFAnalogSoftPlusSettings))
            {
                af = new AFAnalogSoftPlus();
            }
            else if (settingsType == typeof(AFAnalogSQNLSettings))
            {
                af = new AFAnalogSQNL();
            }
            else if (settingsType == typeof(AFAnalogTanHSettings))
            {
                af = new AFAnalogTanH();
            }
            else
            {
                throw new ArgumentException($"Unsupported activation function configuration: {settingsType.Name}");
            }
            return(af);
        }