NIPY logo

Site Navigation

NIPY Community

Table Of Contents

This Page

neurospin.eda.dimension_reduction

Module: neurospin.eda.dimension_reduction

Inheritance diagram for nipy.neurospin.eda.dimension_reduction:

This modules contains several classes to perform non-linear dimension reduction. Each class has 2 methods, ‘train’ and ‘test’ - ‘train’ performs the computation of low-simensional data embedding and the information to generalize to new data - ‘test’ computes the embedding for new dsamples of data This is done for - Multi-dimensional scaling - Isompap (knn or eps-neighb implementation) - Locality Preseving projections (LPP) - laplacian embedding (train only)

Future developpements will include some supervised cases, e.g. LDA,LDE and the estimation of the latent dimension, at least in simple cases.

Bertrand Thirion, 2006-2009

Classes

MDS

class nipy.neurospin.eda.dimension_reduction.MDS(X=None, rdim=1, fdim=1)

Bases: nipy.neurospin.eda.dimension_reduction.NLDR

This is a particular class that perfoms linear dimension reduction
using multi-dimensional scaling (PCA of the distance matrix)

besides the fields of NDLR, it contains the following ones:

embedding: array of shape (nbitems,rdim)
this is representation of the training data
offset: array of shape(nbitems)
affine part of the embedding
projector: array of shape(fdim,rdim)
linear part of the embedding

Methods

check_data
set_train_data
test
train
__init__(X=None, rdim=1, fdim=1)
check_data(X)

Check that X has the specified fdim

set_train_data(X)

Set the input array X as the training data of the class

test(x)

Apply the learnt embedding to the new data x

Parameters :

x: array of shape(nbitems, fdim) :

data points to be embedded

Returns :

chart: array of shape (nbitems, rdim) :

resulting rdim-dimensional represntation :

train(verbose=0)

training procedure

Parameters :verbose=0 : verbosity mode
Returns :chart: resulting rdim-dimensional representation :

NLDR

class nipy.neurospin.eda.dimension_reduction.NLDR(X=None, rdim=1, fdim=1)

Bases: object

This is a generic class for non-linear dimension reduction techniques
(NLDR) the main members are:

train_data, array the input dataset from which the DR is perfomed fdim=1, int, the input deature dimension rdim=1, int, the reduced feature dimension trained: trained==1 means that the system has been trained

and can generalize

Methods

check_data
set_train_data
test
train
__init__(X=None, rdim=1, fdim=1)
check_data(X)

Check that X has the specified fdim

set_train_data(X)

Set the input array X as the training data of the class

test(X)

check that X is suitable as test data

train()

set self.trained as 1

PCA

class nipy.neurospin.eda.dimension_reduction.PCA(X=None, rdim=1, fdim=1)

Bases: nipy.neurospin.eda.dimension_reduction.NLDR

This class performs PCA-based linear dimension reduction besides the fields of NDLR, it contains the following ones:

embedding: array of shape (nbitems,rdim)
this is representation of the training data
offset: array of shape(nbitems)
affine part of the embedding
projector: array of shape(fdim,rdim)
linear part of the embedding

Methods

check_data
set_train_data
test
train
__init__(X=None, rdim=1, fdim=1)
check_data(X)

Check that X has the specified fdim

set_train_data(X)

Set the input array X as the training data of the class

test(x)

Apply the learnt embedding to the new data x

Parameters :

x: array of shape(nbitems, fdim) :

data points to be embedded

Returns :

chart: array of shape (nbitems, rdim) :

resulting rdim-dimensional represntation :

train(verbose=0)

training procedure

Parameters :verbose=0 : verbosity mode
Returns :chart: resulting rdim-dimensional representation :

eps_Isomap

class nipy.neurospin.eda.dimension_reduction.eps_Isomap(X=None, rdim=1, fdim=1)

Bases: nipy.neurospin.eda.dimension_reduction.NLDR

