Changeset 14837
 Timestamp:
 04/10/17 15:50:16 (2 years ago)
 Location:
 branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE
 Files:

 2 edited
Legend:
 Unmodified
 Added
 Removed

branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEAlgorithm.cs
r14807 r14837 200 200 Parameters.Add(new ValueParameter<IDistance<double[]>>(DistanceParameterName, "The distance function used to differentiate similar from nonsimilar points", new EuclideanDistance())); 201 201 Parameters.Add(new FixedValueParameter<DoubleValue>(PerplexityParameterName, "Perplexityparameter of tSNE. Comparable to k in a knearest neighbour algorithm. Recommended value is floor(number of points /3) or lower", new DoubleValue(25))); 202 Parameters.Add(new FixedValueParameter<DoubleValue>(ThetaParameterName, "Value describing how much appoximated gradients my differ from exact gradients. Set to 0 for exact calculation and in [0,1] otherwise. CAUTION: exact calculation of forces requires building a nonsparse N*N matrix where N is the number of data points. This may exceed memory limitations.", new DoubleValue(0))); 202 Parameters.Add(new FixedValueParameter<DoubleValue>(ThetaParameterName, "Value describing how much appoximated " + 203 "gradients my differ from exact gradients. Set to 0 for exact calculation and in [0,1] otherwise. " + 204 "Appropriate values for theta are between 0.1 and 0.7 (default = 0.5). CAUTION: exact calculation of " + 205 "forces requires building a nonsparse N*N matrix where N is the number of data points. This may " + 206 "exceed memory limitations. The function is designed to run on large (N > 5000) data sets. It may give" + 207 " poor performance on very small data sets(it is better to use a standard t  SNE implementation on such data).", new DoubleValue(0))); 203 208 Parameters.Add(new FixedValueParameter<IntValue>(NewDimensionsParameterName, "Dimensionality of projected space (usually 2 for easy visual analysis)", new IntValue(2))); 204 209 Parameters.Add(new FixedValueParameter<IntValue>(MaxIterationsParameterName, "Maximum number of iterations for gradient descent.", new IntValue(1000))); … … 207 212 Parameters.Add(new FixedValueParameter<DoubleValue>(InitialMomentumParameterName, "The initial momentum in the gradient descent.", new DoubleValue(0.5))); 208 213 Parameters.Add(new FixedValueParameter<DoubleValue>(FinalMomentumParameterName, "The final momentum.", new DoubleValue(0.8))); 209 Parameters.Add(new FixedValueParameter<DoubleValue>(EtaParameterName, "Gradient descent learning rate.", new DoubleValue( 200)));214 Parameters.Add(new FixedValueParameter<DoubleValue>(EtaParameterName, "Gradient descent learning rate.", new DoubleValue(10))); 210 215 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "If the seed should be random.", new BoolValue(true))); 211 216 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The seed used if it should not be random.", new IntValue(0))); … … 217 222 FinalMomentumParameter.Hidden = true; 218 223 StopLyingIterationParameter.Hidden = true; 219 EtaParameter.Hidden = true;224 EtaParameter.Hidden = false; 220 225 } 221 226 #endregion 
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEStatic.cs
r14807 r14837 168 168 169 169 [StorableConstructor] 170 public TSNEState(bool deserializing) 170 public TSNEState(bool deserializing) { } 171 171 public TSNEState(T[] data, IDistance<T> distance, IRandom random, int newDimensions, double perplexity, double theta, int stopLyingIter, int momSwitchIter, double momentum, double finalMomentum, double eta) { 172 172 this.distance = distance; … … 205 205 else CalculateApproximateSimilarities(data, distance, perplexity, out rowP, out colP, out valP); 206 206 207 // Lie about the Pvalues 207 // Lie about the Pvalues (factor is 4 in the MATLAB implementation) 208 208 if(exact) for(var i = 0; i < noDatapoints; i++) for(var j = 0; j < noDatapoints; j++) p[i, j] *= 12.0; 209 209 else for(var i = 0; i < rowP[noDatapoints]; i++) valP[i] *= 12.0; … … 213 213 for(var i = 0; i < noDatapoints; i++) 214 214 for(var j = 0; j < newDimensions; j++) 215 newData[i, j] = rand.NextDouble() * .0001; // TODO const ?215 newData[i, j] = rand.NextDouble() * .0001; 216 216 } 217 217 … … 224 224 private static void CalculateApproximateSimilarities(T[] data, IDistance<T> distance, double perplexity, out int[] rowP, out int[] colP, out double[] valP) { 225 225 // Compute asymmetric pairwise input similarities 226 ComputeGaussianPerplexity(data, distance, out rowP, out colP, out valP, perplexity, (int)(3 * perplexity)); // TODO: why 3?226 ComputeGaussianPerplexity(data, distance, out rowP, out colP, out valP, perplexity, (int)(3 * perplexity)); 227 227 // Symmetrize input similarities 228 228 int[] sRowP, symColP; … … 270 270 271 271 // Build ball tree on data set 272 var tree = new VantagePointTree<IndexedItem<T>>(new IndexedItemDistance<T>(distance), objX); // do we really want to recreate the tree on each call?272 var tree = new VantagePointTree<IndexedItem<T>>(new IndexedItemDistance<T>(distance), objX); 273 273 274 274 // Loop over all points to find nearest neighbors … … 343 343 var found = false; 344 344 var beta = 1.0; 345 var minBeta = double.MaxValue;345 var minBeta = double.MinValue; 346 346 var maxBeta = double.MaxValue; 347 347 const double tol = 1e5; … … 350 350 // Iterate until we found a good perplexity 351 351 var iter = 0; 352 while(!found && iter < 200) { // TODO constant352 while(!found && iter < 200) { // 200 iterations as in tSNE implementation by van der Maarten 353 353 354 354 // Compute Gaussian kernel row … … 414 414 var dd = new double[n, n]; 415 415 var q = new double[n, n]; 416 ComputeSquaredEuclideanDistance(y, n, d, dd); // TODO: we use Euclidian distance regardless of the actual distance function416 ComputeSquaredEuclideanDistance(y, n, d, dd); 417 417 418 418 // Compute Qmatrix and normalization sum … … 455 455 for(var j = 0; j < d; j++) buff[j] = y[k, j]; 456 456 for(var j = 0; j < d; j++) buff[j] = y[colP[i], j]; 457 for(var j = 0; j < d; j++) q += buff[j] * buff[j]; // TODO: squared error is used here!458 q = 1.0 / (1.0 + q) / sumQ;457 for(var j = 0; j < d; j++) q += buff[j] * buff[j]; 458 q = (1.0 / (1.0 + q)) / sumQ; 459 459 c += valP[i] * Math.Log((valP[i] + float.Epsilon) / (q + float.Epsilon)); 460 460 } … … 580 580 for(var j = 0; j < state.newDimensions; j++) { 581 581 state.gains[i, j] = Math.Sign(state.dY[i, j]) != Math.Sign(state.uY[i, j]) 582 ? state.gains[i, j] + .2 583 : state.gains[i, j] * .8; // 20% up or 20% down // TODO: +0.2?!584 585 if(state.gains[i, j] < .01) state.gains[i, j] = .01; // TODO why limit the gains?582 ? state.gains[i, j] + .2 // +0.2 nd *0.8 are used in two separate implementations of tSNE > seems to be correct 583 : state.gains[i, j] * .8; 584 585 if(state.gains[i, j] < .01) state.gains[i, j] = .01; 586 586 } 587 587 } … … 605 605 for(var i = 0; i < state.noDatapoints; i++) 606 606 for(var j = 0; j < state.noDatapoints; j++) 607 state.p[i, j] /= 12.0; //XXX why 12?607 state.p[i, j] /= 12.0; 608 608 else 609 609 for(var i = 0; i < state.rowP[state.noDatapoints]; i++) 610 state.valP[i] /= 12.0; // XXX are we not scaling all values?610 state.valP[i] /= 12.0; 611 611 } 612 612 … … 645 645 // Compute the squared Euclidean distance matrix 646 646 var dd = new double[n, n]; 647 ComputeSquaredEuclideanDistance(y, n, d, dd); // TODO: we use Euclidian distance regardless which distance function is actually set!647 ComputeSquaredEuclideanDistance(y, n, d, dd); 648 648 649 649 // Compute Qmatrix and normalization sum
Note: See TracChangeset
for help on using the changeset viewer.