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.0.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.

barbor-1.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: barbor-1.0.0.tar.gz
  • Upload date:
  • Size: 9.4 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.0.tar.gz
Algorithm Hash digest
SHA256 8ffc46eaac1affdb9a4b8c94cc745848616d3b4e3ee4d8990f5a321152ee3e20
MD5 27a31f7e6f339b6296972a3d902fcd2e
BLAKE2b-256 fb61e7b1ef216a23523ac0a7451e58a37644247dba8207ad5598abca8737017c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: barbor-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3beb8111d259b7ac92465a50c6136425e5443e2f16361b8f459c8e0b633a586b
MD5 cfe701323c7b19f88faaaae98ea93350
BLAKE2b-256 d96c0b2410144b302ed1e797b8487b667c81f1efe389f0bdbafa015b31630208

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