inferi.combinatorics

Contains tools for combining and permutating collections.

inferi.combinatorics.permutations(n, r=None)[source]

Returns the number of ways of arranging r elements of a set of size n in a given order - the number of permuatations.

Parameters:
  • n (int) – The size of the set containing the elements.
  • r (int) – The number of elements to arange. If not given, it will be assumed to be equal to n.
Raises:
  • TypeError – if non-integers are given.
  • ValueError – if r is greater than n.
Return type:

int

inferi.combinatorics.combinations(n, r=None)[source]

Returns the number of ways of combining r elements of a set of size n, where order doesn’t matter

Parameters:
  • n (int) – The size of the set containing the elements.
  • r (int) – The number of elements to arange. If not given, it will be assumed to be equal to n.
Raises:
  • TypeError – if non-integers are given.
  • ValueError – if r is greater than n.
Return type:

int

inferi.combinatorics.multiplications(*counts)[source]

Returns the product of the integers given - useful for calculating the number of simple events in a multi-stage process.

Raises:TypeError – if non-integers are given.
Return type:int
inferi.combinatorics.permutate(collection, r=None)[source]

Generates all the permutations of a given iterable, of a given length.

It is essentially a wrapper around the built-in itertools.permutations.

Parameters:
  • collection (iterable) – The iterable to permutate.
  • r (int) – The number of elements to arange. If not given, it will be assumed to be equal to the length of the collection.
Raises:

ValueError – if r is greater than the length of the collection.

Return type:

tuple

inferi.combinatorics.combine(collection, r=None)[source]

Generates all the combinations of a given iterable, of a given length.

It is essentially a wrapper around the built-in itertools.combinations.

Parameters:
  • collection (iterable) – The iterable to combine.
  • r (int) – The number of elements to arange. If not given, it will be assumed to be equal to the length of the collection.
Raises:

ValueError – if r is greater than the length of the collection.

Return type:

set

inferi.combinatorics.multiply(*collections)[source]

Generates all the multiplications of some iterables. For example, passing ["A", "B"] and ["+", "_"] would yield ("A", "+"), ("A", "-"), ("B", "+") and ("B", "-").

Parameters:collections (*) – The iterables to put together.
Return type:tuple