Socket
Socket
Sign inDemoInstall

fmin

Package Overview
Dependencies
125
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fmin

Unconstrained funcion minimization in Javascript


Version published
Weekly downloads
138K
increased by3.63%
Maintainers
1
Install size
6.74 MB
Created
Weekly downloads
 

Readme

Source

fmin Build Status

Unconstrained function minimization in javascript.

This package implements some basic numerical optimization algorithms: Nelder-Mead, Gradient Descent, Wolf Line Search and Non-Linear Conjugate Gradient methods are all provided.

Interactive visualizations with D3 explaining how these algorithms work are also included in this package. Descriptions of the algorithms as well as most of the visualizations are available on my blog post An Interactive Tutorial on Numerical Optimization.

Installing

If you use NPM, npm install fmin. Otherwise, download the latest release.

API Reference

# nelderMead(f, initial)

Uses the Nelder-Mead method to minimize a function f starting at location initial.

Example usage minimizing the function f(x, y) = x2 + y2 + x sin y + y sin x is: nelder mead demo

function loss(X) {
    var x = X[0], y = X[1];
    return Math.sin(y) * x  + Math.sin(x) * y  +  x * x +  y *y;
}

var solution = fmin.nelderMead(loss, [-3.5, 3.5]);
console.log("solution is at " + solution.x);

# conjugateGradient(f, initial)

Minimizes a function using the Polak–Ribière non-linear conjugate gradient method . The function f should compute both the loss and the gradient.

An example minimizing Rosenbrock's Banana function is:

conjugate gradient demo

function banana(X, fxprime) {
    fxprime = fxprime || [0, 0];
    var x = X[0], y = X[1];
    fxprime[0] = 400 * x * x * x - 400 * y * x + 2 * x - 2;
    fxprime[1] = 200 * y - 200 * x * x;
    return (1 - x) * (1 - x) + 100 * (y - x * x) * (y - x * x);
}

var solution = fmin.conjugateGradient(banana, [-1, 1]);
console.log("solution is at " + solution.x);

Keywords

FAQs

Last updated on 25 Nov 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc