Recommend this page to a friend! |
Selection manager for choosing next elements to use from data source based on uniform distribution of selections.
use Smoren\ProbabilitySelector\ProbabilitySelector;
$ps = new ProbabilitySelector([
// data // weight // initial usage counter
['first', 1, 0],
['second', 2, 0],
['third', 3, 4],
]);
foreach ($ps as $datum) {
echo "{$datum}, ";
}
// second, second, first, second, third, third, second, first, third, second, third, third, second, first, third, ...
use Smoren\ProbabilitySelector\ProbabilitySelector;
$ps = new ProbabilitySelector([
// data // weight
['first', 1],
['second', 2],
]);
foreach ($ps->getIterator(6) as $datum) {
echo "{$datum}, ";
}
// second, second, first, second, second, first
print_r($ps->export());
/*
[
['first', 1, 2],
['second', 2, 4],
]
*/
use Smoren\ProbabilitySelector\ProbabilitySelector;
$ps = new ProbabilitySelector([
// data // weight
['first', 1],
['second', 2],
]);
$ps->decide(); // second
$ps->decide(); // second
$ps->decide(); // first
composer install
composer test-init
composer test
PHP Probability Selector conforms to the following standards:
PHP Probability Selector is licensed under the MIT License.
Classes of Smoren Freelight | > | PHP Probability Selector | > | Download .zip .tar.gz | > | Support forum | > | Blog | > | Latest changes |
|
Groups | Applications | Files |
Groups |
Algorithms | Numerical and statistical algorithms | View top rated classes |
PHP 5 | Classes using PHP 5 specific features | View top rated classes |
Statistics | Collecting, processing and reporting statistical data | View top rated classes |
Innovation Award |
February 2023 Nominee Vote |
Some applications need to select items from a list automatically. For instance, applications that need to assign jobs to a list of servers. This class implements an algorithm that considers the number of times the items on a list was used and probability weights assigned to each item to decide which item should be used next time automatically. Manuel Lemos |
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.
Files |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
src (1 file) | ||||
tests (3 files, 2 directories) | ||||
.scrutinizer.yml | Data | Auxiliary data | ||
codeception.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.xml | Data | Auxiliary data | ||
phpstan.neon | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
unit (1 file) | ||||
_support (1 file) | ||||
coding_standard.xml | Data | Auxiliary data | ||
unit.suite.yml | Data | Auxiliary data | ||
_bootstrap.php | Aux. | Auxiliary script |
Download all files: probability-selector.tar.gz probability-selector.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|
Files |
File | Role | Description | ||
---|---|---|---|---|
.github (1 directory) | ||||
src (1 file) | ||||
tests (3 files, 2 directories) | ||||
.scrutinizer.yml | Data | Auxiliary data | ||
codeception.yml | Data | Auxiliary data | ||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpcs.xml | Data | Auxiliary data | ||
phpstan.neon | Data | Auxiliary data | ||
README.md | Doc. | Documentation |
Files | / | tests |
File | Role | Description | ||
---|---|---|---|---|
unit (1 file) | ||||
_support (1 file) | ||||
coding_standard.xml | Data | Auxiliary data | ||
unit.suite.yml | Data | Auxiliary data | ||
_bootstrap.php | Aux. | Auxiliary script |
Download all files: probability-selector.tar.gz probability-selector.zip NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
|