Skip to main content

APEC (Asymmetric Parametric Exponential Curvature) activation function.

Project description

APEC and MAPEC Activation Functions for Neural Networks

Overview

This 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).

Installation

pip install apec-afn

Usage

import torch
from apec import MAPEC

x = torch.randn([8])
f = MAPEC()

print(f(x))

Activation Functions

  • APEC: 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 Formulation

APEC (Asymmetric Parametric Exponential Curvature)

APEC

APEC is designed to introduce a non-linear response with an adjustable curvature, defined by: $$f(x) = a + \frac{b - x}{(g - \exp(-x)) + \epsilon}$$

  • Initialization: Parameters a and b are initialized with a normal distribution of zero mean and a standard deviation of 0.35. Parameter g is initialized with a mean of -1.375 and a standard deviation of 0.35.
  • Constraints: The default constraints for a, b, and g are [-2.0, +2.0], [-2.5, +2.5], and [-2.5, -0.25], respectively.
  • Stability: A small constant eps (1.0e-5) is added to prevent division by zero.

MAPEC (Multiplicative Asymmetric Parametric Exponential Curvature)

MAPEC

MAPEC extends APEC by adding a multiplicative term, enhancing its flexibility: $$f(x) = a + \frac{b - x}{-abs(g) - \exp(-x) - \epsilon} + (x \cdot d)$$

  • Initialization: Parameters a, b, and d are initialized to 0.0, and g is initialized to -1.0.
  • Constraints: There are no constraints on the parameters for MAPEC, allowing for a fully adaptive response.
  • Stability: A small constant eps (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.

Evaluation

To evaluate a model with a specific activation function on CIFAR-100 and plot training loss*, use:

python scripts/eval_cifar100.py --activation APEC --plot-loss

* Plotting training loss requires self-projection package to be installed.

Results

Evaluation results on CIFAR-100:

Activation Average Loss Accuracy
APEC 2.2235 43%
MAPEC 20e* 2.3301 42%
MAPEC 15e* 2.2509 42%
Mish 2.2704 43%
SELU 2.2674 42%
PReLU 2.2759 42%
ReLU 2.3933 39%

* Results provided for training with MAPEC activation for 20 and 15 epochs respectively.

APEC leads to the best performance, closely followed by Mish and SELU.

MAPEC leads to the faster convergence with performance closely to APEC.

You could look at training loss plots here.

Contributing

Contributions and suggestions are welcome! Feel free to fork the repository, open issues, and submit pull requests.

License

APEC is released under the MIT License. See the LICENSE file for more details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apec-afn-0.1.2.tar.gz (5.2 kB view details)

Uploaded Source

Built Distribution

apec_afn-0.1.2-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file apec-afn-0.1.2.tar.gz.

File metadata

  • Download URL: apec-afn-0.1.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for apec-afn-0.1.2.tar.gz
Algorithm Hash digest
SHA256 7bde0aaa693ce46ee6b0a41ff243dfc106243cfd393d8107dbbbcd81b07e1d95
MD5 1405126c78d49bb0a4b35c6c6f3358a5
BLAKE2b-256 cd5cd0f39277913b94393748e523f133863bf5563874db64fd7f8450bf5c7741

See more details on using hashes here.

File details

Details for the file apec_afn-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: apec_afn-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.7

File hashes

Hashes for apec_afn-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 247753629c29a5e27cc39c205e055a5bde5d3c4abca07bb5a4e0ebc0f03ef290
MD5 2fa6412f12782b026cb06e1f58fe59b1
BLAKE2b-256 1f9949346e75b76c50469e441e284ce043f930a065d509e74efe4e2e3d9e2b83

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page