spateo.alignment.methods.sampling

Classes

TRNET

Class for topology representing network sampling.

Functions

sample(→ numpy.ndarray)

A collection of various sampling methods.

trn(→ numpy.ndarray)

Sample method based on topology representing network.

sample_by_velocity(→ numpy.ndarray)

Sample method based on velocity.

sample_by_kmeans(→ Optional[numpy.ndarray])

Sample method based on kmeans.

lhsclassic(→ numpy.ndarray)

Latin Hypercube Sampling method implemented from PyDOE.

Module Contents

spateo.alignment.methods.sampling.sample(arr: list | numpy.ndarray, n: int, method: Literal['random', 'velocity', 'trn', 'kmeans'] = 'random', X: numpy.ndarray | None = None, V: numpy.ndarray | None = None, seed: int = 19491001, **kwargs) numpy.ndarray[source]

A collection of various sampling methods.

Parameters:
arr

The array to be sub-sampled.

n

The number of samples.

method

The method to be used. “random”: randomly choosing n elements from arr; “velocity”: Higher the velocity, higher the chance to be sampled; “trn”: Topology Representing Network based sampling; “kmeans”: n points that are closest to the kmeans centroids on X are chosen. Defaults to “random”.

X

Coordinates associated to each element in arr. Defaults to None.

V

Velocity associated to each element in arr. Defaults to None.

seed

The randomization seed. Defaults to 19491001.

Raises:

NotImplementedErrormethod is invalid.

Returns:

The sampled data array.

class spateo.alignment.methods.sampling.TRNET(n_nodes: int, X: numpy.ndarray, seed: int = 19491001)[source]

Class for topology representing network sampling.

n_nodes[source]

The number of nodes in the graph.

n_dim

The dimensions of the array to be sub-sampled.

X[source]

Coordinates associated to each element in original array to be sub-sampled.

seed[source]

The randomization seed.

W[source]

The sample graph.

n_nodes[source]
n_dims[source]
X[source]
seed = 19491001[source]
W[source]
draw_sample(n_samples: int) numpy.ndarray[source]

Initialize the positions of nodes.

Parameters:
n_samples

The number of nodes.

Returns:

The initial positions of nodes.

runOnce(p: numpy.ndarray, l: float, ep: float, c: float) None[source]

Performs one iteration of the TRN sampling algorithm. Learn from distance to update the sampling index.

Parameters:
p

The target data points to calculate the distance.

l

The learning rate that controls learning speed.

ep

The epsilon that controls learning speed.

c

The cutoff parameter to accelerate the learning.

run(tmax: int = 200, li: float = 0.2, lf: float = 0.01, ei: float = 0.3, ef: float = 0.05, c: float = 0) None[source]

Runs the TRN sampling algorithm for the specified number of iterations.

Parameters:
tmax

The maximum number of iterations.

li

The initial learning rate parameter.

lf

The final learning rate parameter.

ei

The initial epsilon parameter.

ef

The final epsilon parameter.

c

The cutoff parameter to accelerate the learning.

run_n_pause(k0: int, k: int, tmax: float = 200, li: float = 0.2, lf: float = 0.01, ei: float = 0.3, ef: float = 0.05, c: int = 0) None[source]

Run the TRN algorithm sampling for a specified range of iterations.

Parameters:
k0

Starting iteration number.

k

Ending iteration number.

tmax

The maximum number of iterations.

li

The initial learning rate parameter.

lf

The final learning rate parameter.

ei

The initial epsilon parameter.

ef

The final epsilon parameter.

c

The cutoff parameter to accelerate the learning.

spateo.alignment.methods.sampling.trn(X: numpy.ndarray, n: int, return_index: bool = True, seed: int = 19491001, **kwargs) numpy.ndarray[source]

Sample method based on topology representing network.

Parameters:
X

Coordinates associated to each element in original array to be sub-sampled.

n

The number of samples.

return_index

Whether to return the indices of the sub-sampled array or the sample graph. Defaults to True.

seed

The randomization seed. Defaults to 19491001.

Returns:

The sample graph or the indices of the sub-sampled array.

spateo.alignment.methods.sampling.sample_by_velocity(V: numpy.ndarray, n: int, seed: int = 19491001) numpy.ndarray[source]

Sample method based on velocity.

Parameters:
V

Velocity associated with each element in the sample array.

n

The number of samples.

seed

The randomization seed. Defaults to 19491001.

Returns:

The sample data array.

spateo.alignment.methods.sampling.sample_by_kmeans(X: numpy.ndarray, n: int, return_index: bool = False) numpy.ndarray | None[source]

Sample method based on kmeans.

Parameters:
X

Coordinates associated to each element in arr.

n

The number of samples.

return_index

Whether to return the sample indices. Defaults to False.

Returns:

The sample index array if return_index is True. Else return the array after sampling.

spateo.alignment.methods.sampling.lhsclassic(n_samples: int, n_dim: int, bounds: numpy.ndarray | List[List[float]] = None, seed: int = 19491001) numpy.ndarray[source]

Latin Hypercube Sampling method implemented from PyDOE.

Parameters:
n_samples

The number of samples to be generated.

n_dim

The number of data dimensions.

bounds

n_dim-by-2 matrix where each row specifies the lower and upper bound for the corresponding dimension. If None, it is assumed to be (0, 1) for every dimension. Defaults to None.

seed

The randomization seed. Defaults to 19491001.

Returns:

The sampled data array.