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.2.tar.gz (10.0 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.2-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fracgrad-0.1.2.tar.gz
  • Upload date:
  • Size: 10.0 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.2.tar.gz
Algorithm Hash digest
SHA256 a1d1aa7735a154ab489f438362484e73cafc47beff691e44188e5bc411fd4939
MD5 57145eb423be447c4f3b8b947fd5d462
BLAKE2b-256 a0f58d86d70eb3e11dc3e5b41939f9a2b65933d70ed06b5b2342aed2bacb2d86

See more details on using hashes here.

File details

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

File metadata

  • Download URL: FracGrad-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 10.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a9825f1d81465a412296dd10205e20997ca9e00344dbebe0b44afdb716658395
MD5 a35d02c38c3a32f09b0f546ed0ed0073
BLAKE2b-256 2f7f1b4a474aacaeb895dd0047ce345a056e660f521d89b26f76d5298f9b6f56

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