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:

pip install FracGrad

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.1.tar.gz (9.4 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.1-py3-none-any.whl (10.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fracgrad-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 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.1.tar.gz
Algorithm Hash digest
SHA256 16313503e5ea2d60c0291069fbc20be56582ab306200c7c31b866d3ce6f3a644
MD5 a37e0f80d2d4edd8d54f46ce812c157e
BLAKE2b-256 20c06cbdfc419f7ab2d1a81a2020193696d351bd3c4fa296f89a6c97cd7f51e2

See more details on using hashes here.

File details

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

File metadata

  • Download URL: FracGrad-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5de0fb127e8b7626e701d3759d300daffa8e57254d385e0e4b164112007098d7
MD5 6b9378359f9d1f2a3d1e917e487b4094
BLAKE2b-256 821048740f3a6166d219b1922ac994ad73cc0403b6ea091487923e04ec59360c

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