Sampling
The Sampling module provides functions for resampling and search methods suitable for functions found in the Estimators module.
References
- conaction.sampling.heuristic_downward_closure_search(f, X, tau=0.1, abscomp=False, leastarity=2)
Search via the downward closure heuristic.
- Parameters:
f (function) – A permutation-invariant multiary function.
X (ndarray) – m x n data matrix.
tau (float) – Downward closure threshold.
abscomp (Bool) – Whether to compare threshold to absolute value of f.
leastarity (int (default=2)) – The function arity to start search.
- Returns:
d – Computing values of f.
- Return type:
dict[dict]
- conaction.sampling.isoarity_search(f, X, arity)
For a given arity of relation, compute set function on all sets whose cardinality equals that arity.
- Parameters:
f (function) – Estimator
X (np.ndarray-like) – Data matrix
arity (int) – Arity to compute f at; number of variables.
- Returns:
results – Results of computing function f on columns of X.
- Return type:
dict
- conaction.sampling.permute_columns(x)
Permutes the columns of a data matrix.
- Parameters:
x (array-like) – An m x n data matrix.
- Returns:
Permuted matrix.
- Return type:
array-like
References
Examples
>>> import numpy as np >>> np.random.seed(0) >>> data = np.arange(100).reshape(10,10) >>> permute_columns(data) array([[60, 61, 82, 43, 34, 75, 16, 97, 78, 99], [30, 81, 92, 53, 14, 15, 26, 87, 48, 69], [80, 41, 32, 63, 24, 55, 46, 67, 58, 79], [90, 51, 22, 3, 64, 95, 76, 77, 28, 59], [40, 71, 12, 33, 54, 85, 6, 47, 88, 49], [ 0, 11, 2, 73, 94, 65, 86, 57, 18, 9], [50, 91, 62, 83, 4, 35, 96, 37, 98, 29], [10, 1, 42, 93, 84, 25, 36, 17, 68, 39], [70, 31, 72, 23, 44, 5, 56, 7, 38, 19], [20, 21, 52, 13, 74, 45, 66, 27, 8, 89]])
- conaction.sampling.powerset_search(f, X, leastarity=1)
Computes a set function on the whole powerset of sets of variables.
- Parameters:
f (function) – Estimator
X (np.ndarray-like) – Data matrix
- Returns:
results – Computing values of f.
- Return type:
dict
- conaction.sampling.statistic_permute(X, stat_func=<function <lambda>>, iters=100)
Performs a permutation Monte Carlo of a statistical function applied to a given dataset.
- Parameters:
X (array-like) – An m x n data matrix.
stat_func (function) – Function to be calculated on new samples. (default=lambda x: x)
- Returns:
y – Resulting permutation statistics.
- Return type:
list
Notes
This function wraps around the permute_columns function to sample a function of a data matrix multiple times under pseudo-randomly sampled permutations within the columns.
References
[1] “Resampling.”, https://en.wikipedia.org/wiki/Resampling_(statistics)
[2] “Permutation testing.”, https://en.wikipedia.org/wiki/Permutation_test
[3] “Random permutation.”, https://en.wikipedia.org/wiki/Random_permutation
Examples
>>> import numpy as np >>> data = np.arange(9).reshape(3,3) >>> statistic_permute(data, np.mean, 2) [4.0, 4.0]