|
| 1 | +/* *************************************************************************** |
| 2 | + * This file is part of SharpNEAT - Evolution of Neural Networks. |
| 3 | + * |
| 4 | + * Copyright 2004-2016 Colin Green ([email protected]) |
| 5 | + * |
| 6 | + * Written by Scott DeBoer, 2019 ([email protected]) |
| 7 | + * |
| 8 | + * SharpNEAT is free software; you can redistribute it and/or modify |
| 9 | + * it under the terms of The MIT License (MIT). |
| 10 | + * |
| 11 | + * You should have received a copy of the MIT License |
| 12 | + * along with SharpNEAT; if not, see https://opensource.org/licenses/MIT. |
| 13 | + */ |
| 14 | +using System; |
| 15 | +using System.Collections.Generic; |
| 16 | + |
| 17 | +namespace SharpNeat.Network |
| 18 | +{ |
| 19 | + public static class ActivationFunctionRegistry |
| 20 | + { |
| 21 | + // The default set of activation functions. |
| 22 | + private static Dictionary<string, IActivationFunction> __activationFunctionTable = new Dictionary<string, IActivationFunction>() |
| 23 | + { |
| 24 | + // Bipolar. |
| 25 | + { "BipolarSigmoid", BipolarSigmoid.__DefaultInstance }, |
| 26 | + { "BipolarGaussian", BipolarGaussian.__DefaultInstance }, |
| 27 | + { "Linear", Linear.__DefaultInstance }, |
| 28 | + { "Sine", Sine.__DefaultInstance }, |
| 29 | + |
| 30 | + // Unipolar. |
| 31 | + { "ArcSinH", ArcSinH.__DefaultInstance }, |
| 32 | + { "ArcTan", ArcTan.__DefaultInstance }, |
| 33 | + { "Gaussian", Gaussian.__DefaultInstance }, |
| 34 | + { "LeakyReLU", LeakyReLU.__DefaultInstance }, |
| 35 | + { "LeakyReLUShifted", LeakyReLUShifted.__DefaultInstance }, |
| 36 | + { "LogisticFunction", LogisticFunction.__DefaultInstance }, |
| 37 | + { "LogisticFunctionSteep", LogisticFunctionSteep.__DefaultInstance }, |
| 38 | + { "MaxMinusOne", MaxMinusOne.__DefaultInstance }, |
| 39 | + { "PolynomialApproximantSteep", PolynomialApproximantSteep.__DefaultInstance }, |
| 40 | + { "QuadraticSigmoid", QuadraticSigmoid.__DefaultInstance }, |
| 41 | + { "ReLU", ReLU.__DefaultInstance }, |
| 42 | + { "ScaledELU", ScaledELU.__DefaultInstance }, |
| 43 | + { "SoftSignSteep", SoftSignSteep.__DefaultInstance }, |
| 44 | + { "SReLU", SReLU.__DefaultInstance }, |
| 45 | + { "SReLUShifted", SReLUShifted.__DefaultInstance }, |
| 46 | + { "TanH", TanH.__DefaultInstance }, |
| 47 | + |
| 48 | + // Radial Basis. |
| 49 | + { "RbfGaussian", RbfGaussian.__DefaultInstance }, |
| 50 | + }; |
| 51 | + |
| 52 | + #region Public Static Methods |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Registers a custom activation function in addition to those in the default activation function table. |
| 56 | + /// Alows loading of neural nets from XML that use custom activation functions. |
| 57 | + /// </summary> |
| 58 | + public static void RegisterActivationFunction(IActivationFunction function) |
| 59 | + { |
| 60 | + if(!__activationFunctionTable.ContainsKey(function.FunctionId)) { |
| 61 | + __activationFunctionTable.Add(function.FunctionId, function); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /// <summary> |
| 66 | + /// Gets an IActivationFunction with the given short name. |
| 67 | + /// </summary> |
| 68 | + public static IActivationFunction GetActivationFunction(string name) |
| 69 | + { |
| 70 | + if(!__activationFunctionTable.ContainsKey(name)) { |
| 71 | + throw new ArgumentException($"Unexpected activation function [{name}]"); |
| 72 | + } |
| 73 | + return __activationFunctionTable[name]; |
| 74 | + } |
| 75 | + |
| 76 | + #endregion |
| 77 | + } |
| 78 | +} |
0 commit comments