spateo.alignment.methods.sampling¶
Classes¶
Class for topology representing network sampling. |
Functions¶
|
A collection of various sampling methods. |
|
Sample method based on topology representing network. |
|
Sample method based on velocity. |
|
Sample method based on kmeans. |
|
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:
NotImplementedError – method 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_dim¶
The dimensions of the array to be sub-sampled.
- 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.