This is a particular class that perfoms linear dimension reduction
using eps-ball neighbor modelling and isomapping.

besides the fields of NDLR, it contains the following ones:

eps, float eps-ball model used in the knn graph building G : data-representing graph learnt from the training data embedding: array of shape (nbitems,rdim)

this is representation of the training data
offset: array of shape(nbitems)
affine part of the embedding
projector: array of shape(fdim,rdim)
linear part of the embedding

Methods

check_data
set_train_data
test
train
__init__(X=None, rdim=1, fdim=1)
check_data(X)

Check that X has the specified fdim

set_train_data(X)

Set the input array X as the training data of the class

test(x)

Embedding the data conatined in x

Parameters :

x:array of shape(nbitems,fdim) :

new data points to be embedded

verbose=0, bool, verbosity mode :

Returns :

chart: array of shape (nbitems, rdim) :

resulting rdim-dimensional represntation

train(eps=1.0, p=300, verbose=0)

Traing/learning function

Parameters :

eps=1.0, float value of self.eps :

p=300, int :

number points used to compute the low dimensional approximation

verbose=0 : verbosity mode

Returns :

chart, array of shape (nbLearningSamples, rdim), :

the resulting embedding

knn_Isomap

class nipy.neurospin.eda.dimension_reduction.knn_Isomap(X=None, rdim=1, fdim=1)

Bases: nipy.neurospin.eda.dimension_reduction.NLDR

This is a particular class that perfoms linear dimension reduction
using k-nearest-neighbor (knn) modelling and isomapping.

Besides the fields of NDLR, it contains the following ones:

k : number of neighbors in the knn graph building G : knn graph based on the training data embedding: array of shape (nbitems,rdim)

this is representation of the training data
offset: array of shape(nbitems)
affine part of the embedding
projector: array of shape(fdim,rdim)
linear part of the embedding

Methods

check_data
set_train_data
test
train
__init__(X=None, rdim=1, fdim=1)
check_data(X)

Check that X has the specified fdim

set_train_data(X)

Set the input array X as the training data of the class

test(x)

embed new data into the learnt representation

Parameters :

x array of shape(nbitems,fdim) :

new data points to be embedded

verbose=0, bool, verbosity mode :

Returns :

chart, array of shape (nbitems, rdim) :

resulting rdim-dimensional represntation

train(k=1, p=300, verbose=0)

Training function

Parameters :

k=1, int, k in the knn system :

p=300, int, number points used in the low dimensional approximation :

verbose=0, bool, verbosity mode :

Returns :

chart, array of shape (nbLearningSamples, rdim) :

knn_Isomap embedding

knn_LE

class nipy.neurospin.eda.dimension_reduction.knn_LE(X=None, rdim=1, fdim=1)

Bases: nipy.neurospin.eda.dimension_reduction.NLDR

This is a particular class that perfoms linear dimension reduction
using k nearest neighbor modelling and laplacian embedding.

besides the fields of NDLR, it contains the following ones:

k, int number of neighbors in the knn graph building G, graph lerant on the training data embedding: array of shape (nbitems,rdim)

this is representation of the training data
fixme: to date, only the training part (embedding computation)
is considered

Methods

check_data
set_train_data
test
train
__init__(X=None, rdim=1, fdim=1)
check_data(X)

Check that X has the specified fdim

set_train_data(X)

Set the input array X as the training data of the class

test(X)

check that X is suitable as test data

train(k=1, verbose=0)

learning function

Parameters :

k=1, int k in the knn system :

verbose=0, bool, verbosity mode :

Returns :

chart: array of shape (nblearningSamples, rdim) :

embedding of the training data

knn_LPP

class nipy.neurospin.eda.dimension_reduction.knn_LPP(X=None, rdim=1, fdim=1)

Bases: nipy.neurospin.eda.dimension_reduction.NLDR

