{"id":13399543,"url":"https://github.com/benfred/fmin","last_synced_at":"2025-05-14T14:09:34.979Z","repository":{"id":57132492,"uuid":"74711389","full_name":"benfred/fmin","owner":"benfred","description":" Unconstrained function minimization in Javascript","archived":false,"fork":false,"pushed_at":"2024-10-29T16:57:13.000Z","size":1413,"stargazers_count":362,"open_issues_count":11,"forks_count":65,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-05-13T23:52:08.205Z","etag":null,"topics":["numerical-optimization","optimization-algorithms","visualization"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-3-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/benfred.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-24T23:39:25.000Z","updated_at":"2025-03-31T22:45:28.000Z","dependencies_parsed_at":"2024-11-15T17:01:29.972Z","dependency_job_id":null,"html_url":"https://github.com/benfred/fmin","commit_stats":{"total_commits":17,"total_committers":3,"mean_commits":5.666666666666667,"dds":"0.11764705882352944","last_synced_commit":"6b155c9f4a6ecf73ea5d71666da8e5dcd418b18b"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benfred%2Ffmin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benfred%2Ffmin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benfred%2Ffmin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/benfred%2Ffmin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/benfred","download_url":"https://codeload.github.com/benfred/fmin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254160425,"owners_count":22024568,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["numerical-optimization","optimization-algorithms","visualization"],"created_at":"2024-07-30T19:00:39.223Z","updated_at":"2025-05-14T14:09:29.956Z","avatar_url":"https://github.com/benfred.png","language":"JavaScript","readme":"# fmin [![Build Status](https://travis-ci.org/benfred/fmin.svg?branch=master)](https://travis-ci.org/benfred/fmin)\n\nUnconstrained function minimization in javascript.\n\nThis package implements some basic numerical optimization algorithms: Nelder-Mead, Gradient\nDescent, Wolf Line Search and Non-Linear Conjugate Gradient methods are all provided.\n\nInteractive visualizations with D3 explaining how these algorithms work are also included in this package.\nDescriptions of the algorithms as well as most of the visualizations are available on my blog post\n[An Interactive Tutorial on Numerical\nOptimization](http://www.benfrederickson.com/numerical-optimization/).\n\n## Installing\n\nIf you use NPM, `npm install fmin`. Otherwise, download the [latest release](https://github.com/benfred/fmin/releases/latest).\n\n## API Reference\n\n\u003ca href=\"#nelderMead\" name=\"nelderMead\"\u003e#\u003c/a\u003e \u003cb\u003enelderMead\u003c/b\u003e(\u003ci\u003ef\u003c/i\u003e, \u003ci\u003einitial\u003c/i\u003e)\n\nUses the [Nelder-Mead method](https://en.wikipedia.org/wiki/Nelder%E2%80%93Mead_method) to\nminimize a function \u003ci\u003ef\u003c/i\u003e starting at location \u003ci\u003einitial\u003c/i\u003e.\n\nExample usage  minimizing the function \u003ci\u003ef(x, y) = x\u003csup\u003e2\u003c/sup\u003e + y\u003csup\u003e2\u003c/sup\u003e + x sin y + y\nsin x\u003c/i\u003e is:\n![nelder mead demo](./images/nelder_mead.gif)\n\n```js\nfunction loss(X) {\n    var x = X[0], y = X[1];\n    return Math.sin(y) * x  + Math.sin(x) * y  +  x * x +  y *y;\n}\n\nvar solution = fmin.nelderMead(loss, [-3.5, 3.5]);\nconsole.log(\"solution is at \" + solution.x);\n```\n\n\u003c!--\n\u003ca href=\"#gradientDescent\" name=\"gradientDescent\"\u003e#\u003c/a\u003e \u003cb\u003egradientDescent\u003c/b\u003e()\n\n[![gradient descent demo](./images/gradient_descent.gif)](./examples/gradient_descent.html)\n--\u003e\n\n\u003ca href=\"#conjugateGradient\" name=\"conjugateGradient\"\u003e#\u003c/a\u003e \u003cb\u003econjugateGradient\u003c/b\u003e(\u003ci\u003ef\u003c/i\u003e, \u003ci\u003einitial\u003c/i\u003e)\n\nMinimizes a function using the [Polak–Ribière non-linear conjugate gradient method\n](https://en.wikipedia.org/wiki/Nonlinear_conjugate_gradient_method). The function \u003ci\u003ef\u003c/i\u003e should\ncompute both the loss and the gradient.\n\nAn example minimizing [Rosenbrock's Banana\nfunction](https://en.wikipedia.org/wiki/Rosenbrock_function) is:\n\n![conjugate gradient demo](./images/conjugate_gradient.gif)\n\n```js\nfunction banana(X, fxprime) {\n    fxprime = fxprime || [0, 0];\n    var x = X[0], y = X[1];\n    fxprime[0] = 400 * x * x * x - 400 * y * x + 2 * x - 2;\n    fxprime[1] = 200 * y - 200 * x * x;\n    return (1 - x) * (1 - x) + 100 * (y - x * x) * (y - x * x);\n}\n\nvar solution = fmin.conjugateGradient(banana, [-1, 1]);\nconsole.log(\"solution is at \" + solution.x);\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenfred%2Ffmin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenfred%2Ffmin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenfred%2Ffmin/lists"}