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
-
property
-
class
fake_data_for_learning.utils.MapMultidimIndexToLinear(dims, coords)[source]¶ Bases:
objectConvert multidimensional array indices to linear and back
-
class
fake_data_for_learning.utils.ProbabilityPolytope(dims=, coords={})[source]¶ Bases:
objectPolytope 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
-
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_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_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
-
class
fake_data_for_learning.utils.RandomCpt(*shape)[source]¶ Bases:
objectGenerate random 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