This is a particular class that perfoms linear dimension reduction
using k nearest neighbor modelling and locality preserving projection (LPP).

besides the fields of NDLR, it contains the following ones:

k, int, number of neighbors in the knn graph building G, graph learnt based on the training data embedding: array of shape (nbitems,rdim)

this is representation of the training data
projector: array of shape(fdim,rdim)
linear part of the embedding

Methods

check_data
set_train_data
test
train
__init__(X=None, rdim=1, fdim=1)
check_data(X)

Check that X has the specified fdim

set_train_data(X)

Set the input array X as the training data of the class

test(x)

Function to generalize the embedding to new data

Parameters :

x: array of shape(nbitems,fdim) :

new data points to be embedded

verbose=0, bool, verbosity mode :

Returns :

chart,array of shape (nbitems,rdim) :

resulting rdim-dimensional represntation

train(k=1, verbose=0)

Learning function

Parameters :

k=1, int, k in the knn system :

verbose=0, bool, verbosity mode :

Returns :

chart, array of shape (nblearningSamples, rdim) :

the resulting data embedding

Functions

nipy.neurospin.eda.dimension_reduction.CCA(X, Y, eps=1e-15)

Canonical corelation analysis of two matrices

Parameters :

X array of shape (nbitem,p) :

Y array of shape (nbitem,q) :

eps=1.e-15, float is a small biasing constant :

to grant invertibility of the matrices

Returns :

