/** * Constructor. Clustering data into k clusters. * @param data the dataset for clustering. * @param distance the distance/dissimilarity measure. * @param k the number of clusters. * @param maxNeighbor the maximum number of neighbors examined during a random search of local minima. */ public CLARANS(T[] data, Distance<T> distance, int k, int maxNeighbor) { this(data, distance, k, maxNeighbor, Math.max(2, MulticoreExecutor.getThreadPoolSize())); }
/** * Mines the frequent item sets. The discovered frequent item sets * will be printed out to the provided stream. * @param out a print stream for output of frequent item sets. * @return the number of discovered frequent item sets. */ private long learn(PrintStream out, List<ItemSet> list, TotalSupportTree ttree) { if (MulticoreExecutor.getThreadPoolSize() > 1) { return grow(out, list, ttree, T0, null, null, null); } else { return grow(out, list, ttree, T0, null); } }
/** Compute the Gaussian kernel (search the width for given perplexity. */ private double[][] expd(double[][] D, double perplexity, double tol) { int n = D.length; double[][] P = new double[n][n]; double[] DiSum = Math.rowSums(D); int nprocs = MulticoreExecutor.getThreadPoolSize(); int chunk = n / nprocs; List<PerplexityTask> tasks = new ArrayList<>(); for (int i = 0; i < nprocs; i++) { int start = i * chunk; int end = i == nprocs-1 ? n : (i+1) * chunk; PerplexityTask task = new PerplexityTask(start, end, D, P, DiSum, perplexity, tol); tasks.add(task); } try { MulticoreExecutor.run(tasks); } catch (Exception e) { logger.error("t-SNE Gaussian kernel width search task fails: {}", e); } return P; }
/** * Constructor. */ MultiClassObjectiveFunction(double[][] x, int[] y, int k, double lambda) { this.x = x; this.y = y; this.k = k; this.lambda = lambda; int n = x.length; int m = MulticoreExecutor.getThreadPoolSize(); if (n >= 1000 && m >= 2) { ftasks = new ArrayList<>(m + 1); gtasks = new ArrayList<>(m + 1); int step = n / m; if (step < 100) { step = 100; } int start = 0; int end = step; for (int i = 0; i < m - 1; i++) { ftasks.add(new FTask(start, end)); gtasks.add(new GTask(start, end)); start += step; end += step; } ftasks.add(new FTask(start, n)); gtasks.add(new GTask(start, n)); } }
int nprocs = MulticoreExecutor.getThreadPoolSize(); List<List<HeaderTableItem>> headers = new ArrayList<>(); for (int i = 0; i < 2*nprocs; i++) {
/** * Constructor. */ BinaryObjectiveFunction(double[][] x, int[] y, double lambda) { this.x = x; this.y = y; this.lambda = lambda; int n = x.length; int m = MulticoreExecutor.getThreadPoolSize(); if (n >= 1000 && m >= 2) { ftasks = new ArrayList<>(m + 1); gtasks = new ArrayList<>(m + 1); int step = n / m; if (step < 100) { step = 100; } int start = 0; int end = step; for (int i = 0; i < m - 1; i++) { ftasks.add(new FTask(start, end)); gtasks.add(new GTask(start, end)); start += step; end += step; } ftasks.add(new FTask(start, n)); gtasks.add(new GTask(start, n)); } }
int m = MulticoreExecutor.getThreadPoolSize(); if (n < 1000 || m < 2) { for (int i = 0; i < n; i++) {
int m = MulticoreExecutor.getThreadPoolSize(); if (n < 1000 || m < 2) { for (int i = 0; i < n; i++) {
int[] y = seed(data, k, ClusteringDistance.EUCLIDEAN_MISSING_VALUES); int np = MulticoreExecutor.getThreadPoolSize(); List<LloydThread> tasks = null; if (n >= 1000 && np >= 2) {
int d = Y[0].length; int nprocs = MulticoreExecutor.getThreadPoolSize(); int chunk = n / nprocs; List<SNETask> tasks = new ArrayList<>();
int m = MulticoreExecutor.getThreadPoolSize(); if (n < 1000 || m < 2) { for (int i = 0; i < n; i++) {
radius = new double[n]; int np = MulticoreExecutor.getThreadPoolSize(); List<DENCLUEThread> tasks = null; if (n >= 1000 && np >= 2) {
int m = MulticoreExecutor.getThreadPoolSize(); if (n < 1000 || m < 2) { for (int i = 0; i < n; i++) {
/** * Constructor. Clustering the data. * @param data the dataset for clustering. * @param distance the distance measure for neighborhood search. * @param k the number of clusters. Note that this is just a hint. The final * number of clusters may be less. * @param radius the neighborhood radius. */ public MEC(T[] data, Distance<T> distance, int k, double radius) { if (k < 2) { throw new IllegalArgumentException("Invalid k: " + k); } if (radius <= 0.0) { throw new IllegalArgumentException("Invalid radius: " + radius); } LinearSearch<T> naive = new LinearSearch<>(data, distance); naive.setIdenticalExcluded(false); // Initialize clusters with KMeans/CLARANS. if (data[0] instanceof double[] && distance instanceof EuclideanDistance) { KMeans kmeans = new KMeans((double[][]) data, k, 10, Math.max(1, MulticoreExecutor.getThreadPoolSize())); y = kmeans.getClusterLabel(); } else { CLARANS<T> clarans = new CLARANS<>(data, distance, k, Math.min(100, (int) Math.round(0.01 * k * (data.length - k))), Math.max(1, MulticoreExecutor.getThreadPoolSize())); y = clarans.getClusterLabel(); } learn(data, naive, k, radius, y); }
/** * Constructor. Clustering the data. * @param data the dataset for clustering. * @param distance the distance measure for neighborhood search. * @param k the number of clusters. Note that this is just a hint. The final * number of clusters may be less. * @param radius the neighborhood radius. */ public MEC(T[] data, Metric<T> distance, int k, double radius) { if (k < 2) { throw new IllegalArgumentException("Invalid k: " + k); } if (radius <= 0.0) { throw new IllegalArgumentException("Invalid radius: " + radius); } CoverTree<T> cover = new CoverTree<>(data, distance); cover.setIdenticalExcluded(false); // Initialize clusters with KMeans/CLARANS. if (data[0] instanceof double[] && distance instanceof EuclideanDistance) { KMeans kmeans = new KMeans((double[][]) data, k, 10, Math.max(1, MulticoreExecutor.getThreadPoolSize())); y = kmeans.getClusterLabel(); } else { CLARANS<T> clarans = new CLARANS<>(data, distance, k, Math.min(100, (int) Math.round(0.01 * k * (data.length - k))), Math.max(1, MulticoreExecutor.getThreadPoolSize())); y = clarans.getClusterLabel(); } learn(data, cover, k, radius, y); }
int m = MulticoreExecutor.getThreadPoolSize(); i.kcache = new DoubleArrayList(n); if (n < 100 || m < 2) {
double[] priori = new double[2 * Kmax]; int np = MulticoreExecutor.getThreadPoolSize(); if (n >= 1000 && np >= 2) { tasks = new ArrayList<>(np + 1);