{"id":15560690,"url":"https://github.com/jdleesmiller/cross_entropy","last_synced_at":"2025-04-23T21:11:01.724Z","repository":{"id":17859310,"uuid":"20784869","full_name":"jdleesmiller/cross_entropy","owner":"jdleesmiller","description":"Ruby library for solving optimisation problems with the Cross Entropy Method.","archived":false,"fork":false,"pushed_at":"2017-05-06T22:31:54.000Z","size":34,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-15T09:06:54.772Z","etag":null,"topics":["cross-entropy","narray","optimization","optimization-algorithms","ruby"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jdleesmiller.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-12T22:27:32.000Z","updated_at":"2018-11-30T02:39:15.000Z","dependencies_parsed_at":"2022-09-01T00:51:54.994Z","dependency_job_id":null,"html_url":"https://github.com/jdleesmiller/cross_entropy","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdleesmiller%2Fcross_entropy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdleesmiller%2Fcross_entropy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdleesmiller%2Fcross_entropy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jdleesmiller%2Fcross_entropy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jdleesmiller","download_url":"https://codeload.github.com/jdleesmiller/cross_entropy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250514789,"owners_count":21443209,"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":["cross-entropy","narray","optimization","optimization-algorithms","ruby"],"created_at":"2024-10-02T16:02:25.741Z","updated_at":"2025-04-23T21:11:01.653Z","avatar_url":"https://github.com/jdleesmiller.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# cross_entropy\n\n[![Build Status](https://travis-ci.org/jdleesmiller/cross_entropy.svg?branch=master)](https://travis-ci.org/jdleesmiller/cross_entropy)\n[![Gem Version](https://badge.fury.io/rb/cross_entropy.svg)](https://badge.fury.io/rb/cross_entropy)\n\nhttps://github.com/jdleesmiller/cross_entropy\n\n## SYNOPSIS\n\nImplementations of the [Cross Entropy Method](https://en.wikipedia.org/wiki/Cross-entropy_method) for several types of problems. Uses [NArray](http://masa16.github.io/narray/) for the numerics, to achieve reasonable performance.\n\n### What is the Cross Entropy method?\n\nIt's basically like a [genetic algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm) without the biological analogy. Instead, it uses probability distributions. You start by specifying a probability distribution for the optimal values, based on your initial guess. The CEM then\n- generates samples based on that distribution,\n- scores them according to the objective function, and\n- uses the lowest-scoring samples (that is, this library assumes that we want to minimize the objective function) to update the parameters of the probability distribution, so it converges on an optimal value.\n\nIt has relatively few tuneable parameters, and it automatically balances diversification and intensification. It is robust to noise in the objective function, so it is very useful for parameter tuning and simulation work.\n\n### Supported problem types\n\n- MatrixProblem: For discrete optimisation problems. Each variable can take one of a fixed number of states. The sampling distribution is a defined by a probability mass function for each variable. The term \"matrix problem\" is based on the idea that we can write the PMFs for each variable into the rows (NArray dimension 1) of a matrix. For example:\n    ```\n               value 1 | value 2\n    variable 1     0.3 | 0.7\n    variable 2     0.9 | 0.1\n    ```\n\n- ContinuousProblem: For continuous unbounded problems. The sampling\n  distribution is a univariate Gaussian.\n\n- BetaProblem: For continous bounded problems. The sampling distribution is a\n  Beta distribution.\n\n### Usage\n\nFor example, here is the [Rosenbrock banana function](http://en.wikipedia.org/wiki/Rosenbrock_function) and a custom smooth updater. The function has a global minimum at `(a, a^2)`, but it's hard to find.\n```{ruby}\n# Parameters for the \"banana\" objective function.\na = 1.0\nb = 100.0\n\n# Our initial guess at the optimal solution.\n# This is just a guess, so we give it a large standard deviation.\nmean = NArray[0.0, 0.0]\nstddev = NArray[10.0, 10.0]\n\n# Set up the problem. These are the CEM parameters.\nproblem = CrossEntropy::ContinuousProblem.new(mean, stddev)\nproblem.num_samples = 1000\nproblem.num_elite   = 10\nproblem.max_iters   = 300\nsmooth = 0.1\n\n# Objective function.\nproblem.to_score_sample {|x| (a - x[0])**2 + b*(x[1] - x[0]**2)**2 }\n\n# Do some smoothing when updating the parameters based on new samples.\n# This isn't strictly required, but I find it often helps convergence.\nproblem.to_update {|new_mean, new_stddev|\n  smooth_mean = smooth*new_mean + (1 - smooth)*problem.param_mean\n  smooth_stddev = smooth*new_stddev + (1 - smooth)*problem.param_stddev\n  [smooth_mean, smooth_stddev]\n}\n\n# It's all calculation from now on...\nproblem.solve\n# problems.param_mean =\u003e NArray[1.0, 1.0]\n```\n\n## INSTALLATION\n\n    gem install cross_entropy\n\n## HISTORY\n\n### 1.1.0 - 6 May 2017\n\n- Linted with rubocop\n- Improved test coverage\n- Added recent rubies in CI\n- Improved README\n\n### 1.0.0 - 2 Jan 2016\n\n- Initial release after extraction from https://github.com/jdleesmiller/si_taxi\n- Added Gaussian and Beta problems\n\n## LICENSE\n\n(The MIT License)\n\nCopyright (c) 2014-2017 John Lees-Miller\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdleesmiller%2Fcross_entropy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjdleesmiller%2Fcross_entropy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjdleesmiller%2Fcross_entropy/lists"}