Giter VIP home page Giter VIP logo

autoptim's Introduction

autoptim: automatic differentiation + optimization

Do you have a new machine learning model that you want to optimize, and do not want to bother computing the gradients? Autoptim is for you.

Warning:

As of version 0.3, pytorch has been replaced with autograd for automatic differentiation. It makes the interfacing with numpy even simpler.

Short presentation

Autoptim is a small Python package that blends autograd's automatic differentiation in scipy.optimize.minimize.

The gradients are computed under the hood using automatic differentiation; the user only provides the objective function:

import numpy as np
from autoptim import minimize


def rosenbrock(x):
    return (1 - x[0]) ** 2 + 100 * (x[1] - x[0] ** 2) ** 2


x0 = np.zeros(2)

x_min, _ = minimize(rosenbrock, x0)
print(x_min)

>>> [0.99999913 0.99999825]

It comes with the following features:

  • Natural interfacing with Numpy: The objective function is written in standard Numpy. The input/ output of autoptim.minimize are Numpy arrays.

  • Smart input processing: scipy.optimize.minimize is only meant to deal with one-dimensional arrays as input. In autoptim, variables can be multi-dimensional arrays or lists of arrays.

  • Preconditioning: Preconditioning is a simple way to accelerate minimization, by doing a change of variables. autoptim makes preconditioning straightforward.

Disclaimer

This package is meant to be as easy to use as possible. As so, some compromises on the speed of minimization are made.

Installation

To install, use pip:

pip install autoptim

Dependencies

  • numpy>=1.12
  • scipy>=0.18.0
  • autograd >= 1.2

Examples

Several examples can be found in autoptim/tutorials

autoptim's People

Contributors

pierreablin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

autoptim's Issues

Syntax error in Python 2.7

I get a syntax error using old Python 2.7 due to double splat unpacking in _scipy_func at this line:

obj = objective_function(*torch_vars, *args)

A fix that worked for me was to use functools.partial like so

of = partial(objective_function, *args)
obj = of(*torch_vars)

Thanks for the very handy library!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.