spateo.alignment.methods.sampling ================================= .. py:module:: spateo.alignment.methods.sampling Classes ------- .. autoapisummary:: spateo.alignment.methods.sampling.TRNET Functions --------- .. autoapisummary:: spateo.alignment.methods.sampling.sample spateo.alignment.methods.sampling.trn spateo.alignment.methods.sampling.sample_by_velocity spateo.alignment.methods.sampling.sample_by_kmeans spateo.alignment.methods.sampling.lhsclassic Module Contents --------------- .. py:function:: sample(arr: Union[list, numpy.ndarray], n: int, method: Literal['random', 'velocity', 'trn', 'kmeans'] = 'random', X: Optional[numpy.ndarray] = None, V: Optional[numpy.ndarray] = None, seed: int = 19491001, **kwargs) -> numpy.ndarray A collection of various sampling methods. :param arr: The array to be sub-sampled. :param n: The number of samples. :param 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". :param X: Coordinates associated to each element in `arr`. Defaults to None. :param V: Velocity associated to each element in `arr`. Defaults to None. :param seed: The randomization seed. Defaults to 19491001. :raises NotImplementedError: `method` is invalid. :returns: The sampled data array. .. py:class:: TRNET(n_nodes: int, X: numpy.ndarray, seed: int = 19491001) Class for topology representing network sampling. .. attribute:: n_nodes The number of nodes in the graph. .. attribute:: n_dim The dimensions of the array to be sub-sampled. .. attribute:: X Coordinates associated to each element in original array to be sub-sampled. .. attribute:: seed The randomization seed. .. attribute:: W The sample graph. .. py:attribute:: n_nodes .. py:attribute:: n_dims .. py:attribute:: X .. py:attribute:: seed .. py:attribute:: W .. py:method:: draw_sample(n_samples: int) -> numpy.ndarray Initialize the positions of nodes. :param n_samples: The number of nodes. :returns: The initial positions of nodes. .. py:method:: runOnce(p: numpy.ndarray, l: float, ep: float, c: float) -> None Performs one iteration of the TRN sampling algorithm. Learn from distance to update the sampling index. :param p: The target data points to calculate the distance. :param l: The learning rate that controls learning speed. :param ep: The epsilon that controls learning speed. :param c: The cutoff parameter to accelerate the learning. .. py:method:: run(tmax: int = 200, li: float = 0.2, lf: float = 0.01, ei: float = 0.3, ef: float = 0.05, c: float = 0) -> None Runs the TRN sampling algorithm for the specified number of iterations. :param tmax: The maximum number of iterations. :param li: The initial learning rate parameter. :param lf: The final learning rate parameter. :param ei: The initial epsilon parameter. :param ef: The final epsilon parameter. :param c: The cutoff parameter to accelerate the learning. .. py:method:: 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 Run the TRN algorithm sampling for a specified range of iterations. :param k0: Starting iteration number. :param k: Ending iteration number. :param tmax: The maximum number of iterations. :param li: The initial learning rate parameter. :param lf: The final learning rate parameter. :param ei: The initial epsilon parameter. :param ef: The final epsilon parameter. :param c: The cutoff parameter to accelerate the learning. .. py:function:: trn(X: numpy.ndarray, n: int, return_index: bool = True, seed: int = 19491001, **kwargs) -> numpy.ndarray Sample method based on topology representing network. :param X: Coordinates associated to each element in original array to be sub-sampled. :param n: The number of samples. :param return_index: Whether to return the indices of the sub-sampled array or the sample graph. Defaults to True. :param seed: The randomization seed. Defaults to 19491001. :returns: The sample graph or the indices of the sub-sampled array. .. py:function:: sample_by_velocity(V: numpy.ndarray, n: int, seed: int = 19491001) -> numpy.ndarray Sample method based on velocity. :param V: Velocity associated with each element in the sample array. :param n: The number of samples. :param seed: The randomization seed. Defaults to 19491001. :returns: The sample data array. .. py:function:: sample_by_kmeans(X: numpy.ndarray, n: int, return_index: bool = False) -> Optional[numpy.ndarray] Sample method based on kmeans. :param X: Coordinates associated to each element in `arr`. :param n: The number of samples. :param 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. .. py:function:: lhsclassic(n_samples: int, n_dim: int, bounds: Union[numpy.ndarray, List[List[float]]] = None, seed: int = 19491001) -> numpy.ndarray Latin Hypercube Sampling method implemented from PyDOE. :param n_samples: The number of samples to be generated. :param n_dim: The number of data dimensions. :param 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. :param seed: The randomization seed. Defaults to 19491001. :returns: The sampled data array.