spateo.tdr.widgets.tree#

Module Contents#

Classes#

NLPCA

This is a global solver for principal curves that uses neural networks.

Functions#

cal_ncenter(ncells[, ncells_limit])

pca_projection(C, L)

solve the problem size(C) = NxN, size(W) = NxL. max_W trace( W' C W ) : W' W = I.

repmat(→ numpy.ndarray)

This function returns an array containing m (n) copies of A in the row (column) dimensions. The size of B is

sqdist(→ numpy.ndarray)

calculate the square distance between a, b.

DDRTree(X[, maxIter, sigma, gamma, eps, dim, Lambda, ...])

This function is a pure Python implementation of the DDRTree algorithm.

orth_dist(y_true, y_pred)

Loss function for the NLPCA NN. Returns the sum of the orthogonal

spateo.tdr.widgets.tree.cal_ncenter(ncells, ncells_limit=100)[source]#
spateo.tdr.widgets.tree.pca_projection(C: numpy.ndarray, L: int)[source]#

solve the problem size(C) = NxN, size(W) = NxL. max_W trace( W’ C W ) : W’ W = I.

Parameters
C

An array like matrix.

L

The number of Eigenvalues.

Returns

The L largest Eigenvalues.

Return type

W

spateo.tdr.widgets.tree.repmat(X: numpy.ndarray, m: int, n: int) numpy.ndarray[source]#

This function returns an array containing m (n) copies of A in the row (column) dimensions. The size of B is size(A)*n when A is a matrix.For example, repmat(np.matrix(1:4), 2, 3) returns a 4-by-6 matrix.

Parameters
X

An array like matrix.

m

Number of copies on row dimension

n

Number of copies on column dimension

Returns

A matrix of repmat.

Return type

xy_rep

spateo.tdr.widgets.tree.sqdist(a: numpy.ndarray, b: numpy.ndarray) numpy.ndarray[source]#

calculate the square distance between a, b.

Parameters
a

A matrix with \(D imes N\) dimension

b

A matrix with \(D imes N\) dimension

Returns

A numeric value for the different between a and b

Return type

dist

spateo.tdr.widgets.tree.DDRTree(X: numpy.ndarray, maxIter: int = 20, sigma: Union[int, float] = 0.001, gamma: Union[int, float] = 10, eps: int = 0, dim: int = 2, Lambda: Union[int, float] = 1.0, ncenter: Optional[int] = None)[source]#

This function is a pure Python implementation of the DDRTree algorithm.

Parameters
X

DxN, data matrix list.

maxIter

Maximum iterations.

eps

Relative objective difference.

dim

Reduced dimension.

Lambda

Regularization parameter for inverse graph embedding.

sigma

Bandwidth parameter.

gamma

Regularization parameter for k-means.

ncenter

number of nodes allowed in the regularization graph

Returns

A tuple of Z, Y, stree, R, W, Q, C, objs

W is the orthogonal set of d (dimensions) linear basis vector Z is the reduced dimension space stree is the smooth tree graph embedded in the low dimension space Y represents latent points as the center of

spateo.tdr.widgets.tree.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.widgets.tree.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

create_model(num_dim: int, nodes: int, lr: float)[source]#

Creates a tf model.

Parameters
num_dim

How many dimensions the input space is

nodes

How many nodes for the construction layers

lr

Learning rate of backpropigation

Returns

Keras Model

Return type

model (object)