Skip to main content

Fractional derivatives based gradient descent optimizers for PyTorch

Project description

Fractional Gradient Descent Optimizers for PyTorch

This package implements a novel approach to gradient descent by incorporating fractional derivatives into the update rules of popular optimization algorithms. Built on top of PyTorch, the optimizers in this package (SGD, AdaGrad, RMSProp, and Adam) can leverage both CPU and CUDA devices, making them versatile for a wide range of applications.

Overview

Fractional derivatives extend the traditional concept of differentiation, offering a more generalized framework that can capture memory and hereditary properties of complex systems. In this package, a custom fractional gradient operator is provided that modifies the gradient computation based on a user-defined fractional order (alpha). This operator can be optionally integrated into any of the available optimizers, allowing for experimental research into fractional gradient descent methods.

Features

  • Multiple Optimizers: Custom implementations for SGD, AdaGrad, RMSProp, and Adam.

  • Fractional Derivative Operator: Modify gradient updates using a fractional derivative, with an adjustable parameter alpha.

  • Seamless Integration: Easily swap between standard and fractional gradient descent by providing (or omitting) the operator.

  • PyTorch-Based: Built on top of PyTorch, ensuring compatibility with existing models and the autograd system.

  • CPU and CUDA Support: Run your experiments on both CPU and GPU.

Installation

Ensure you have PyTorch installed. You can install PyTorch by following the instructions at PyTorch.org.

Clone this repository and add it to your Python path:

git clone https://github.com/your_username/fractional-optimizers.git
cd fractional-optimizers
pip install -r requirements.txt

Usage

To use the fractional optimizers, import the desired optimizer and the fractional operator, then pass your model parameters and operator to the optimizer.

Example

import torch
import torch.nn as nn
import torch.nn.functional as F
from FracGrad import SGD, AdaGrad, RMSProp, Adam
from operators import fractional

# Define a simple model
model = nn.Linear(10, 1)

# Choose a fractional operator with a specific order (alpha)
frac_operator = fractional(alpha=0.9)

# Initialize an optimizer; here we use SGD with the fractional operator
optimizer = SGD(model.parameters(), operator=frac_operator, lr=0.03)

# Training loop example
for data, target in dataloader:
    optimizer.zero_grad()
    output = model(data)
    loss = F.mse_loss(output, target)
    loss.backward()
    optimizer.step()

File Structure

  • operators.py: Contains the implementation of the fractional class, which defines the fractional derivative operator. This operator adjusts the gradient based on the fractional order.

  • optimizers.py: Implements custom versions of standard optimizers (SGD, AdaGrad, RMSProp, and Adam). Each optimizer is designed to optionally use the fractional operator for modified gradient updates.

Contributing

Contributions, suggestions, and bug reports are welcome! Feel free to open an issue or submit a pull request.

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

fracgrad-0.1.0.tar.gz (9.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

FracGrad-0.1.0-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

Details for the file fracgrad-0.1.0.tar.gz.

File metadata

  • Download URL: fracgrad-0.1.0.tar.gz
  • Upload date:
  • Size: 9.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for fracgrad-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cd3dfd65f4dc6405788c3df6d7427088926ae34d3b370aef071d5f4800aab791
MD5 ff2d7f57cb1e9f0c8fc13f40c84151e9
BLAKE2b-256 5f28855ec36cdc8ee6ce78ecc001d36e41b7643dd715507b104d4ccefc467b92

See more details on using hashes here.

File details

Details for the file FracGrad-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: FracGrad-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.7

File hashes

Hashes for FracGrad-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 56d065fd3742617fdaaf8182201ce1cdd772abc2eb700c5dd91c137848a6b51c
MD5 253de0c0da8abbc4cd01f472d3e984ee
BLAKE2b-256 87f7648089cbe84777a93e500078dee45296c1ff8c2db75607c6dc21f00d305c

See more details on using hashes here.

Supported by

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