import { ProbabilityObjectArray } from "https://deno.land/x/sptaki@1.2.0/utils/mod.ts";
Array of ProbabilityObjectArray which allow to randomly draw of the contained objects based on the relative probability of each of its elements. The probabilities of the contained element is not required to be normalized.
Example: po = new ProbabilityObjectArray( new ProbabilityObject("a", 5), new ProbabilityObject("b", 1), new ProbabilityObject("c", 1) ); res = po.draw(10000); // count the elements which should be distributed according to the relative probabilities res.filter(x => x==="b").reduce((sum, x) => sum + 1 , 0)
Constructors
Methods
Clone this ProbabilitObjectArray
Calculates the normalized cumulative probability of the ProbabilityObjectArray's elements normalized to 1
Draw random element of the ProbabilityObject N times to return an array of N keys. Drawing can be with or without replacement
Drop an element from the ProbabilityObjectArray
Get the maximum relative probability out of a ProbabilityObjectArray
Example: po = new ProbabilityObjectArray(new ProbabilityObject("a", 5), new ProbabilityObject("b", 1)) po.maxProbability() // returns 5
Get the minimum relative probability out of a ProbabilityObjectArray
Example: po = new ProbabilityObjectArray(new ProbabilityObject("a", 5), new ProbabilityObject("b", 1)) po.minProbability() // returns 1
Get the relative probability of an element by its key
Example: po = new ProbabilityObjectArray(new ProbabilityObject("a", 5), new ProbabilityObject("b", 1)) po.maxProbability() // returns 5