Coder Social home page Coder Social logo

probabilistic_item_selector's Introduction

Probabilistic ItemSelector PHP Library

Description

This library enables you to continuosly traverse a set of items based on a given probability distribution and selection strategy to use when multiple eligible items are found.

The library is organized around to 2 interfaces:

  • SelectorInterface: abstracts the logic that computes the selection of the next eligible item. Can also be used to keep track of the items being selected.
  • MultipleItemSelectorInterface: abstracts the logic that decides how an item should be selected among a set of multiple eligible items.

Selector

A generic selector implementation has been provided which keeps track of the total number of times an item has been traversed. Additionaly, this selector supports the parametrization of the following features during object creation and also during runtime execution:

  • Desired probability distribution
  • Initial item count
  • Multiple item selector strategy

During runtime this selector supports querying of the following data:

  • Current probability distribution for items
  • Traversal count: per item and total
  • Item values

Multiple eligible items selection strategies

A selection strategy is used to decide how the next item should be chosen when there are several that are eligible. The following strategies have been implemented:

  • Random: Choose a random item among all the eligible items
  • First Item: Choose the first elegible item based on the initial item ordering
  • Highest Desired Probability: Choose the eligible item with the highest desired probability
  • Lowest Desired Probability: Choose the eligible with the lowest desired probability
  • Highest Current Probability: Choose the eligible item with the highest current probability
  • Lowest Current Probability: Choose the eligible with the lowest current probability

Requirements

Installation

Use Composer to install this library from the following Git repository

Composer

Follow the installation instructions if you do not already have composer installed.

Add the following repository to your project's composer.json file

"repositories": [
	{ "type": "vcs", "url": "https://github.com/fernando-almeida/probabilistic_item_selector" }
],

Once this repository is added, execute the following command in your project root to install this library:

composer require fernando-almeida/probabilistic_item_selector

Finally, be sure to include the autoloader:

require_once '/path/to/your-project/vendor/autoload.php';

Examples

See the examples/ directory for examples of the key library features. Run any example using the PHP CLI

php 'path/to/example/example.php'

Code Quality

Run the PHPUnit tests with PHPUnit from the root directory.

phpunit

Coding Style

To check for coding style violations, run

vendor/bin/phpcs src --standard=style/ruleset.xml -np

To automatically fix (fixable) coding style violations, run

vendor/bin/phpcbf src --standard=style/ruleset.xml

probabilistic_item_selector's People

Contributors

fernando-almeida avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.