MyNixOS website logo
Description

Unified interface to various numerical optimization algorithms.

numeric-optimization

Hackage Hackage Deps License

Unified interface to various numerical optimization algorithms.

The aim of the package is to provide a convenient interface like Python's scipy.optimize.

Note that the package name is numeric-optimization and not numerical-optimization. The name numeric-optimization comes from the module name Numeric.Optimization.

Example Usage

{-# LANGUAGE OverloadedLists #-}
import Data.Vector.Storable (Vector)
import Numeric.Optimization

main :: IO ()
main = do
  result <- minimize LBFGS def (WithGrad rosenbrock rosenbrock') [-3,-4]
  print (resultSuccess result)  -- True
  print (resultSolution result)  -- [0.999999999009131,0.9999999981094296]
  print (resultValue result)  -- 1.8129771632403013e-18

-- https://en.wikipedia.org/wiki/Rosenbrock_function
rosenbrock :: Vector Double -> Double
rosenbrock [x,y] = sq (1 - x) + 100 * sq (y - sq x)

rosenbrock' :: Vector Double -> Vector Double
rosenbrock' [x,y] =
  [ 2 * (1 - x) * (-1) + 100 * 2 * (y - sq x) * (-2) * x
  , 100 * 2 * (y - sq x)
  ]

sq :: Floating a => a -> a
sq x = x ** 2

Supported Algorithms

AlgorithmSolver implementionHaskell binding
CG_DESCENTCG_DESCENT-Cnonlinear-optimizationRequires with-cg-descent flag
Limited memory BFGS (L-BFGS)liblbfgslbfgs
Limited memory BFGS with bounds constraints (L-BFGS-B)L-BFGS-Bl-bfgs-bRequires with-lbfgsb flag
Newton's methodPure Haskell implementation using HMatrix-

Installation

Installing Prerequisites

BLAS and LAPACK

You may need to install BLAS and LAPACK for hmatrix.

Windows (MSYS2):
$ pacman -S mingw-w64-x86_64-lapack

or if you use MSYS2 installed by stack

$ stack exec -- pacman -S mingw-w64-x86_64-lapack
Debian and Ubuntu Linux:
$ apt-get install libblas-dev liblapack-dev

libblas-dev and liblapack-dev are reference implementations. You need to install optimized ones for better performance. (See DebianScience/LinearAlgebraLibraries)

macOS

By default hmatrix uses BLAS and LAPACK provided by Accelerate Framework provided by macOS.

liblbfgsb

If you want to use L-BFGS-B, you have to install the development package of liblbfgsb.

Ubuntu Linux:
$ apt-get install liblbfgsb-dev
Homebrew (macOS and Linux):
$ brew install msakai/tap/liblbfgsb
Windows (MSYS2):
$ wget https://github.com/msakai/mingw-w64-liblbfgsb/releases/download/v3.0-1/mingw-w64-x86_64-liblbfgsb-3.0-1-any.pkg.tar.zst
$ pacman -U mingw-w64-x86_64-liblbfgsb-3.0-1-any.pkg.tar.zst

or if you use MSYS2 installed by stack

$ wget https://github.com/msakai/mingw-w64-liblbfgsb/releases/download/v3.0-1/mingw-w64-x86_64-liblbfgsb-3.0-1-any.pkg.tar.zst
$ stack exec -- pacman -Sy
$ stack exec -- pacman -U mingw-w64-x86_64-liblbfgsb-3.0-1-any.pkg.tar.zst

Related Packages

LICENSE

The code in thie packaged is licensed under BSD-3-Clause.

If you enable with-cg-descent flag, it uses GPL-licensed packages and the resulting binary should be distributed under GPL.

Metadata

Version

0.1.1.0

Platforms (75)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-darwin
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-darwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows