- Timestamp:
- 03/30/17 19:06:44 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/TSNE/HeuristicLab.Algorithms.DataAnalysis/3.4/TSNE/TSNEStatic.cs
r14806 r14807 60 60 using HeuristicLab.Common; 61 61 using HeuristicLab.Core; 62 using HeuristicLab.Optimization; 62 63 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 63 64 using HeuristicLab.Random; … … 65 66 namespace HeuristicLab.Algorithms.DataAnalysis { 66 67 [StorableClass] 67 public class TSNE <T> {68 public class TSNEStatic<T> { 68 69 69 70 [StorableClass] … … 166 167 } 167 168 169 [StorableConstructor] 170 public TSNEState(bool deserializing) { } 168 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) { 169 172 this.distance = distance; … … 525 528 for(var i = 0; i < noElem; i++) symValP[i] /= 2.0; 526 529 } 527 528 530 } 529 531 530 public static TSNEState CreateState(T[] data, IDistance<T> distance, IRandom random, int newDimensions = 2, double perplexity = 25, double theta = 0, 531 int stopLyingIter = 250, int momSwitchIter = 250, double momentum = .5, double finalMomentum = .8, double eta = 200.0 532 /// <summary> 533 /// Simple interface to tSNE 534 /// </summary> 535 /// <param name="data"></param> 536 /// <param name="distance">The distance function used to differentiate similar from non-similar points, e.g. Euclidean distance.</param> 537 /// <param name="random">Random number generator</param> 538 /// <param name="newDimensions">Dimensionality of projected space (usually 2 for easy visual analysis).</param> 539 /// <param name="perplexity">Perplexity parameter of tSNE. Comparable to k in a k-nearest neighbour algorithm. Recommended value is floor(number of points /3) or lower</param> 540 /// <param name="iterations">Maximum number of iterations for gradient descent.</param> 541 /// <param name="theta">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 non-sparse N*N matrix where N is the number of data points. This may exceed memory limitations.</param> 542 /// <param name="stopLyingIter">Number of iterations after which p is no longer approximated.</param> 543 /// <param name="momSwitchIter">Number of iterations after which the momentum in the gradient descent is switched.</param> 544 /// <param name="momentum">The initial momentum in the gradient descent.</param> 545 /// <param name="finalMomentum">The final momentum in gradient descent (after momentum switch).</param> 546 /// <param name="eta">Gradient descent learning rate.</param> 547 /// <returns></returns> 548 public static double[,] Run(T[] data, IDistance<T> distance, IRandom random, 549 int newDimensions = 2, double perplexity = 25, int iterations = 1000, 550 double theta = 0, 551 int stopLyingIter = 250, int momSwitchIter = 250, double momentum = .5, 552 double finalMomentum = .8, double eta = 200.0 553 ) { 554 var state = CreateState(data, distance, random, newDimensions, perplexity, 555 theta, stopLyingIter, momSwitchIter, momentum, finalMomentum, eta); 556 557 for(int i = 0; i < iterations - 1; i++) { 558 Iterate(state); 559 } 560 return Iterate(state); 561 } 562 563 public static TSNEState CreateState(T[] data, IDistance<T> distance, IRandom random, 564 int newDimensions = 2, double perplexity = 25, double theta = 0, 565 int stopLyingIter = 250, int momSwitchIter = 250, double momentum = .5, 566 double finalMomentum = .8, double eta = 200.0 532 567 ) { 533 568 return new TSNEState(data, distance, random, newDimensions, perplexity, theta, stopLyingIter, momSwitchIter, momentum, finalMomentum, eta); … … 564 599 // Make solution zero-mean 565 600 ZeroMean(state.newData); 601 566 602 // Stop lying about the P-values after a while, and switch momentum 567 568 603 if(state.iter == state.stopLyingIter) { 569 604 if(state.exact) 570 for(var i = 0; i < state.noDatapoints; i++) for(var j = 0; j < state.noDatapoints; j++) state.p[i, j] /= 12.0; //XXX why 12? 605 for(var i = 0; i < state.noDatapoints; i++) 606 for(var j = 0; j < state.noDatapoints; j++) 607 state.p[i, j] /= 12.0; //XXX why 12? 571 608 else 572 for(var i = 0; i < state.rowP[state.noDatapoints]; i++) state.valP[i] /= 12.0; // XXX are we not scaling all values? 609 for(var i = 0; i < state.rowP[state.noDatapoints]; i++) 610 state.valP[i] /= 12.0; // XXX are we not scaling all values? 573 611 } 574 612
Note: See TracChangeset
for help on using the changeset viewer.