This repository offers a Python code for the PyTorch implementation of the APTx Neuron and experimentation on MNIST dataset, as introduced in the paper "APTx Neuron: A Unified Trainable Neuron Architecture Integrating Activation and Computation".
Paper Title: APTx Neuron: A Unified Trainable Neuron Architecture Integrating Activation and Computation
Author: Ravin Kumar
Sources:
- APTx Neuron (Pytorch + PyPI Package): APTx Neuron
- APTx Activation Function (Pytorch + PyPI Package): APTx Activation Function
- Experimentation Results with MNIST (APTx Neuron): MNIST Experimentation Code
Kumar, Ravin. "APTx Neuron: A Unified Trainable Neuron Architecture Integrating Activation and Computation." arXiv preprint arXiv:2507.14270 (2025).
Or,
@article{kumar2025aptx,
title={APTx Neuron: A Unified Trainable Neuron Architecture Integrating Activation and Computation},
author={Kumar, Ravin},
journal={arXiv preprint arXiv:2507.14270},
year={2025}
}
Abstract: We propose the APTx Neuron, a novel, unified neural computation unit that integrates non-linear activation and linear transformation into a single trainable expression. The APTx Neuron is derived from the APTx activation function, thereby eliminating the need for separate activation layers and making the architecture both computationally efficient and elegant. The proposed neuron follows the functional form
The APTx Neuron is a novel computational unit that unifies linear transformation and non-linear activation into a single, expressive formulation. Inspired by the parametric APTx activation function, this neuron architecture removes the strict separation between computation and activation, allowing both to be learned as a cohesive entity. It is designed to enhance representational flexibility while reducing architectural redundancy.
Traditionally, a neuron computes the output as:
where:
-
$x_i$ are the inputs, -
$w_i$ are the weights, -
$b$ is the bias, - and
$\phi$ is an activation function such as ReLU, Swish, or Mish.
The APTx Neuron merges these components into a unified trainable expression as:
where:
-
$x_i$ is the$i$ -th input feature, -
$\alpha_i$ ,$\beta_i$ , and$\gamma_i$ are trainable parameters for each input, -
$\delta$ is a trainable scalar bias.
This equation allows the neuron to modulate each input through a learned, per-dimension non-linearity and scaling operation. The term
pip install aptx_neuron
or,
pip install git+https://github.com/mr-ravin/aptx_neuron.git
1. APTx Neuron-based Layer with all
The setting is_alpha_trainable = True
keeps is_alpha_trainable
is True
.
import aptx_neuron
input_dim = 8 # assuming input vector to be of dimension 8.
output_dim = 1 # assuming output dimension equals 1.
aptx_neuron_layer = aptx_neuron.aptx_layer(input_dim=input_dim, output_dim=output_dim, is_alpha_trainable=True)
2. APTx Neuron-based Layer with
The setting is_alpha_trainable = False
makes
import aptx_neuron
input_dim = 8 # assuming input vector to be of dimension 8.
output_dim = 1 # assuming output dimension equals 1.
aptx_neuron_layer = aptx_neuron.aptx_layer(input_dim=input_dim, output_dim=output_dim, is_alpha_trainable=False) # Ξ±_i is fixed (not trainable)
Run the below command to train an APTx Neuron-based fully-connected neural network on the MNIST dataset. The model will automatically save training loss
and accuracy
values in the ./result/
directory.
Note: For this MNIST experimentation, we have hardcoded is_alpha_trainable=True
inside run.py
.
If you wish to explore the full flexibility and modularity of APTx Neuron (including toggling Ξ± trainability), we recommend using the official PyPI package:
pip install aptx-neuron
Or, install directly from GitHub:
pip install git+https://github.com/mr-ravin/aptx_neuron.git
1. Model Training
To train the model from scratch (using Python 3.12.11 on cpu):
python3 run.py --total_epoch 20
This command will:
- Train the model on MNIST
- Save training and validation loss/accuracy in the ./result/ directory
- Use the default device: cpu
2. Model Inference
To perform inference on the test set using the trained model (reproducibility mode):
python3 run.py --mode infer --device cpu
-
β Test Accuracy: 96.69%
-
π Model Weights File:
./weights/aptx_neural_network_11.pt
-
π» Environment: Python
3.12.11
, Pytorch>=1.8.0
, and Device:cpu
-
Command:
python3 run.py --mode infer --device cpu --load_model_weights_path ./weights/aptx_neural_network_11.pt
Epoch | Train Loss | Test Loss | Train Accuracy (%) | Test Accuracy (%) |
---|---|---|---|---|
1 | 85.58 | 36.73 | 84.16 | 89.12 |
2 | 33.27 | 17.82 | 90.16 | 90.76 |
3 | 19.97 | 28.16 | 91.80 | 90.82 |
4 | 9.98 | 27.00 | 92.55 | 90.66 |
5 | 15.28 | 24.45 | 93.59 | 93.03 |
6 | 13.88 | 9.13 | 97.11 | 96.33 |
7 | 9.35 | 8.84 | 97.47 | 95.53 |
8 | 0.00 | 7.73 | 97.38 | 95.51 |
9 | 1.10 | 9.19 | 97.51 | 94.47 |
10 | 6.41 | 8.69 | 97.56 | 95.59 |
11 | 0.00 | 6.81 | 98.75 | 96.69 |
12 | 0.00 | 6.57 | 99.11 | 96.53 |
13 | 0.00 | 6.67 | 99.19 | 96.57 |
14 | 0.00 | 7.29 | 99.21 | 96.40 |
15 | 0.00 | 6.90 | 99.23 | 96.46 |
16 | 0.00 | 6.25 | 99.60 | 96.63 |
17 | 0.00 | 6.21 | 99.77 | 96.58 |
18 | 0.00 | 6.02 | 99.79 | 96.65 |
19 | 0.00 | 5.95 | 99.78 | 96.68 |
20 | 0.00 | 6.13 | 99.81 | 96.56 |
β Best Test Accuracy:
96.69%
at Epoch 11
π Indicates potential for further improvement with better optimization or deeper architecture.
This work introduced the APTx Neuron, a unified, fully trainable neural unit that integrates linear transformation and non-linear activation into a single expression, extending the APTx activation function. By learning per-input parameters
Copyright (c) 2025 Ravin Kumar
Website: https://mr-ravin.github.io
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the βSoftwareβ), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
Software.
THE SOFTWARE IS PROVIDED βAS ISβ, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.