fake_data_for_learning.utils module

Utility functions for fake_data_for_learning

class fake_data_for_learning.utils.ExpectationConstraint(equation, moment, value)

Bases: tuple

property equation

Alias for field number 0

property moment

Alias for field number 1

property value

Alias for field number 2

class fake_data_for_learning.utils.MapMultidimIndexToLinear(dims, coords)[source]

Bases: object

Convert multidimensional array indices to linear and back

get_coord_tuple(coord_index_dict)[source]
to_linear(multi_index_value)[source]
to_multidim(linear_index_value)[source]
class fake_data_for_learning.utils.ProbabilityPolytope(dims=, coords={})[source]

Bases: object

Polytope represenation and methods for discrete (conditional) probability distributions.

Parameters
  • dims (iterable of strings) – Dimension names

  • coords (dict) – Dict with keys dimension names and values dimension values

generate_flat_random_cpt()[source]

Generate flat (i.e. array with only 1 dimension) representation of a random (conditional) probability table from the polytope.

Returns

res – Float array of shape (number of possible outcomes, )

Return type

np.array

generate_random_cpt()[source]

Generate random (conditional) probability table from the polytope

get_all_half_planes()[source]
Get half plane representations of polytope defined by
  • the probability polytope half planes due to
    • probabilities summing to one, and

    • probabilities lying in [0, 1], plus

  • the given expectation value constraints

Returns

A, b

Return type

tuple of np.array

get_expect_equation_coefficient(constraint_equation)[source]
Parameters

constraint_equation (dict) –

Returns

res

Return type

float

get_expect_equations_col_indices(constraint_equation)[source]
get_expect_equations_half_planes()[source]
get_expect_equations_matrix()[source]

Generate (linearly indexed) equation matrix from expect_constraints

Returns

A

Return type

numpy.array

get_expect_equations_row_entries(constraint_equation, moment)[source]
Parameters

constraint_equation (dict) –

Returns

Values of self.expect_on_dimension in summand

Return type

list of int

static get_half_planes_from_equations(A, b)[source]

Convert equations of the form Ax = b to inequalties of the form A’ x’ <= b’

Parameters
  • A (numpy.array of shape (m,n)) –

  • b (numpy.array of shape (n,)) –

Returns

  • Ap (numpy.array of shape (2m, n))

  • bp (numpy.array of shape (2n,))

get_n_outcomes()[source]
get_n_probability_constraints()[source]

Get the number of probability constraints involved in calculating expectation values over self.expect_on_dimension.

Returns

res

Return type

int

get_probability_bounds_half_planes()[source]

Get half-plane representation of bounds 0 <= p_I <= 1 for all possible value indices I.

Returns

A, b

Return type

tuple of np.array

get_probability_half_planes()[source]
Get half plane representations of polytope defined by
  • the probability polytope half planes due to
    • probabilities summing to one, and

    • probabilities lying in [0, 1], plus

  • the given expectation value constraints

Returns

A, b

Return type

tuple of np.array

get_sum_dims(constraint_equation)[source]
Parameters

constraint_equation (dict) –

Returns

res – Matrix dimension names not among constraint equations

Return type

tuple

get_sum_overs(constraint_equation)[source]
Parameters

constraint_equation (dict) –

Returns

Return type

list

get_total_probability_constraint_equations()[source]

Get iterator of constraint equation for conditional probabilities summing to 1.

Returns

Return type

itertools.product

get_total_probability_constraint_matrix()[source]
Returns

A

Return type

np.array

get_total_probability_half_planes()[source]
Returns

A, b

Return type

tuple of np.array

get_vertex_representation()[source]

Calculate the vertex representation of the probability polytope.

Returns

res – Matrix of shape self.dim, total number of constraints

Return type

np.array

set_expectation_constraints(constraints)[source]
class fake_data_for_learning.utils.RandomCpt(*shape)[source]

Bases: object

Generate random conditional probability table

static make_cpt(x)[source]

Convert numpy array x to conditional probability table.

fake_data_for_learning.utils.flatten_list(l)[source]

From StackOverflow: 952914/how-to-make-a-flat-list-out-of-list-of-lists

fake_data_for_learning.utils.get_simplex_sample(ambient_dimension, size=None)[source]

Get random element of the simplex of given ambient dimension

Parameters

ambient_dimension (int) – Dimension of ambient real vector space in which (probability) simplex is defined.

Returns

res – Random sample point from the simplex

Return type

np.array

fake_data_for_learning.utils.product_dict(**kwargs)[source]

From StackOverflow: 5228158/cartesian-product-of-a-dictionary-of-lists