ccs, array of shape(min(n,p,q) the canonical correlations :

nipy.neurospin.eda.dimension_reduction.Euclidian_distance(X, Y=None)

Considering the rows of X (and Y=X) as vectors, compute the distance matrix between each pair of vector

Parameters :

X, array of shape (n1,p) :

Y=None, array of shape (n2,p) :

if Y==None, then Y=X is used instead

Returns :

ED, array fo shape(n1, n2) :

nipy.neurospin.eda.dimension_reduction.Euclidian_mds(X, dim, verbose=0)

returns a dim-dimensional MDS representation of the rows of X using an Euclidian metric

nipy.neurospin.eda.dimension_reduction.LE(G, dim, verbose=0, maxiter=1000)

Laplacian Embedding of the data returns the dim-dimensional LE of the graph G

Parameters :

G, nipy.neurospin.graph.WeightedGraph instance that represents the data :

dim=1, int, number of dimensions :

verbose=0, verbosity level :

maxiter=1000, int, maximum number of iterations of the algorithm :

Returns :

chart, array of shape(G.V,dim) :

nipy.neurospin.eda.dimension_reduction.LE_dev(G, dim, verbose=0, maxiter=1000)

Laplacian Embedding of the data returns the dim-dimensional LE of the graph G

Parameters :

G, nipy.neurospin.graph.WeightedGraph instance that represents the data :

dim=1, int number of dimensions :

verbose=0, verbosity level :

maxiter=1000, maximum number of iterations of the algorithm :

Returns :

chart, array of shape(G.V,dim), the resulting embedding :

nipy.neurospin.eda.dimension_reduction.LPP(G, X, dim, verbose=0, maxiter=1000)

Compute the Locality preserving projector of the data

Parameters :

G, nipy.neurospin.graph.WeightedGraph instance that represents the data :

X, array of shape (G.V, input_dim) related input dataset :

dim=1, int, representation dimensions :

verbose=0, bool verbosity level :

maxiter=1000, int, maximum number of iterations of the algorithm :

Returns :

proj, array of shape(X.shape[0],dim) :

nipy.neurospin.eda.dimension_reduction.Orthonormalize(M) orthonormalize the columns of M (Gram-Schmidt procedure)
nipy.neurospin.eda.dimension_reduction.check_isometry(G, chart, nseeds=100, verbose=0)

A simple check of the Isometry: look whether the output distance match the intput distances for nseeds points

Returns :a scaling factor between the proposed and the true metrics :
nipy.neurospin.eda.dimension_reduction.infer_latent_dim(X, verbose=0, maxr=-1)

r = infer_latent_dim(X, verbose=0) Infer the latent dimension of an aray assuming data+gaussian noise mixture

Parameters :

array X, data whose deimsnionhas to be inferred :

verbose=0, int, verbosity level :

maxr=-1, int, maximum dimension that can be achieved :

if maxr = -1, this is equal to rank(X)

Returns :

r, int, the inferred dimension :

nipy.neurospin.eda.dimension_reduction.isomap(G, dim=1, p=300, verbose=0)

Isomapping of the data return the dim-dimensional ISOMAP chart that best represents the graph G

Parameters :

G : nipy.neurospin.graph.WeightedGraph instance that represents the data

dim=1, int number of dimensions :

p=300, int nystrom reduction of the problem :

verbose = 0: verbosity level :

Returns :

chart, array of shape(nbitem, dim), :

the resulting reprsentation of the traing data

proj, array of shape (nbitem, dim) :

the set of directions used to embed the data in the reduced space

scaling, array of shape (dim) :

scaling to apply to perform the embedding of the data

offset, array of shape (nbitem) :

additive factor necessary to center the embedding (analogous to mean subtraction)

seed, array of shape (p): :

the seed nodes that were used to compute fast embedding

nipy.neurospin.eda.dimension_reduction.local_sym_normalize(G)

graph symmetric normalization; moiover, the normalizing vector is returned NB : this is now in the C graph lib.

nipy.neurospin.eda.dimension_reduction.mds(dm, dim=1, verbose=0)

Multi-dimensional scaling, i.e. derivation of low dimensional representations from distance matrices.

Parameters :

dm, array of shape(nbitem, nbitem), the input distance matrix :

dim=1: the dimension of the desired representation :

verbose=0: verbosity level :

Returns :

chart, array of shape(nbitem, dim), :

the resulting reprsentation of the traing data

embedding_direction, array of shape (nbitem, dim) :

the set of directions used to embed the data in the reduced space

scaling, array of shape (dim) :

scaling to apply to perform the embedding of the data

offset, array of shape (nbitem) :

additive factor necessary to center the embedding (analogous to mean subtraction)

nipy.neurospin.eda.dimension_reduction.mds_embedding(dm, embedding_direction, scaling, offset)

Embedding new data based on a previous mds computation

Parameters :

dm, array of shape(nb_test_item, nb_train_item), :

the input distance matrix:

embedding_direction, array of shape (nb_train_item, dim) :

the set of directions used to embed the data in the reduced space

scaling, array of shape (dim) :

scaling to apply to perform the embedding of the data

offset, array of shape (nbitem) :

additive factor necessary to center the embedding (analogous to mean subtraction)

Returns :

chart, array of shape(nb_test_item, dim), :

the resulting reprsentation of the traing data

nipy.neurospin.eda.dimension_reduction.mds_parameters(dm, dim=1, verbose=0)

Compute the embedding parameters to perform the embedding of some data given a distance matrix

Parameters :

dm, array of shape(nbitem, nbitem), the input distance matrix :

dim=1: the dimension of the desired representation :

verbose=0: verbosity level :

Returns :

embedding_direction, array of shape (nbitem, dim) :

the set of directions used to embed the data in the reduced space

scaling, array of shape (dim) :

scaling to apply to perform the embedding of the data

offset, array of shape (nbitem) :

additive factor necessary to center the embedding (analogous to mean subtraction)

nipy.neurospin.eda.dimension_reduction.partial_floyd_graph(G, k)

Create a graph of the knn in the geodesic sense, given an input graph G

nipy.neurospin.eda.dimension_reduction.swiss_roll(nbitem=1000)

Sample nbitem=1000 point from a swiss roll

Returns :

x array of shape (nbitem,3) the 3D embedding :

u array of shape (nbitem,2) the intrinsic coordinates :