spateo.tdr.models.models_backbone.backbone_methods ================================================== .. py:module:: spateo.tdr.models.models_backbone.backbone_methods Classes ------- .. autoapisummary:: spateo.tdr.models.models_backbone.backbone_methods.NLPCA Functions --------- .. autoapisummary:: spateo.tdr.models.models_backbone.backbone_methods.orth_dist spateo.tdr.models.models_backbone.backbone_methods.ElPiGraph_method spateo.tdr.models.models_backbone.backbone_methods.SimplePPT_method spateo.tdr.models.models_backbone.backbone_methods.PrinCurve_method Module Contents --------------- .. py:function:: orth_dist(y_true, y_pred) Loss function for the NLPCA NN. Returns the sum of the orthogonal distance from the output tensor to the real tensor. .. py:class:: NLPCA Bases: :py:obj:`object` This is a global solver for principal curves that uses neural networks. .. attribute:: None .. py:attribute:: fit_points :value: None .. py:attribute:: model :value: None .. py:attribute:: intermediate_layer_model :value: None .. py:method:: fit(data: numpy.ndarray, epochs: int = 500, nodes: int = 25, lr: float = 0.01, verbose: int = 0) This method creates a model and will fit it to the given m x n dimensional data. :param data: A numpy array of shape (m,n), where m is the number of points and n is the number of dimensions. :param epochs: Number of epochs to train neural network, defaults to 500. :param nodes: Number of nodes for the construction layers. Defaults to 25. The more complex the curve, the higher this number should be. :param lr: Learning rate for backprop. Defaults to .01 :param verbose: Verbose = 0 mutes the training text from Keras. Defaults to 0. .. py:method:: project(data: numpy.ndarray) -> Tuple[numpy.ndarray, numpy.ndarray] The project function will project the points to the curve generated by the fit function. Given back is the projection index of the original data and a sorted version of the original data. :param data: m x n array to project to the curve :returns: A one-dimension array that contains the projection index for each point in data. all_sorted: A m x n+1 array that contains data sorted by its projection index, along with the index. :rtype: proj .. py:method:: create_model(num_dim: int, nodes: int) Creates a PyTorch model. :param num_dim: How many dimensions the input space is :param nodes: How many nodes for the construction layers :returns: PyTorch Model :rtype: model (object) .. py:function:: ElPiGraph_method(X: numpy.ndarray, NumNodes: int = 50, topology: Literal['tree', 'circle', 'curve'] = 'curve', Lambda: float = 0.01, Mu: float = 0.1, alpha: float = 0.0, FinalEnergy: Literal['Base', 'Penalized'] = 'Penalized', **kwargs) -> Tuple[numpy.ndarray, numpy.ndarray] Generate a principal elastic tree. Reference: Albergante et al. (2020), Robust and Scalable Learning of Complex Intrinsic Dataset Geometry via ElPiGraph. :param X: DxN, data matrix list. :param NumNodes: The number of nodes of the principal graph. Use a range of 10 to 100 for ElPiGraph approach. :param topology: The appropriate topology used to fit a principal graph for each dataset. :param Lambda: The attractive strength of edges between nodes (constrains edge lengths) :param Mu: The repulsive strength of a node’s neighboring nodes (constrains angles to be close to harmonic) :param alpha: Branching penalty (penalizes number of branches for the principal tree) :param FinalEnergy: Indicating the final elastic emergy associated with the configuration. Currently it can be “Base” or “Penalized” :param \*\*kwargs: Other parameters used in elpigraph.computeElasticPrincipalTree. For details, please see: https://elpigraph-python.readthedocs.io/en/latest/basics.html :returns: The nodes in the principal tree. edges: The edges between nodes in the principal tree. :rtype: nodes .. py:function:: SimplePPT_method(X: numpy.ndarray, NumNodes: int = 50, sigma: Optional[Union[float, int]] = 0.1, lam: Optional[Union[float, int]] = 1, metric: str = 'euclidean', nsteps: int = 50, err_cut: float = 0.005, seed: Optional[int] = 1, **kwargs) -> Tuple[numpy.ndarray, numpy.ndarray] Generate a simple principal tree. Reference: Mao et al. (2015), SimplePPT: A simple principal tree algorithm, SIAM International Conference on Data Mining. :param X: DxN, data matrix list. :param NumNodes: The number of nodes of the principal graph. Use a range of 100 to 2000 for PPT approach. :param sigma: Regularization parameter. :param lam: Penalty for the tree length. :param metric: The metric to use to compute distances in high dimensional space. For compatible metrics, check the documentation of sklearn.metrics.pairwise_distances. :param nsteps: Number of steps for the optimisation process. :param err_cut: Stop algorithm if proximity of principal points between iterations less than defined value. :param seed: A numpy random seed. :param \*\*kwargs: Other parameters used in simpleppt.ppt. For details, please see: https://github.com/LouisFaure/simpleppt/blob/main/simpleppt/ppt.py :returns: The nodes in the principal tree. edges: The edges between nodes in the principal tree. :rtype: nodes .. py:function:: PrinCurve_method(X: numpy.ndarray, NumNodes: int = 50, epochs: int = 500, lr: float = 0.01, scale_factor: Union[int, float] = 1, **kwargs) -> Tuple[numpy.ndarray, numpy.ndarray] This is the global module that contains principal curve and nonlinear principal component analysis algorithms that work to optimize a line over an entire dataset. Reference: Chen et al. (2016), Constraint local principal curve: Concept, algorithms and applications. :param X: DxN, data matrix list. :param NumNodes: Number of nodes for the construction layers. Defaults to 50. The more complex the curve, the higher this number should be. :param epochs: Number of epochs to train neural network, defaults to 500. :param lr: Learning rate for backprop. Defaults to .01 :param scale_factor: :param \*\*kwargs: Other parameters used in global algorithms. For details, please see: https://github.com/artusoma/prinPy/blob/master/prinpy/glob.py :returns: The nodes in the principal tree. edges: The edges between nodes in the principal tree. :rtype: nodes