Package: apec-afn
APEC and MAPEC Activation Functions for Neural NetworksAPEC and MAPEC Activation Functions for Neural NetworksOverviewInstallationUsageActivation FunctionsMathematical FormulationAPEC (Asymmetric Parametric Exponential Curvature)MAPEC (Multiplicative Asymmetric Parametric Exponential Curvature)EvaluationResultsContributingLicenseOverviewThis repository introduces two novel activation functions, APEC (Asymmetric Parametric Exponential Curvature) and its variant MAPEC (Multiplicative APEC), designed for deep learning models to capture complex patterns with improved performance. Functions have been tested on the CIFAR-100 dataset (results included) and on some of my experimental models (results not included).Installationpipinstallapec-afnUsageimporttorchfromapecimportMAPECx=torch.randn([8])f=MAPEC()print(f(x))Activation FunctionsAPEC: Offers a balance between flexibility and performance, as demonstrated by the improvement over traditional functions on CIFAR-100.MAPEC: An extension of APEC with an additional multiplicative term, allowing for an even richer model expressiveness and an observed faster convergence (up to 15%).Mathematical FormulationAPEC (Asymmetric Parametric Exponential Curvature)APEC is designed to introduce a non-linear response with an adjustable curvature, defined by:
$$f(x) = \alpha + \frac{\beta - x}{(\gamma - \exp(-x)) + \epsilon}$$Initialization: Parametersaandbare initialized with a normal distribution of zero mean and a standard deviation of 0.35. Parametergis initialized with a mean of -1.375 and a standard deviation of 0.35.Constraints: The default constraints fora,b, andgare [-2.0, +2.0], [-2.5, +2.5], and [-2.5, -0.25], respectively.Stability: A small constanteps(1.0e-5) is added to prevent division by zero.MAPEC (Multiplicative Asymmetric Parametric Exponential Curvature)MAPEC extends APEC by adding a multiplicative term, enhancing its flexibility:
$$f(x) = (\alpha + \frac{\beta - x}{-abs(\gamma) - \exp(-x) - \epsilon} + (x \cdot \delta)) \cdot \zeta$$Initialization: Parameters initialization values are -3.333e-2, -0.1, -2.0, +0.1 and +1.0 for alpha, beta, gamma, delta and zeta respectively.Constraints: There are no constraints on the parameters for MAPEC, allowing for a fully adaptive response.Stability: A small constanteps(1.0e-3) is subtracted from denominator to prevent division by zero.These functions aim to provide enhanced flexibility and adaptability for neural networks, particularly beneficial for complex pattern recognition tasks.EvaluationTo evaluate a model with a specific activation function on CIFAR-100 and plottraining loss*, use:pythonscripts/eval_cifar100.py--activationAPEC--plot-loss* Plotting training loss requiresself-projectionpackage to be installed.ResultsEvaluation results on CIFAR-100:ActivationAverage LossAccuracyMAPEC 16e*2.200443%APEC2.223543%MAPEC 20e*2.245643%Mish2.270443%SELU2.267442%PReLU2.275942%ReLU2.393339%* Results provided for training with MAPEC activation for 20 and 16 epochs respectively.APECleads to the best performance, closely followed by Mish and SELU.MAPECleads to the faster convergence with performance closely followed by APEC.You could look at training loss plotshere.ContributingContributions and suggestions are welcome! Feel free to fork the repository, open issues, and submit pull requests.LicenseAPECis released under the MIT License. See theLICENSEfile for more details.