Package elki.projection
Class NearestNeighborAffinityMatrixBuilder<O>
- java.lang.Object
-
- elki.projection.GaussianAffinityMatrixBuilder<O>
-
- elki.projection.PerplexityAffinityMatrixBuilder<O>
-
- elki.projection.NearestNeighborAffinityMatrixBuilder<O>
-
- Type Parameters:
O- Object type
- All Implemented Interfaces:
AffinityMatrixBuilder<O>
- Direct Known Subclasses:
IntrinsicNearestNeighborAffinityMatrixBuilder
@Reference(authors="L. J. P. van der Maaten", title="Accelerating t-SNE using Tree-Based Algorithms", booktitle="Journal of Machine Learning Research 15", url="http://dl.acm.org/citation.cfm?id=2697068", bibkey="DBLP:journals/jmlr/Maaten14") public class NearestNeighborAffinityMatrixBuilder<O> extends PerplexityAffinityMatrixBuilder<O>
Build sparse affinity matrix using the nearest neighbors only.Reference:
L. J. P. van der Maaten
Accelerating t-SNE using Tree-Based Algorithms
Journal of Machine Learning Research 15TODO: this implementation currently differs in one major point: we do not symmetrize the sparse \(p_{ij}\) matrix.
- Since:
- 0.7.5
- Author:
- Erich Schubert
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classNearestNeighborAffinityMatrixBuilder.Par<O>Parameterization class.
-
Field Summary
Fields Modifier and Type Field Description private static LoggingLOGClass logger.protected intnumberOfNeighboursNumber of neighbors to use.-
Fields inherited from class elki.projection.PerplexityAffinityMatrixBuilder
distance, MIN_PIJ, perplexity, PERPLEXITY_ERROR, PERPLEXITY_MAXITER
-
Fields inherited from class elki.projection.GaussianAffinityMatrixBuilder
sigma
-
-
Constructor Summary
Constructors Constructor Description NearestNeighborAffinityMatrixBuilder(Distance<? super O> distance, double perplexity)Constructor.NearestNeighborAffinityMatrixBuilder(Distance<? super O> distance, double perplexity, int neighbors)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <T extends O>
AffinityMatrixcomputeAffinityMatrix(Relation<T> relation, double initialScale)Compute the affinity matrix.protected static doublecomputeH(DoubleArray dist_i, double[] pij_row, double mbeta)Compute H (observed perplexity) for row i, and the row pij_i.protected voidcomputePij(DBIDRange ids, KNNSearcher<DBIDRef> knnq, boolean square, int numberOfNeighbours, double[][] pij, int[][] indices, double initialScale)Compute the sparse pij using the nearest neighbors only.protected static doublecomputeSigma(int i, DoubleArray pij_row, double perplexity, double log_perp, double[] pij_i)Compute row pij[i], using binary search on the kernel bandwidth sigma to obtain the desired perplexity.protected static intcontainsIndex(int[] is, int i)Check if the index array containsi.protected voidconvertNeighbors(DBIDRange ids, DBIDRef ix, boolean square, KNNList neighbours, DoubleArray dist, IntegerArray ind)Load a neighbor query result into a double and and integer array, also removing the query point.-
Methods inherited from class elki.projection.PerplexityAffinityMatrixBuilder
computePi, computePij, estimateInitialBeta, getInputTypeRestriction
-
Methods inherited from class elki.projection.GaussianAffinityMatrixBuilder
buildDistanceMatrix, computeH
-
-
-
-
Field Detail
-
LOG
private static final Logging LOG
Class logger.
-
numberOfNeighbours
protected int numberOfNeighbours
Number of neighbors to use.
-
-
Method Detail
-
computeAffinityMatrix
public <T extends O> AffinityMatrix computeAffinityMatrix(Relation<T> relation, double initialScale)
Description copied from interface:AffinityMatrixBuilderCompute the affinity matrix.- Specified by:
computeAffinityMatrixin interfaceAffinityMatrixBuilder<O>- Overrides:
computeAffinityMatrixin classPerplexityAffinityMatrixBuilder<O>- Type Parameters:
T- Relation type- Parameters:
relation- Data relationinitialScale- initial scale- Returns:
- Affinity matrix
-
computePij
protected void computePij(DBIDRange ids, KNNSearcher<DBIDRef> knnq, boolean square, int numberOfNeighbours, double[][] pij, int[][] indices, double initialScale)
Compute the sparse pij using the nearest neighbors only.- Parameters:
ids- ID rangeknnq- kNN querysquare- Use squared distancesnumberOfNeighbours- Number of neighbors to getpij- Output of distancesindices- Output of indexesinitialScale- Initial scaling factor
-
convertNeighbors
protected void convertNeighbors(DBIDRange ids, DBIDRef ix, boolean square, KNNList neighbours, DoubleArray dist, IntegerArray ind)
Load a neighbor query result into a double and and integer array, also removing the query point. This is necessary, because we have to modify the distances. TODO: sort by index, not distance- Parameters:
ids- Indexesix- Current Objectsquare- Use squared distancesneighbours- Neighbor listdist- Output distance arrayind- Output index array
-
computeSigma
protected static double computeSigma(int i, DoubleArray pij_row, double perplexity, double log_perp, double[] pij_i)Compute row pij[i], using binary search on the kernel bandwidth sigma to obtain the desired perplexity.- Parameters:
i- Current pointpij_row- Distance matrix row pij[i]perplexity- Desired perplexitylog_perp- Log of desired perplexitypij_i- Output row- Returns:
- beta
-
computeH
protected static double computeH(DoubleArray dist_i, double[] pij_row, double mbeta)
Compute H (observed perplexity) for row i, and the row pij_i.- Parameters:
dist_i- Distances to neighborspij_row- Row pij[i] (output)mbeta--1. / (2 * sigma * sigma)- Returns:
- Observed perplexity
-
containsIndex
protected static int containsIndex(int[] is, int i)Check if the index array containsi. TODO: sort arrays, use binary search!- Parameters:
is- Array to searchi- Index to search- Returns:
- Position of index i, or
-1if not found.
-
-