spateo.tdr.models.models_backbone.backbone_methods¶
Classes¶
This is a global solver for principal curves that uses neural networks. |
Functions¶
|
Loss function for the NLPCA NN. Returns the sum of the orthogonal |
|
Generate a principal elastic tree. |
|
Generate a simple principal tree. |
|
This is the global module that contains principal curve and nonlinear principal component analysis algorithms that |
Module Contents¶
- spateo.tdr.models.models_backbone.backbone_methods.orth_dist(y_true, y_pred)[source]¶
Loss function for the NLPCA NN. Returns the sum of the orthogonal distance from the output tensor to the real tensor.
- class spateo.tdr.models.models_backbone.backbone_methods.NLPCA[source]¶
Bases:
object
This is a global solver for principal curves that uses neural networks. .. attribute:: None
- fit(data: numpy.ndarray, epochs: int = 500, nodes: int = 25, lr: float = 0.01, verbose: int = 0)[source]¶
This method creates a model and will fit it to the given m x n dimensional data.
- Parameters:
- data
A numpy array of shape (m,n), where m is the number of points and n is the number of dimensions.
- epochs
Number of epochs to train neural network, defaults to 500.
- nodes
Number of nodes for the construction layers. Defaults to 25. The more complex the curve, the higher this number should be.
- lr
Learning rate for backprop. Defaults to .01
- verbose
Verbose = 0 mutes the training text from Keras. Defaults to 0.
- project(data: numpy.ndarray) Tuple[numpy.ndarray, numpy.ndarray] [source]¶
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.
- Parameters:
- 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.
- Return type:
proj
- spateo.tdr.models.models_backbone.backbone_methods.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] [source]¶
Generate a principal elastic tree. Reference: Albergante et al. (2020), Robust and Scalable Learning of Complex Intrinsic Dataset Geometry via ElPiGraph.
- Parameters:
- X
DxN, data matrix list.
- NumNodes
The number of nodes of the principal graph. Use a range of 10 to 100 for ElPiGraph approach.
- topology
The appropriate topology used to fit a principal graph for each dataset.
- Lambda
The attractive strength of edges between nodes (constrains edge lengths)
- Mu
The repulsive strength of a node’s neighboring nodes (constrains angles to be close to harmonic)
- alpha
Branching penalty (penalizes number of branches for the principal tree)
- FinalEnergy
Indicating the final elastic emergy associated with the configuration. Currently it can be “Base” or “Penalized”
- **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.
- Return type:
nodes
- spateo.tdr.models.models_backbone.backbone_methods.SimplePPT_method(X: numpy.ndarray, NumNodes: int = 50, sigma: float | int | None = 0.1, lam: float | int | None = 1, metric: str = 'euclidean', nsteps: int = 50, err_cut: float = 0.005, seed: int | None = 1, **kwargs) Tuple[numpy.ndarray, numpy.ndarray] [source]¶
Generate a simple principal tree. Reference: Mao et al. (2015), SimplePPT: A simple principal tree algorithm, SIAM International Conference on Data Mining.
- Parameters:
- X
DxN, data matrix list.
- NumNodes
The number of nodes of the principal graph. Use a range of 100 to 2000 for PPT approach.
- sigma
Regularization parameter.
- lam
Penalty for the tree length.
- metric
The metric to use to compute distances in high dimensional space. For compatible metrics, check the documentation of sklearn.metrics.pairwise_distances.
- nsteps
Number of steps for the optimisation process.
- err_cut
Stop algorithm if proximity of principal points between iterations less than defined value.
- seed
A numpy random seed.
- **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.
- Return type:
nodes
- spateo.tdr.models.models_backbone.backbone_methods.PrinCurve_method(X: numpy.ndarray, NumNodes: int = 50, epochs: int = 500, lr: float = 0.01, scale_factor: int | float = 1, **kwargs) Tuple[numpy.ndarray, numpy.ndarray] [source]¶
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.
- Parameters:
- X
DxN, data matrix list.
- NumNodes
Number of nodes for the construction layers. Defaults to 50. The more complex the curve, the higher this number should be.
- epochs
Number of epochs to train neural network, defaults to 500.
- lr
Learning rate for backprop. Defaults to .01
- scale_factor
- **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.
- Return type:
nodes