PHP Classes

PHP Probability Selector: Decide which item to select based on probabilities

Recommend this page to a friend!

  Author Author  
Picture of Smoren  Freelight
Name: Smoren Freelight <contact>
Classes: 11 packages by
Country: Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 5x


  Detailed description   Download Download .zip .tar.gz  
This class can decide which item to select based on probabilities.

It can take a parameter, a list of items with identifiers, probability weight, and usage count.

The class can calculate probabilities based on the item weight and usage count and decide the next item to use. The identifier of the selected item is returned.

Details

PHP Probability Selector

Packagist PHP Version Support Scrutinizer Code Quality Coverage Status Build and test License: MIT

Selection manager for choosing next elements to use from data source based on uniform distribution of selections.

Infinite iteration

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, ...

Iteration limit and export

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],
]
 */

Single decision

use Smoren\ProbabilitySelector\ProbabilitySelector;

$ps = new ProbabilitySelector([
    // data     // weight
    ['first',   1],
    ['second',  2],
]);
$ps->decide(); // second
$ps->decide(); // second
$ps->decide(); // first

Unit testing

composer install
composer test-init
composer test

Standards

PHP Probability Selector conforms to the following standards:

License

PHP Probability Selector is licensed under the MIT License.


  Classes of Smoren Freelight  >  PHP Probability Selector  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Probability Selector
Base name: probability-selector
Description: Decide which item to select based on probabilities
Version: -
PHP version: 7.4
License: MIT/X Consortium License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image Algorithms Numerical and statistical algorithms View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Statistics Collecting, processing and reporting statistical data View top rated classes


  Innovation Award  
PHP Programming Innovation award nominee
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  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 file)
Files folder imagetests (3 files, 2 directories)
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file codeception.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file test_master.yml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file ProbabilitySelector.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageunit (1 file)
Files folder image_support (1 file)
  Accessible without login Plain text file coding_standard.xml Data Auxiliary data
  Accessible without login Plain text file unit.suite.yml Data Auxiliary data
  Accessible without login Plain text file _bootstrap.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  unit  
File Role Description
  Plain text file ProbabilitySelectorTest.php Class Class source

  Files folder image Files  /  tests  /  _support  
File Role Description
  Plain text file UnitTester.php Class Class source

Download 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 folder image Files  
File Role Description
Files folder image.github (1 directory)
Files folder imagesrc (1 file)
Files folder imagetests (3 files, 2 directories)
Accessible without login Plain text file .scrutinizer.yml Data Auxiliary data
Accessible without login Plain text file codeception.yml Data Auxiliary data
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file phpcs.xml Data Auxiliary data
Accessible without login Plain text file phpstan.neon Data Auxiliary data
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  .github  
File Role Description
Files folder imageworkflows (1 file)

  Files folder image Files  /  .github  /  workflows  
File Role Description
  Accessible without login Plain text file test_master.yml Data Auxiliary data

  Files folder image Files  /  src  
File Role Description
  Plain text file ProbabilitySelector.php Class Class source

  Files folder image Files  /  tests  
File Role Description
Files folder imageunit (1 file)
Files folder image_support (1 file)
  Accessible without login Plain text file coding_standard.xml Data Auxiliary data
  Accessible without login Plain text file unit.suite.yml Data Auxiliary data
  Accessible without login Plain text file _bootstrap.php Aux. Auxiliary script

  Files folder image Files  /  tests  /  unit  
File Role Description
  Plain text file ProbabilitySelectorTest.php Class Class source

  Files folder image Files  /  tests  /  _support  
File Role Description
  Plain text file UnitTester.php Class Class source

Download 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.