Package elki.projection
Class SNE<O>
- java.lang.Object
-
- elki.projection.AbstractProjectionAlgorithm<Relation<DoubleVector>>
-
- elki.projection.SNE<O>
-
- Type Parameters:
O
- Object type
- All Implemented Interfaces:
Algorithm
@Reference(authors="G. Hinton, S. Roweis", title="Stochastic Neighbor Embedding", booktitle="Advances in Neural Information Processing Systems 15", url="http://papers.nips.cc/paper/2276-stochastic-neighbor-embedding", bibkey="DBLP:conf/nips/HintonR02") public class SNE<O> extends AbstractProjectionAlgorithm<Relation<DoubleVector>>
Stochastic Neighbor Embedding is a projection technique designed for visualization that tries to preserve the nearest neighbor structure.Reference:
G. Hinton, S. Roweis
Stochastic Neighbor Embedding
Advances in Neural Information Processing Systems 15- Since:
- 0.7.5
- Author:
- Erich Schubert
-
-
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 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 SNE(AffinityMatrixBuilder<? super O> affinity, int dim, double finalMomentum, double learningRate, int iterations, RandomFactory random, boolean keep)
Constructor.SNE(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
optimizeSNE(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 SNE 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
-
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
-
SNE
public SNE(AffinityMatrixBuilder<? super O> affinity, int dim, RandomFactory random)
Constructor with default values.- Parameters:
affinity
- Affinity matrix builderdim
- Output dimensionalityrandom
- Random generator
-
SNE
public SNE(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 SNE 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
-
optimizeSNE
protected void optimizeSNE(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.
-
-