Skip to main content

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) = \alpha + \frac{\beta - x}{(\gamma - \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) = (\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 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
MAPEC 16e* 2.2004 43%
APEC 2.2235 43%
MAPEC 20e* 2.2456 43%
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 16 epochs respectively.

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

MAPEC leads to the faster convergence with performance closely followed by 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.

Metadata

Release files for apec-afn 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apec-afn 0.1.3
File Size Uploaded Provenance Actions
apec-afn-0.1.3.tar.gz 5.4 kB Without provenance Details for apec-afn-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for apec-afn 0.1.3
File Interpreter ABI Platform Actions
apec_afn-0.1.3-py3-none-any.whl Python 3 none any Details for apec_afn-0.1.3-py3-none-any.whl

Total release size: 11.0 kB

Release files / apec-afn-0.1.3.tar.gz

Download URL apec-afn-0.1.3.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d1b2f4ae08a7e2c8d5beb3e23da245339f202e6c17df93a60acb24f07fe2a7fd
BLAKE2b-256 checksum
How to use checksums
0a9cbe0839e243270cbb2ae98823ccbf7b1a2d445c60f778f8bbb3742ca73bbf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Release files / apec_afn-0.1.3-py3-none-any.whl

Download URL apec_afn-0.1.3-py3-none-any.whl
Size 5.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
38e1b7206f3e8e81963502510bb3d989fb7cd5ae05167fd2b2c7ee1377df683a
BLAKE2b-256 checksum
How to use checksums
16926c5c99e524b6c053671bbcf7d6b8b8aa9b5b7eeab5d56413a9d26d71cf63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.7

Security for apec-afn 0.1.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page