MCPcopy Create free account
hub / github.com/EdwardRaff/JSAT / computeP

Method computeP

JSAT/src/jsat/datatransform/visualization/TSNE.java:348–516  ·  view source on GitHub ↗

@param d the dataset to search @param ex the source of threads for parallel computation @param rand source of randomness @param knn the number of neighbors to search for @param nearMe each row is the set of knn indices returned by the NN search @param nearMePij the symmetrized neighbor probability @

(DataSet d, ExecutorService ex, Random rand, final int knn, final int[][] nearMe, final double[][] nearMePij, final DistanceMetric dm, final double perplexity)

Source from the content-addressed store, hash-verified

346 * @param perplexity the perplexity value for the effective nearest neighbor search and weighting
347 */
348 protected static void computeP(DataSet d, ExecutorService ex, Random rand, final int knn, final int[][] nearMe, final double[][] nearMePij, final DistanceMetric dm, final double perplexity)
349 {
350 @SuppressWarnings("unchecked")
351 final List<Vec> vecs = d.getDataVectors();
352 final List<Double> accelCache = dm.getAccelerationCache(vecs, ex);
353 final int N = vecs.size();
354
355 final VPTreeMV<Vec> vp = new VPTreeMV<Vec>(vecs, dm, VPTree.VPSelection.Random, rand, 2, 1, ex);
356
357 final List<List<? extends VecPaired<Vec, Double>>> neighbors = new ArrayList<List<? extends VecPaired<Vec, Double>>>(N);
358 for(int i = 0; i < N; i++)
359 neighbors.add(null);
360
361
362
363 //new scope b/c I don't want to leark the silly vecIndex thing
364 {
365 //Used to map vecs back to their index so we can store only the ones we need in nearMe
366 final IdentityHashMap<Vec, Integer> vecIndex = new IdentityHashMap<Vec, Integer>(N);
367 for(int i = 0; i < N; i++)
368 vecIndex.put(vecs.get(i), i);
369
370 final CountDownLatch latch = new CountDownLatch(SystemInfo.LogicalCores);
371
372 for (int id = 0; id < SystemInfo.LogicalCores; id++)
373 {
374 final int ID = id;
375 ex.submit(new Runnable()
376 {
377 @Override
378 public void run()
379 {
380 for (int i = ID; i < N; i += SystemInfo.LogicalCores)//lets pre-compute the 3u nearesst neighbors used in eq(1)
381 {
382 Vec x_i = vecs.get(i);
383 List<? extends VecPaired<Vec, Double>> closest = vp.search(x_i, knn+1);//+1 b/c self is closest
384 neighbors.set(i, closest);
385 for (int j = 1; j < closest.size(); j++)
386 {
387 nearMe[i][j - 1] = vecIndex.get(closest.get(j).getVector());
388 }
389 }
390 latch.countDown();
391 }
392 });
393 }
394
395 try
396 {
397 latch.await();
398 }
399 catch (InterruptedException ex1)
400 {
401 Logger.getLogger(TSNE.class.getName()).log(Level.SEVERE, null, ex1);
402 }
403
404 }
405 //Now lets figure out everyone's sigmas

Callers 2

transformMethod · 0.95
transformMethod · 0.95

Calls 15

setMethod · 0.95
getMethod · 0.95
getDataVectorsMethod · 0.80
submitMethod · 0.80
logMethod · 0.80
getAccelerationCacheMethod · 0.65
sizeMethod · 0.65
getNameMethod · 0.65
addMethod · 0.45
putMethod · 0.45
getMethod · 0.45
awaitMethod · 0.45

Tested by

no test coverage detected