Skip to main content

The gradient optimization library with barzilar borwein method.

Project description

barbor

The gradient optimization library with barzilar borwein method.

description

This PyTorch implementation of the Barzilai-Borwein (BB) gradient descent optimizer represents a sophisticated advancement beyond standard first-order optimization methods. The core innovation lies in its adaptive step size computation that approximates second-order curvature information without explicit Hessian calculation, addressing a fundamental limitation of fixed-learning-rate gradient descent.

The implementation introduces two complementary step size strategies: BB1 (α = s·s/s·y) and BB2 (α = s·y/y·y), where s represents parameter changes and y represents gradient differences between iterations. These formulas effectively capture local curvature, enabling the optimizer to automatically adjust step sizes based on problem geometry. The default alternating strategy intelligently switches between these variants, leveraging their complementary strengths—BB1 tends to be more stable while BB2 can achieve faster convergence.

A key innovation is the adaptive restart mechanism that prevents divergence in non-convex landscapes. The code implements three restart conditions: gradient orthogonality (when s and y become nearly orthogonal), negative gradient correlation (when consecutive gradients point in opposite directions), or a combined approach. This system allows the optimizer to reset to initial learning rates when progress stalls, effectively escaping regions of poor curvature.

The implementation also integrates momentum support (both standard and Nesterov variants) with the BB framework, creating a hybrid approach that combines momentum's acceleration with BB's curvature awareness. Comprehensive numerical safeguards—including regularization parameters, step size clamping, and division-by-zero protection—ensure robustness across diverse optimization landscapes.

Beyond the core algorithm, the optimizer provides extensive diagnostic tools for monitoring convergence behavior, including real-time step size tracking, gradient correlation metrics, and convergence statistics. This transparency allows users to understand the adaptive behavior and make informed adjustments.

The combination of curvature-aware step sizing, intelligent restart conditions, momentum integration, and robust numerical handling makes this implementation particularly valuable for non-convex optimization problems where traditional methods struggle with learning rate selection and convergence stability.

install barbor

pip install torch==2.1.0 --index-url https://download.pytorch.org/whl/cu121
pip install barbor

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

barbor-1.0.1.tar.gz (9.3 kB view details)

Uploaded Source

Built Distribution

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

barbor-1.0.1-py3-none-any.whl (9.0 kB view details)

Uploaded Python 3

File details

Details for the file barbor-1.0.1.tar.gz.

File metadata

  • Download URL: barbor-1.0.1.tar.gz
  • Upload date:
  • Size: 9.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.8.12

File hashes

Hashes for barbor-1.0.1.tar.gz
Algorithm Hash digest
SHA256 594d79309bcc2c7d9adfac00c4039e747903dbdd4de94ad30293326cb88310d5
MD5 518080d1afef6fa444370bfa45f8fcb7
BLAKE2b-256 cfacaa0bedfa082bf8853b82401ac4a30e73829a2febd6ac84982620bb95dbb7

See more details on using hashes here.

File details

Details for the file barbor-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: barbor-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/6.0.0 pkginfo/1.8.2 requests/2.27.0 requests-toolbelt/0.9.1 tqdm/4.64.1 CPython/3.8.12

File hashes

Hashes for barbor-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ef93449295fd381de5dc5db146ede6a05a3bc020e1f0072eea2cbaacfbc77a35
MD5 d1ae3ed42a6b8214bcfc3e9904a32133
BLAKE2b-256 7218de856c8d8003bedf53928338de3844644df56ae2721380ef565972e704bf

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