{"id":13438813,"url":"https://github.com/noshu/rustimization","last_synced_at":"2025-03-20T06:31:27.950Z","repository":{"id":49604784,"uuid":"59403595","full_name":"noshu/rustimization","owner":"noshu","description":"Collection of Optimization algorithm in Rust","archived":false,"fork":false,"pushed_at":"2021-06-12T09:41:59.000Z","size":17,"stargazers_count":52,"open_issues_count":4,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T10:54:16.453Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/noshu.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-22T09:06:12.000Z","updated_at":"2025-02-25T09:47:37.000Z","dependencies_parsed_at":"2022-09-14T13:00:54.376Z","dependency_job_id":null,"html_url":"https://github.com/noshu/rustimization","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noshu%2Frustimization","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noshu%2Frustimization/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noshu%2Frustimization/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/noshu%2Frustimization/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/noshu","download_url":"https://codeload.github.com/noshu/rustimization/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244565471,"owners_count":20473279,"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":[],"created_at":"2024-07-31T03:01:08.639Z","updated_at":"2025-03-20T06:31:22.942Z","avatar_url":"https://github.com/noshu.png","language":"Rust","funding_links":[],"categories":["Libraries","库","库 Libraries"],"sub_categories":["Computation","计算","计算 Computation"],"readme":"# rustimization\n\nA rust optimization library which includes **L-BFGS-B** and **Conjugate Gradient** algorithm.\n\n## Documentation\n\nThe simplest way to use these optimization algorithm is to use the Funcmin class.\n```rust\nextern crate rustimization;\nuse rustimization::minimizer::Funcmin;\nfn test(){\n    let f = |x: \u0026Vec\u003cf64\u003e| { (x[0]+4.0).powf(2.0)};\n    let g = |x: \u0026Vec\u003cf64\u003e| {vec![2.0*(x[0]+4.0)]};\n    let mut x = vec![40.0f64];\n    {\n        //you must create a mutable object\n        let mut fmin = Funcmin::new(\u0026mut x,\u0026f,\u0026g,\"cg\");\n        fmin.minimize();\n    }\n    println!(\"{:?}\",x);\n}\n```\nOutput\n```\n[-4.000000000000021]\n```\nhere Funcmin constructor takes four **parameters** first one is initial estimation **x** second and third one is the function **f** and\nthe derivative **g** of the function respectively and forth one is the algorithm you want to use. Currently two algorithms \navailable **\"cg\"** and **\"lbfgsb\"**\nif you want more parameter tuning you can use the classes of the algorithm such as for Lbbfgsb_minimizer class\n\n### Example\n\n```rust\nlet f = |x:\u0026Vec\u003cf64\u003e|{ (x[0]+4.0).powf(2.0)};\n    let g = |x:\u0026Vec\u003cf64\u003e|{vec![2.0*(x[0]+4.0)]};\n    let mut x = vec![40.0f64];\n    {\n        //creating lbfgsb object. here it takes three parameter\n        let mut fmin = Lbfgsb::new(\u0026mut x,\u0026f,\u0026g);\n        //seting upper and lower bound first parameter is the index and second one is value\n        fmin.set_upper_bound(0,100.0);\n        fmin.set_lower_bound(0,10.0);\n        //set verbosity. higher value is more verbosity. the value is -1\u003c= to \u003c=101\n        fmin.set_verbosity(101);\n        //start the algorithm\n        fmin.minimize();\n    }\n    println!(\"{:?}\",x);\n```\nOutput\n```\nRUNNING THE L-BFGS-B CODE\n\n           * * *\n\nMachine precision = 2.220D-16\n N =            1     M =            5\n\n L =  1.0000D+01\n\nX0 =  4.0000D+01\n\n U =  1.0000D+02\n\nAt X0         0 variables are exactly at the bounds\n\nAt iterate    0    f=  1.93600D+03    |proj g|=  3.00000D+01\n\n\nITERATION     1\n\n---------------- CAUCHY entered-------------------\n There are            1   breakpoints \n\nPiece      1 --f1, f2 at start point  -7.7440D+03  7.7440D+03\nDistance to the next break point =   3.4091D-01\nDistance to the stationary point =   1.0000D+00\n Variable             1   is fixed.\nCauchy X =  \n      1.0000D+01\n\n---------------- exit CAUCHY----------------------\n\n           0  variables are free at GCP            1\n LINE SEARCH           0  times; norm of step =    30.000000000000000     \n\nAt iterate    1    f=  1.96000D+02    |proj g|=  0.00000D+00\n\n X =  1.0000D+01\n\n G =  2.8000D+01\n\n           * * *\n\nTit   = total number of iterations\nTnf   = total number of function evaluations\nTnint = total number of segments explored during Cauchy searches\nSkip  = number of BFGS updates skipped\nNact  = number of active bounds at final generalized Cauchy point\nProjg = norm of the final projected gradient\nF     = final function value\n\n           * * *\n\n   N    Tit     Tnf  Tnint  Skip  Nact     Projg        F\n    1      1      2      1     0     1   0.000D+00   1.960D+02\n\n X =  1.0000D+01\n  F =   196.00000000000000     \n\nCONVERGENCE: NORM_OF_PROJECTED_GRADIENT_\u003c=_PGTOL            \n\n Cauchy                time 1.570E-04 seconds.\n Subspace minimization time 0.000E+00 seconds.\n Line search           time 1.800E-05 seconds.\n\n Total User time 9.330E-04 seconds.\n\nconvergence!\n```\n\n## Requirements\n\nTo use this library you must have **gfortran** installed in your pc\n* for **windows** use fortran compiler provided by [mingw](http://www.mingw.org/) or [TDM-GCC](http://tdm-gcc.tdragon.net/)\n* for **linux** you can use the package manager to install gfortran\n* for Mac os you can install it form [here](http://hpc.sourceforge.net/) or [here](http://sourceforge.net/projects/hpc/files/hpc/g95/gfortran-mlion.tar.gz)\n\nThe orginal **L-BFGS-B** fortran subroutine is distributed under BSD-3 license. To know more about the condition to use this fortran routine please go [here](http://users.iems.northwestern.edu/~nocedal/lbfgsb.html).\n\nTo know more about the condition to use the **Conjugate Gradient** Fortran routine please go [here](http://users.iems.northwestern.edu/~nocedal/lbfgsb.html) \n\n## References\n\n1. R. H. Byrd, P. Lu and J. Nocedal. [A Limited Memory Algorithm for Bound Constrained Optimization](http://www.ece.northwestern.edu/~nocedal/PSfiles/limited.ps.gz), (1995), SIAM Journal on Scientific and Statistical Computing , 16, 5, pp. 1190-1208.\n2. C. Zhu, R. H. Byrd and J. Nocedal. [L-BFGS-B: Algorithm 778: L-BFGS-B, FORTRAN routines for large scale bound constrained optimization](http://www.ece.northwestern.edu/~nocedal/PSfiles/lbfgsb.ps.gz) (1997), ACM Transactions on Mathematical Software, Vol 23, Num. 4, pp. 550 - 560.\n3. J.L. Morales and J. Nocedal. [L-BFGS-B: Remark on Algorithm 778: L-BFGS-B, FORTRAN routines for large scale bound constrained optimization](http://www.ece.northwestern.edu/~morales/PSfiles/acm-remark.pdf) (2011), to appear in ACM Transactions on Mathematical Software.\n4. J. C. Gilbert and J. Nocedal. Global Convergence Properties of Conjugate Gradient Methods for Optimization, (1992) SIAM J. on Optimization, 2, 1.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoshu%2Frustimization","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnoshu%2Frustimization","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnoshu%2Frustimization/lists"}