Skip to content

Commit

Permalink
set default learning rate to 200
Browse files Browse the repository at this point in the history
  • Loading branch information
haifengl committed Aug 6, 2017
1 parent 3dc37a2 commit fd9d6a8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 8 deletions.
8 changes: 2 additions & 6 deletions core/src/main/java/smile/manifold/TSNE.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class TSNE {
* @param d the dimension of embedding space.
*/
public TSNE(double[][] X, int d) {
this(X, d, 20, 500, 1000);
this(X, d, 20, 200, 1000);
}

/** Constructor.
Expand Down Expand Up @@ -264,7 +264,7 @@ private void compute(int i) {
// Perform the update
for (int k = 0; k < d; k++) {
// Update gains
g[k] = (signum(dC[k]) != signum(dYi[k])) ? (g[k] + .2) : (g[k] * .8);
g[k] = (Math.signum(dC[k]) != Math.signum(dYi[k])) ? (g[k] + .2) : (g[k] * .8);
if (g[k] < minGain) g[k] = minGain;

// gradient update with momentum and gains
Expand All @@ -274,10 +274,6 @@ private void compute(int i) {
}
}

private int signum(double x) {
return (x == .0 ? 0 : (x < .0 ? -1 : 1));
}

/** Compute the Gaussian kernel (search the width for given perplexity. */
private double[][] expd(double[][] D, double perplexity, double tol) {
int n = D.length;
Expand Down
2 changes: 1 addition & 1 deletion demo/src/main/java/smile/demo/manifold/TSNEDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public JComponent learn() {
pca.setProjection(50);
double[][] X = pca.project(data);
long clock = System.currentTimeMillis();
TSNE tsne = new TSNE(X, 2, perplexity, 500, 1000);
TSNE tsne = new TSNE(X, 2, perplexity, 200, 1000);
System.out.format("Learn t-SNE from %d samples in %dms\n", data.length, System.currentTimeMillis() - clock);

double[][] y = tsne.getCoordinates();
Expand Down
2 changes: 1 addition & 1 deletion scala/src/main/scala/smile/manifold/Operators.scala
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ trait Operators {
* @param eta the learning rate.
* @param iterations the number of iterations.
*/
def tsne(X: Array[Array[Double]], d: Int = 2, perplexity: Double = 20.0, eta: Double = 500.0, iterations: Int = 1000): TSNE = {
def tsne(X: Array[Array[Double]], d: Int = 2, perplexity: Double = 20.0, eta: Double = 200.0, iterations: Int = 1000): TSNE = {
time {
new TSNE(X, d, perplexity, eta, iterations)
}
Expand Down

0 comments on commit fd9d6a8

Please sign in to comment.