Skip to main content

Very Fast Gradient-Based Optimization Algorithm

Project description

mizoGrad: Search & Accelerate Gradient-Based Algorithm

Description

This module is dedicated to the implementation of the Gradient-based box constrained optimization proposed in this paper.

This algorithm combines the following features:

  • Line search along the gradient line
  • Line search along the acceleration path
  • Provable asymptotic convergence to a solution meeting the KKT-optimality conditions.

The abobe mentioned paper shows that the algorithm outperfoms almost all existing gradient-based methods on a set of benchmark problems proposed in the kaggle repository.

Installation

pip install mizoGrad

Input arguments

The user needs to provide the following mandatory input arguments:

  • The first, say cost, represents the cost functiont to be minimized
  • The second, say cost_gradient, is the gradient of the same cost funciton
  • The number of decision variables nx

Note: The names cost and cost_gradient are just examples, any names can be used; only their key fields are detremined which are f and g respectively (see the example below).

The complete list of input parameters (including all those with defaults values) is given on the following table:

Parameter Type Default Description
f callable Cost function to minimize
g callable Gradient of the cost function
nx int Number of decision variables
xmin ndarray [-inf] * nx Lower bound on the decision variable
xmax ndarray [+inf] * nx Upper bound on the decision variable
ng int 5 Number of exploration points
alpha_min float -8 lower initial exponent on the step
alpha_max float 0 Higher initial exponent on the step
ng int 5 Number of exploration points
fast_min float -0.2 Maximum number of iterations
fast_max float 1 Maximum number of iterations
rho_adapt float 0.05 Adaptation ratio
eta float 10^{-16} Small step (<1/L)

Returned solution

The returned solution is a dictionary with the following format:

Dictionary key Type of value Description
xopt ndarray The best solution found
fopt float The corresponding best cost function value
normG float The norm of the gradient at solution
lesalpha_min ndarray The sequence of values taken by alpha_min
lesalpha_max ndarray The sequence of values taken by alpha_max
traj ndarray The sequence of values of the cost
traj_c ndarray The sequence of step sizes on the acceleration direction

Example of use

import numpy as np
from mizoGrad import GradOptimizer
from time import time

#from SaA import GradOptimizer

np.set_printoptions(formatter={'float': lambda x: "{0:0.4f}".format(x)})

# Define the cost function and the gradient

def cost(x, a=10, b=2, m=1):

    f = np.power((x[0]-a)*x[1] + b * x[2] ** 3, 2*m)
    return f

def cost_gradient(x, a=10, b=2, m=1):
    term = 4 * np.power((x[0]-a)*x[1] + b * x[2] ** 3, 2*m-1)
    g = np.array([
        term * x[1],
        term * (x[0]-a),
        term * (3 * b * x[2] ** 2)
    ])
    return g


x0 = 2*np.array([1,1,1])

xmin = np.array([-5] * len(x0))
xmax = np.array([+5] * len(x0))

s2a = GradOptimizer(
    f=cost,
    g=cost_gradient,
    nx = 3,
    xmin=xmin,
    xmax=xmax,
    ng=5,
    alpha_min=-8,
    alpha_max=0,
    fast_min=-0.2,
    fast_max=1.0,
    rho_adapt=0.05,
    eta=1e-16,
)

# set the dictionary argument used the cost function and gradient 

kwargs = dict(
    a=3,
    b=1,
    m=1,
)

# solve the problem

t1 = time()
R = s2a.solve(x0=x0, kwargs=kwargs, maxIter=20, epsG=1e-8, display=True)
cpu = time()-t1

print('solution: ', np.array(R['xopt'], dtype=float))
print('best cost : ', cost(s2a.y, **kwargs))
print('cpu = ', cpu)

which gives the following results:

value 9.374756801 normg=292.957 | alpha_min=-8.0 | alpha_max=-0.4
value 3.931283917 normg=31.930 | alpha_min=-8.0 | alpha_max=-0.78
value 1.109572100 normg=17.759 | alpha_min=-7.962 | alpha_max=-0.419
value 0.000013588 normg=6.499 | alpha_min=-7.922 | alpha_max=-0.04185
value 0.000000666 normg=0.066 | alpha_min=-7.922 | alpha_max=-0.4359
value 0.000000029 normg=0.015 | alpha_min=-7.922 | alpha_max=-0.8102
value 0.000000000 normg=0.003 | alpha_min=-7.922 | alpha_max=-1.166
value 0.000000000 normg=0.000 | alpha_min=-7.922 | alpha_max=-1.504
value 0.000000000 normg=0.000 | alpha_min=-7.922 | alpha_max=-1.825
value 0.000000000 normg=0.000 | alpha_min=-7.89 | alpha_max=-1.52
value 0.000000000 normg=0.000 | alpha_min=-7.89 | alpha_max=-1.838
value 0.000000000 normg=0.000 | alpha_min=-7.859 | alpha_max=-1.536
value 0.000000000 normg=0.000 | alpha_min=-7.859 | alpha_max=-1.852
solution:  [1.7020 -1.2326 -1.1696]
best cost :  8.860672896017431e-21
cpu =  0.0008881092071533203

Citing mizoGrad

@misc{alamir2026nonlinearmodelpredictivecontrol,
      title={A Nonlinear Model Predictive Control Perspective on Gradient-Based Optimization: A New Efficient, Parameter-Free and Provably Stable Algorithm}, 
      author={Mazen Alamir},
      year={2026},
      eprint={2607.14600},
      archivePrefix={arXiv},
      primaryClass={cs.CE},
      url={https://arxiv.org/abs/2607.14600}, 
}

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

mizograd-0.1.2.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

mizograd-0.1.2-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: mizograd-0.1.2.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for mizograd-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b6d261deb5206a189d93e1f6e6bb078af933ea79047d1ade83f39403ce434b8a
MD5 83009e4577cd6e528f233247244582d2
BLAKE2b-256 f7b1fd0eaa96ca8e213ab7acbccd4cfa055db9d58d80cab7a8b21bc2b889e70b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mizograd-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.7

File hashes

Hashes for mizograd-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 802ebafd567ec40b1b41c0b0153c9f8c23aaa937dbfe69f504e1572ff9945178
MD5 288a1e7f5c1971fe3db127317f9803bf
BLAKE2b-256 cf8dc295c96e86d88caf0c734bfcc1b6c6e847e5588135d75329014a829867cf

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