Previous topic

fem.continuous package

Next topic

fortran_module extension

fem.discrete package

Submodules

fem.discrete.combinatorics module

fem.discrete.combinatorics.binomial_coefficients(n, k)[source]

Return a list of binomial coefficients.

Parameters:
  • n (int) – the first argument to the choose operation
  • k (int) – the maximum second argument to the choose operation
Returns:

a list of binomial coefficients

Return type:

ndarray

Examples

Compute the binomial coefficients \({4\choose 0}\), \({4\choose 1}\), and \({4\choose 2}\)

>>> from fem.discrete.combinatorics import binomial_coefficients
>>> binomial_coefficients(4, 2)
array([1, 4, 6])
fem.discrete.combinatorics.mixed_radix_to_base_10(x, b)[source]

Convert the mixed radix integer with digits x and bases b to base 10.

Parameters:
  • x (list) – a list of digits ordered by increasing place values
  • b (list) – a list of bases corresponding to the digits

Examples

Generally, the base 10 representation of the mixed radix number \(x_n\ldots x_1\) where \(x_i\) is a digit in place value \(i\) with base \(b_i\) is

\[\sum_{i=1}^nx_i\prod_{j=i+1}^nb_j = x_n + b_nx_{n-1} + b_nb_{n-1}x_{n-2} + \cdots + b_n\cdots b_2x_1\]

Convert 111 with bases \((b_1,b_2,b_3)=(2,3,4)\) to base 10:

>>> from fem.discrete.combinatorics import mixed_radix_to_base_10
>>> mixed_radix_to_base_10([1,1,1], [2,3,4])
17
fem.discrete.combinatorics.multiindices(n, k)[source]

Return an ordered list of distinct tuples of the first \(n\) nonnegative integers.

Parameters:
  • n (int) – The least integer not included in the list of distinct tuples
  • k (int) – The length of each tuple
Returns:

a list of distinct tupes of shape \({n\choose k}\) by \(k\)

Return type:

ndarray

Examples

>>> from fem.discrete.combinatorics import multiindices
>>> multiindices(4, 2)
array([[0, 1], [0, 2], [0, 3], [1, 2], [1, 3], [2, 3]])

fem.discrete.fit module

fem.discrete.fit.categorize(x)[source]

Convert x to integer data

Parameters:x (list) –
Returns:The integer data and the map from symbols to integers
Return type:(list, dict)
fem.discrete.fit.fit(x, y=None, iters=100, degs=[1], overfit=True, impute=None)[source]

Fit the Potts model to the data

Parameters:
  • x (ndarray) –
  • y (ndarray) –
  • degs (list) –
  • iters (int) –
  • overfit (bool) –
  • impute (bool) –
Returns:

The fitted model parameters and the running discrepancies

Return type:

(dict, list)

class fem.discrete.fit.model(degs=[1])[source]
fit(x, y=None, iters=100, overfit=True, impute=None, svd='approx')[source]

Fit the Potts model to the data

Parameters:
  • x (ndarray) –
  • y (ndarray) –
  • degs (list) –
  • iters (int) –
  • overfit (bool) –
  • impute (bool) –
Returns:

The fitted model parameters and the running discrepancies

Return type:

(dict, list)

predict(x)[source]
fem.discrete.fit.one_hot(x, m, degs)[source]

One hot encoding of x

Parameters:
  • x (ndarray) –
  • degs (list) –
Returns
(csc_matrix, ndarray): the one hot encoding and the multiindices
fem.discrete.fit.svd_pinv(x)[source]

fem.discrete.simulate module

fem.discrete.simulate.model_parameters(n, m, degs=[1], dist=None, dist_par=None)[source]

Draw random model parameters

Parameters:
  • n (int) –
  • m (int) –
  • degs (list) –
  • dist (callable) –
  • dist_par (tuple) –
Returns:

keys degs

Return type:

dict

fem.discrete.simulate.mutations(w, n, m, l=None, o=1.0)[source]
fem.discrete.simulate.time_series(w, n, m, l=None, o=1.0)[source]

Simulate discrete time series data

Parameters:
  • w (dict) –
  • n (int) –
  • m (int) –
  • l (int) –
  • o (float) –
Returns:

time series data

Return type:

ndarray

Module contents