Package elki.projection
Class TSNE<O>
- java.lang.Object
-
- elki.projection.AbstractProjectionAlgorithm<Relation<DoubleVector>>
-
- elki.projection.TSNE<O>
-
- Type Parameters:
O
- Object type
- All Implemented Interfaces:
Algorithm
- Direct Known Subclasses:
BarnesHutTSNE
@Title("t-SNE") @Reference(authors="L. J. P. van der Maaten, G. E. Hinton", title="Visualizing High-Dimensional Data Using t-SNE", booktitle="Journal of Machine Learning Research 9", url="http://www.jmlr.org/papers/v9/vandermaaten08a.html", bibkey="journals/jmlr/MaatenH08") @Alias({"t-SNE","tSNE"}) public class TSNE<O> extends AbstractProjectionAlgorithm<Relation<DoubleVector>>
t-Stochastic Neighbor Embedding is a projection technique designed for visualization that tries to preserve the nearest neighbor structure.Reference:
L. J. P. van der Maaten, G. E. Hinton
Visualizing High-Dimensional Data Using t-SNE
Journal of Machine Learning Research 9- Since:
- 0.7.5
- Author:
- Erich Schubert, Dominik Acker
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface elki.Algorithm
Algorithm.Utils
-
-
Field Summary
Fields Modifier and Type Field Description protected AffinityMatrixBuilder<? super O>
affinity
Affinity matrix builder.protected int
dim
Desired projection dimensionalityprotected static double
EARLY_EXAGGERATION
Early exaggeration factor.protected static int
EARLY_EXAGGERATION_ITERATIONS
Number of iterations to apply early exaggeration.protected double
finalMomentum
Final momentum.protected static double
INITIAL_SOLUTION_SCALE
Scale of the initial solution.protected double
initialMomentum
Final momentum.protected int
iterations
Number of iterations.protected double
learningRate
Initial learning rate.private static Logging
LOG
Class logger.protected static double
MIN_GAIN
Minimum gain in learning rate.protected static double
MIN_QIJ
Minimum value for qij entries (even when duplicate)protected int
momentumSwitch
Iteration when to switch momentum.protected long
projectedDistances
Number of distance computations performed in projected space.protected RandomFactory
random
Random generator-
Fields inherited from class elki.projection.AbstractProjectionAlgorithm
KEEP_ID
-
-
Constructor Summary
Constructors Constructor Description TSNE(AffinityMatrixBuilder<? super O> affinity, int dim, double finalMomentum, double learningRate, int iterations, RandomFactory random, boolean keep)
Constructor.TSNE(AffinityMatrixBuilder<? super O> affinity, int dim, RandomFactory random)
Constructor with default values.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description Relation<DoubleVector>
autorun(Database database)
Try to auto-run the algorithm on a database by calling a method calledrun
, with an optionalDatabase
first, and with data relations as specified byAlgorithm.getInputTypeRestriction()
.protected void
computeGradient(AffinityMatrix pij, double[][] qij, double qij_isum, double[][] sol, double[] meta)
Compute the gradients.protected double
computeQij(double[][] qij, double[][] solution)
Compute the qij of the solution, and the sum.TypeInformation[]
getInputTypeRestriction()
Get the input type restriction used for negotiating the data query.protected void
optimizetSNE(AffinityMatrix pij, double[][] sol)
Perform the actual tSNE optimization.protected static double[][]
randomInitialSolution(int size, int dim, java.util.Random random)
Generate a random initial solution.Relation<DoubleVector>
run(Relation<O> relation)
Perform tSNE projection.protected double
sqDist(double[] v1, double[] v2)
Squared distance, in projection space.protected void
updateSolution(double[][] sol, double[] meta, int it)
Update the current solution on iteration.-
Methods inherited from class elki.projection.AbstractProjectionAlgorithm
removePreviousRelation
-
-
-
-
Field Detail
-
LOG
private static final Logging LOG
Class logger.
-
MIN_QIJ
protected static final double MIN_QIJ
Minimum value for qij entries (even when duplicate)- See Also:
- Constant Field Values
-
EARLY_EXAGGERATION
protected static final double EARLY_EXAGGERATION
Early exaggeration factor.Barnes-Hut tSNE implementation used 12.
- See Also:
- Constant Field Values
-
EARLY_EXAGGERATION_ITERATIONS
protected static final int EARLY_EXAGGERATION_ITERATIONS
Number of iterations to apply early exaggeration.- See Also:
- Constant Field Values
-
INITIAL_SOLUTION_SCALE
protected static final double INITIAL_SOLUTION_SCALE
Scale of the initial solution.- See Also:
- Constant Field Values
-
MIN_GAIN
protected static final double MIN_GAIN
Minimum gain in learning rate.- See Also:
- Constant Field Values
-
affinity
protected AffinityMatrixBuilder<? super O> affinity
Affinity matrix builder.
-
projectedDistances
protected long projectedDistances
Number of distance computations performed in projected space.
-
dim
protected int dim
Desired projection dimensionality
-
learningRate
protected double learningRate
Initial learning rate.
-
initialMomentum
protected double initialMomentum
Final momentum.
-
finalMomentum
protected double finalMomentum
Final momentum.
-
momentumSwitch
protected int momentumSwitch
Iteration when to switch momentum.
-
iterations
protected int iterations
Number of iterations.
-
random
protected RandomFactory random
Random generator
-
-
Constructor Detail
-
TSNE
public TSNE(AffinityMatrixBuilder<? super O> affinity, int dim, RandomFactory random)
Constructor with default values.- Parameters:
affinity
- Affinity matrix builderdim
- Output dimensionalityrandom
- Random generator
-
TSNE
public TSNE(AffinityMatrixBuilder<? super O> affinity, int dim, double finalMomentum, double learningRate, int iterations, RandomFactory random, boolean keep)
Constructor.- Parameters:
affinity
- Affinity matrix builderdim
- Output dimensionalityfinalMomentum
- Final momentumlearningRate
- Learning rateiterations
- Number of iterationsrandom
- Random generatorkeep
- Keep the original data (or remove it)
-
-
Method Detail
-
getInputTypeRestriction
public TypeInformation[] getInputTypeRestriction()
Description copied from interface:Algorithm
Get the input type restriction used for negotiating the data query.- Returns:
- Type restriction
-
autorun
public Relation<DoubleVector> autorun(Database database)
Description copied from interface:Algorithm
Try to auto-run the algorithm on a database by calling a method calledrun
, with an optionalDatabase
first, and with data relations as specified byAlgorithm.getInputTypeRestriction()
.- Parameters:
database
- the database to run the algorithm on- Returns:
- the Result computed by this algorithm
-
run
public Relation<DoubleVector> run(Relation<O> relation)
Perform tSNE projection.- Parameters:
relation
- Input relation- Returns:
- Output relation
-
randomInitialSolution
protected static double[][] randomInitialSolution(int size, int dim, java.util.Random random)
Generate a random initial solution.- Parameters:
size
- Data set sizedim
- Output dimensionalityrandom
- Random generator- Returns:
- Initial solution matrix
-
optimizetSNE
protected void optimizetSNE(AffinityMatrix pij, double[][] sol)
Perform the actual tSNE optimization.- Parameters:
pij
- Initial affinity matrixsol
- Solution output array (preinitialized)
-
computeQij
protected double computeQij(double[][] qij, double[][] solution)
Compute the qij of the solution, and the sum.- Parameters:
qij
- Qij matrix (output)solution
- Solution matrix (input)- Returns:
- qij sum
-
sqDist
protected double sqDist(double[] v1, double[] v2)
Squared distance, in projection space.- Parameters:
v1
- First vectorv2
- Second vector- Returns:
- Squared distance
-
computeGradient
protected void computeGradient(AffinityMatrix pij, double[][] qij, double qij_isum, double[][] sol, double[] meta)
Compute the gradients.- Parameters:
pij
- Desired affinity matrixqij
- Projected affinity matrixqij_isum
- Normalization factorsol
- Current solution coordinatesmeta
- Point metadata
-
updateSolution
protected void updateSolution(double[][] sol, double[] meta, int it)
Update the current solution on iteration.- Parameters:
sol
- Solution matrixmeta
- Metadata array (gradient, momentum, learning rate)it
- Iteration number, to choose momentum factor.
-
-