geometric_kernels.utils.utils

Convenience utilities.

Module Contents

geometric_kernels.utils.utils.chain(elements, repetitions)[source]

Repeats each element in elements by a certain number of repetitions as specified in repetitions. The length of elements and repetitions should match.

Parameters:
  • elements (lab.Numeric) – An [N,]-shaped array of elements to repeat.

  • repetitions (beartype.typing.List[int]) – A list specifying the number of types to repeat each of the elements in elements. The length of repetitions should be equal to N.

Returns:

An [M,]-shaped array.

Return type:

lab.Numeric

EXAMPLE:

elements = np.array([1, 2, 3])
repetitions = [2, 1, 3]
out = chain(elements, repetitions)
print(out)  # [1, 1, 2, 3, 3, 3]
geometric_kernels.utils.utils.fixed_length_partitions(n, L)[source]

A generator for integer partitions of n into L parts, in colex order.

Parameters:
  • n (int) – The number to partition.

  • L (int) – Size of partitions.

Return type:

beartype.typing.Generator[beartype.typing.List[int], None, None]

Developed by D. Eppstein in 2005, taken from https://www.ics.uci.edu/~eppstein/PADS/IntegerPartitions.py The algorithm follows Knuth v4 fasc3 p38 in rough outline; Knuth credits it to Hindenburg, 1779.

geometric_kernels.utils.utils.get_resource_file_path(filename)[source]

A contextmanager wrapper around impresources that supports both Python>=3.9 and Python==3.8 with a unified interface.

Parameters:

filename (str) – The name of the file.

geometric_kernels.utils.utils.make_deterministic(f, key)[source]

Returns a deterministic version of a function that uses a random number generator.

Parameters:
  • f (beartype.typing.Callable) – The function to make deterministic.

  • key (lab.RandomState) – The key used to generate the random state.

Returns:

A function representing the deterministic version of the input function.

Note

This function assumes that the input function has a ‘key’ argument or keyword-only argument that is used to generate random numbers. Otherwise, the function is returned as is.

Return type:

beartype.typing.Callable

EXAMPLE:

key = tf.random.Generator.from_seed(1234)
feature_map = default_feature_map(kernel=base_kernel)
sample_paths = make_deterministic(sampler(feature_map), key)
_, ys_train  = sample_paths(xs_train, params)
key, ys_test = sample_paths(xs_test,  params)
geometric_kernels.utils.utils.ordered_pairwise_differences(X)[source]

Compute the ordered pairwise differences between elements of a vector.

Parameters:

X (lab.Numeric) – A […, D]-shaped array, a batch of D-dimensional vectors.

Returns:

A […, C]-shaped array, where C = D*(D-1)//2, containing the ordered pairwise differences between the elements of X. That is, the array containing differences X[…,i] - X[…,j] for all i < j.

Return type:

lab.Numeric

geometric_kernels.utils.utils.partition_dominance_cone(partition)[source]

Calculates partitions dominated by a given one and having the same number of parts (including the zero parts of the original).

Parameters:

partition (beartype.typing.Tuple[int, Ellipsis]) – A partition.

Returns:

A set of partitions.

Return type:

beartype.typing.Set[beartype.typing.Tuple[int, Ellipsis]]

geometric_kernels.utils.utils.partition_dominance_or_subpartition_cone(partition)[source]

Calculates subpartitions and partitions dominated by a given one and having the same number of parts (including zero parts of the original).

Parameters:

partition (beartype.typing.Tuple[int, Ellipsis]) – A partition.

Returns:

A set of partitions.

Return type:

beartype.typing.Set[beartype.typing.Tuple[int, Ellipsis]]