variate

alias

ALIAS method to generate random variate from discrete probability distribution

class AliasMethod(probabilities: array, states: Callable[[list[int]], Any])[source]

Bases: Sampling

Alias Method

__init__(probabilities: array, states: Callable[[list[int]], Any])[source]
Parameters
  • probabilities – vector of probabilities (which must sum to 1)

  • states – discrete spatial states

cost()[source]
Returns

the computing cost of the algorithm for generating the random variable the cost will usually correspond to the number of generated uniform random variables

reset_sampling_cost()[source]

reset the simulation cost to 0

sample(size: int = 1) array[source]

sample a random variable corresponding the distribution in scope

Parameters

size – size of the sampling vector

Returns

the array of simulated variables

create_alias(probabilities)[source]

Initialisation of the ALIAS method

binarysearchtree

Binary Search Tree method to generate discrete probability distribution

class BinarySearchTree(probabilities: array, states: Callable[[list[int]], Any])[source]

Bases: Sampling

__init__(probabilities: array, states: Callable[[list[int]], Any])[source]
sample(size: int = 1) ndarray[Any, dtype[float]][source]

sample a random variable corresponding the distribution in scope

Parameters

size – size of the sampling vector

Returns

the array of simulated variables

sample_with_u(u)[source]
create_binary_search_tree(probabilities)[source]

binarysearchtreeadapted

Binary Search Tree method. The term adapted means two things: - the probabilities of the tree are computed on the fly, contrary to the usual binary search tree where the probabilities are pre-computed. - it is adapted to our purpose, that is to the simulation CTMC processes, but the code could be made generic to be adapted to other simulation algorithms

class Point(coordinates, value)[source]

Bases: object

Representation of a point in the state grid

__init__(coordinates, value)[source]
Parameters
  • coordinates – coordinates (x1, x2, x3,…)

  • value – values (y1, y2, y3, …)

coordinates
value
class BinarySearchTreeAdapted1D(model: LevyModel, grid: CTMCGrid, intensity_of_jumps: float)[source]

Bases: Sampling

__init__(model: LevyModel, grid: CTMCGrid, intensity_of_jumps: float)[source]
sample(size: int = 1) array[source]

sample a random variable corresponding the distribution in scope

Parameters

size – size of the sampling vector

Returns

the array of simulated variables

sample_with_u(u: float)[source]
class BinarySearchTreeAdapted(model: LevyModel, grid: CTMCGrid)[source]

Bases: Sampling

__init__(model: LevyModel, grid: CTMCGrid)[source]
cost() int[source]
Returns

the computing cost of the algorithm for generating the random variable the cost will usually correspond to the number of generated uniform random variables

reset_sampling_cost() None[source]

reset the simulation cost to 0

sample(size: int = 1) array[source]

sample a random variable corresponding the distribution in scope

Parameters

size – size of the sampling vector

Returns

the array of simulated variables

sample_with_us(us: array)[source]
sample_one_bucket(coordinates, probability: float)[source]

huffmantree

Huffman’s Tree method to generate discrete probability distribution

class HuffmanTree(probabilities: array, states: Callable[[list[int]], Any])[source]

Bases: Sampling

__init__(probabilities: array, states: Callable[[list[int]], Any])[source]
sample(size: int = 1) ndarray[Any, dtype[float]][source]

sample a random variable corresponding the distribution in scope

Parameters

size – size of the sampling vector

Returns

the array of simulated variables

sample_with_u(u: float, head: Node) tuple[int, int][source]
class Node(value: float, is_leaf: bool)[source]

Bases: object

A node in the tree is defined by its value and whether it is a leaf (or has children nodes)

__init__(value: float, is_leaf: bool)[source]
value
is_leaf
class InternalNode(value: float, left_node: Node, right_node: Node)[source]

Bases: Node

An internal node is not a lead, that is it has at least a left node child or a right node child

__init__(value: float, left_node: Node, right_node: Node)[source]
left_node
right_node
class Leaf(value: float, state: int)[source]

Bases: Node

A leaf node has no children

__init__(value: float, state: int)[source]
state
class Heap(nodes: [<class 'distribution.variate.huffmantree.Node'>])[source]

Bases: object

__init__(nodes: [<class 'distribution.variate.huffmantree.Node'>])[source]
pop() Node[source]
insert(node: Node)[source]
create_huffman_tree(probabilities) Node[source]

inversion

INVERSION method to generate random variate from discrete probability distribution

class InversionMethod(probability_to_jump_to_state: Callable[[tuple[int, ...]], float], state_manager: StatesManager)[source]

Bases: Sampling

Inversion method

The inversion method might be slower than other methods but one of the benefits is that there is no pre-computation and therefore no (much) impact on memory

__init__(probability_to_jump_to_state: Callable[[tuple[int, ...]], float], state_manager: StatesManager)[source]
cost() int[source]
Returns

the computing cost of the algorithm for generating the random variable the cost will usually correspond to the number of generated uniform random variables

reset_sampling_cost()[source]

reset the simulation cost to 0

sample(size: int = 1) list[tuple[int, ...]][source]

sample a random variable corresponding the distribution in scope

Parameters

size – size of the sampling vector

Returns

the array of simulated variables

sample_with_u(u: float) tuple[int, ...][source]

table

TABLE method to generate random variate from discrete probability distribution

class TableMethod(probabilities: array, states: Callable[[list[int]], Any])[source]

Bases: Sampling

Table method - 32bit implementation

__init__(probabilities: array, states: Callable[[list[int]], Any])[source]
sample(size: int = 1) ndarray[Any, dtype[float]][source]

sample a random variable corresponding the distribution in scope

Parameters

size – size of the sampling vector

Returns

the array of simulated variables

create_table(probabilities, states)[source]