/// <summary> /// Checks whether the specified configuration is an existing type of A2S coder configuration. /// </summary> /// <param name="cfg">The coder configuration.</param> public static bool CheckSettings(RCNetBaseSettings cfg) { Type type = cfg.GetType(); if (type == typeof(A2SCoderGaussianReceptorsSettings)) { return(true); } else if (type == typeof(A2SCoderSignalStrengthSettings)) { return(true); } else if (type == typeof(A2SCoderUpDirArrowsSettings)) { return(true); } else if (type == typeof(A2SCoderDownDirArrowsSettings)) { return(true); } else { return(false); } }
/// <summary> /// Instantiates generator of proper type according to settings /// </summary> /// <param name="settings">Generator configuration</param> public static IGenerator Create(RCNetBaseSettings settings) { Type cfgType = settings.GetType(); if (cfgType == typeof(PulseGeneratorSettings)) { return(new PulseGenerator((PulseGeneratorSettings)settings)); } else if (cfgType == typeof(RandomValueSettings)) { return(new RandomGenerator((RandomValueSettings)settings)); } else if (cfgType == typeof(SinusoidalGeneratorSettings)) { return(new SinusoidalGenerator((SinusoidalGeneratorSettings)settings)); } else if (cfgType == typeof(MackeyGlassGeneratorSettings)) { return(new MackeyGlassGenerator((MackeyGlassGeneratorSettings)settings)); } else { throw new ArgumentException($"Unexpected transformer configuration {cfgType.Name}", "settings"); } }
/// <summary> /// Instantiates the appropriate A2S coder. /// </summary> /// <param name="cfg">The coder configuration.</param> public static A2SCoderBase Create(RCNetBaseSettings cfg) { Type type = cfg.GetType(); if (type == typeof(A2SCoderGaussianReceptorsSettings)) { return(new A2SCoderGaussianReceptors((A2SCoderGaussianReceptorsSettings)cfg)); } else if (type == typeof(A2SCoderSignalStrengthSettings)) { return(new A2SCoderSignalStrength((A2SCoderSignalStrengthSettings)cfg)); } else if (type == typeof(A2SCoderUpDirArrowsSettings)) { return(new A2SCoderUpDirArrows((A2SCoderUpDirArrowsSettings)cfg)); } else if (type == typeof(A2SCoderDownDirArrowsSettings)) { return(new A2SCoderDownDirArrows((A2SCoderDownDirArrowsSettings)cfg)); } else { throw new ArgumentException($"Unexpected A2S coder type {type.Name}", "settings"); } }
/// <summary> /// Returns collection of names of the fields associated with the transformed field /// </summary> /// <param name="settings">Transformed field configuration</param> public static List <string> GetAssociatedNames(RCNetBaseSettings settings) { List <string> names = new List <string>(); Type cfgType = settings.GetType(); if (cfgType == typeof(DiffTransformerSettings)) { names.Add(((DiffTransformerSettings)settings).InputFieldName); } else if (cfgType == typeof(CDivTransformerSettings)) { names.Add(((CDivTransformerSettings)settings).InputFieldName); } else if (cfgType == typeof(LogTransformerSettings)) { names.Add(((LogTransformerSettings)settings).InputFieldName); } else if (cfgType == typeof(ExpTransformerSettings)) { names.Add(((ExpTransformerSettings)settings).InputFieldName); } else if (cfgType == typeof(PowerTransformerSettings)) { names.Add(((PowerTransformerSettings)settings).InputFieldName); } else if (cfgType == typeof(YeoJohnsonTransformerSettings)) { names.Add(((YeoJohnsonTransformerSettings)settings).InputFieldName); } else if (cfgType == typeof(MWStatTransformerSettings)) { names.Add(((MWStatTransformerSettings)settings).InputFieldName); } else if (cfgType == typeof(MulTransformerSettings)) { names.Add(((MulTransformerSettings)settings).XInputFieldName); names.Add(((MulTransformerSettings)settings).YInputFieldName); } else if (cfgType == typeof(DivTransformerSettings)) { names.Add(((DivTransformerSettings)settings).XInputFieldName); names.Add(((DivTransformerSettings)settings).YInputFieldName); } else if (cfgType == typeof(LinearTransformerSettings)) { names.Add(((LinearTransformerSettings)settings).XInputFieldName); names.Add(((LinearTransformerSettings)settings).YInputFieldName); } else { throw new ArgumentException($"Unexpected transformer configuration {cfgType.Name}", "settings"); } return(names); }
/// <summary> /// Instantiates transformer of proper type according to settings /// </summary> /// <param name="fieldNames">Collection of names of all available input fields</param> /// <param name="settings">Transformer configuration</param> public static ITransformer Create(List <string> fieldNames, RCNetBaseSettings settings) { Type cfgType = settings.GetType(); if (cfgType == typeof(DiffTransformerSettings)) { return(new DiffTransformer(fieldNames, (DiffTransformerSettings)settings)); } else if (cfgType == typeof(CDivTransformerSettings)) { return(new CDivTransformer(fieldNames, (CDivTransformerSettings)settings)); } else if (cfgType == typeof(LogTransformerSettings)) { return(new LogTransformer(fieldNames, (LogTransformerSettings)settings)); } else if (cfgType == typeof(ExpTransformerSettings)) { return(new ExpTransformer(fieldNames, (ExpTransformerSettings)settings)); } else if (cfgType == typeof(PowerTransformerSettings)) { return(new PowerTransformer(fieldNames, (PowerTransformerSettings)settings)); } else if (cfgType == typeof(YeoJohnsonTransformerSettings)) { return(new YeoJohnsonTransformer(fieldNames, (YeoJohnsonTransformerSettings)settings)); } else if (cfgType == typeof(MWStatTransformerSettings)) { return(new MWStatTransformer(fieldNames, (MWStatTransformerSettings)settings)); } else if (cfgType == typeof(MulTransformerSettings)) { return(new MulTransformer(fieldNames, (MulTransformerSettings)settings)); } else if (cfgType == typeof(DivTransformerSettings)) { return(new DivTransformer(fieldNames, (DivTransformerSettings)settings)); } else if (cfgType == typeof(LinearTransformerSettings)) { return(new LinearTransformer(fieldNames, (LinearTransformerSettings)settings)); } else { throw new ArgumentException($"Unexpected transformer configuration {cfgType.Name}", "settings"); } }
/// <summary> /// Returns the deep clone of the activation function settings /// </summary> /// <param name="settings"> /// Specific activation function settings /// </param> public static RCNetBaseSettings DeepCloneActivationSettings(RCNetBaseSettings settings) { Type settingsType = settings.GetType(); if (settingsType == typeof(AdExpIFSettings)) { return(((AdExpIFSettings)settings).DeepClone()); } else if (settingsType == typeof(SQNLSettings)) { return(((SQNLSettings)settings).DeepClone()); } else if (settingsType == typeof(BentIdentitySettings)) { return(((BentIdentitySettings)settings).DeepClone()); } else if (settingsType == typeof(ElliotSettings)) { return(((ElliotSettings)settings).DeepClone()); } else if (settingsType == typeof(ExpIFSettings)) { return(((ExpIFSettings)settings).DeepClone()); } else if (settingsType == typeof(GaussianSettings)) { return(((GaussianSettings)settings).DeepClone()); } else if (settingsType == typeof(IdentitySettings)) { return(((IdentitySettings)settings).DeepClone()); } else if (settingsType == typeof(ISRUSettings)) { return(((ISRUSettings)settings).DeepClone()); } else if (settingsType == typeof(IzhikevichIFSettings)) { return(((IzhikevichIFSettings)settings).DeepClone()); } else if (settingsType == typeof(AutoIzhikevichIFSettings)) { return(((AutoIzhikevichIFSettings)settings).DeepClone()); } else if (settingsType == typeof(LeakyIFSettings)) { return(((LeakyIFSettings)settings).DeepClone()); } else if (settingsType == typeof(LeakyReLUSettings)) { return(((LeakyReLUSettings)settings).DeepClone()); } else if (settingsType == typeof(LeakyReLUSettings)) { return(((LeakyReLUSettings)settings).DeepClone()); } else if (settingsType == typeof(SigmoidSettings)) { return(((SigmoidSettings)settings).DeepClone()); } else if (settingsType == typeof(SimpleIFSettings)) { return(((SimpleIFSettings)settings).DeepClone()); } else if (settingsType == typeof(SincSettings)) { return(((SincSettings)settings).DeepClone()); } else if (settingsType == typeof(SinusoidSettings)) { return(((SinusoidSettings)settings).DeepClone()); } else if (settingsType == typeof(SoftExponentialSettings)) { return(((SoftExponentialSettings)settings).DeepClone()); } else if (settingsType == typeof(SoftPlusSettings)) { return(((SoftPlusSettings)settings).DeepClone()); } else if (settingsType == typeof(TanHSettings)) { return(((TanHSettings)settings).DeepClone()); } else { throw new ArgumentException($"Unsupported activation function settings: {settingsType.Name}"); } }
/// <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); }