Observed since 20 Oct, 19:03 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
Adaptive Fractional Gradient Descent Optimizers (AdaFGD & AdaNCFGD)
The adancfgd package implements two advanced optimizers combining fractional gradient descent with adaptive learning rates, along with a comprehensive Spiking Neural Network (SNN) framework. Building on PyTorch's SGD, these algorithms enhance convergence and performance for machine learning tasks using fractional calculus-based gradient adjustments.
This package provides two novel optimization algorithms and a complete SNN implementation:
The package has been successfully uploaded to PyPI. You can install it directly from PyPI or from the source code.
pip install adancfgd
git clone https://github.com/HunLuanZhiZhu/AdaNCFGD.git
cd AdaNCFGD
pip install -e .
AdaFGD(params, lr=0.001, alpha=1.0, epsilon=1e-4, momentum=0.0, dampening=0.0, weight_decay=0.0, nesterov=False, betas=(0.9, 0.999), eps=1e-8, amsgrad=False, maximize=False, foreach=None, differentiable=False, fused=None)
Parameters:
params: Iterable of parameters to optimize or dicts defining parameter groupslr: Learning rate (default: 0.001)alpha: Fractional order (must satisfy 0 < alpha < 2, default: 1.0)epsilon: Small positive constant to avoid division by zero (default: 1e-4)momentum: Momentum factor (default: 0.0)dampening: Dampening for momentum (default: 0.0)weight_decay: Weight decay (L2 penalty, default: 0.0)nesterov: Enables Nesterov momentum (default: False)betas: Coefficients used for computing running averages of gradient and its square (default: (0.9, 0.999))eps: Term added to the denominator to improve numerical stability (default: 1e-8)amsgrad: Whether to use the AMSGrad variant (default: False)AdaNCFGD(params, lr=0.001, alpha=1.0, epsilon=1e-4, momentum=0.0, dampening=0.0, weight_decay=0.0, nesterov=False, betas=(0.9, 0.999), eps=1e-8, amsgrad=False, maximize=False, foreach=None, differentiable=False, fused=None)
Parameters:
SNNLinear(in_features, out_features, bias=True, window_t=100, threshold_voltage=15, initial_potential_ratio=0.5, w_mean=0, w_std=1, device=None, dtype=None)
SNNConv2d(input_shape, in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, window_t=100, threshold_voltage=15, initial_potential_ratio=0.5, w_mean=0, w_std=1, device=None, dtype=None)
SNNCNN(device=None, dtype=None)
import torch
import torch.nn as nn
from adancfgd import AdaFGD
# Create a simple model
model = nn.Linear(10, 1)
# Initialize optimizer with default parameters
optimizer = AdaFGD(model.parameters(), lr=0.001, alpha=1.0)
# Training loop
inputs = torch.randn(32, 10)
targets = torch.randn(32, 1)
criterion = nn.MSELoss()
for epoch in range(10):
optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, targets)
loss.backward()
optimizer.step()
print(f"Epoch {epoch+1}, Loss: {loss.item():.4f}")
import torch
import torch.nn as nn
from adancfgd import AdaNCFGD
# Create a simple CNN
model = nn.Sequential(
nn.Conv2d(3, 32, kernel_size=3, padding=1),
nn.ReLU(),
nn.MaxPool2d(2),
nn.Flatten(),
nn.Linear(32 * 16 * 16, 10)
)
# Initialize optimizer
optimizer = AdaNCFGD(model.parameters(), lr=0.0001, alpha=1.0, betas=(0.9, 0.999))
# Training loop (simplified)
inputs = torch.randn(32, 3, 32, 32)
targets = torch.randint(0, 10, (32,))
criterion = nn.CrossEntropyLoss()
for epoch in range(5):
optimizer.zero_grad()
outputs = model(inputs)
loss = criterion(outputs, targets)
loss.backward()
optimizer.step()
print(f"Epoch {epoch+1}, Loss: {loss.item():.4f}")
import torch
from adancfgd import SNNLinear, SNNConv2d, SNNDropout, SNNSequential
# Create a simple SNN model using SNNSequential
snn_model = SNNSequential(
SNNLinear(784, 256),
SNNDropout(p=0.5),
SNNLinear(256, 10)
)
# Create test data
spikes = torch.randn(10, 32, 784) # (time_steps, batch, features)
# Forward pass
output = snn_model.step(spikes)
print(f"Output shape: {output.shape}")
import torch
from adancfgd import SNNCNN
from adancfgd.train_mnist import train
# Create SNNCNN model
model = SNNCNN()
# Train on MNIST dataset
train(model, 'snncnn_test', epochs=10, batch_size=50)
AdaFGD and AdaNCFGD have been shown to converge faster than traditional optimizers like SGD and Adam for certain tasks, especially for models with complex loss landscapes.
For image classification tasks, these optimizers can achieve higher final accuracy compared to standard optimizers when used with appropriate hyperparameters.
The SNN implementation supports efficient training of spiking neural networks using surrogate gradients, achieving competitive performance with traditional ANN models on MNIST and other datasets.
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
If you use this package in your research, please consider citing:
@software{adancfgd2025,
author = {Yihe Zhu},
title = {adancfgd: Adaptive Fractional Gradient Descent Optimizers and SNN Framework},
year = {2025},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/HunLuanZhiZhu/AdaNCFGD}},
}
Download counts and popularity will appear here as the collector receives them.
| Version | Published | Direct dependencies | Open version |
|---|---|---|---|
| 0.1.5 | 14 Dec 2025 | 5 |
This describes our collected data; it is not a security assessment.
Observed since 20 Oct, 19:03 UTC
No superseded metadata states collected. Unchanged observations do not create new revisions.
package:5aa66d3b510fc9592eb80d82324ed0a752c5cbb3fdbb689f9df3728881f42196