List of usage examples for java.util TreeMap get
public V get(Object key)
From source file:org.apache.hadoop.mapred.HFSPScheduler.java
private void assignSizeBasedTasks(TaskType type, HelperForType helper, TreeMap<JobDurationInfo, JobInProgress> sizeBasedJobs, TreeMap<JobDurationInfo, TaskStatuses> taskStatusesSizeBased) throws IOException { final boolean isMap = type == TaskType.MAP; int totClaimedSlots = 0; // StringBuilder builder = new StringBuilder("SBJobs("); // builder.append(type).append("): ["); // boolean first = true; // for (Entry<JobDurationInfo,JobInProgress> jip : sizeBasedJobs.entrySet()) // {// w w w .j a v a 2 s . c o m // if (first) // first = false; // else // builder.append(","); // builder.append(jip.getValue().getJobID()) // .append(" -> ") // .append(jip.getKey().getPhaseDuration()) // .append("/") // .append(jip.getKey().getPhaseTotalDuration()) // .append(" p: ") // .append(this.getNumPendingNewTasks(jip.getValue(), type)) // .append(" r: ") // .append(this.getNumRunningTasks(jip.getValue(), type)) // .append(" f: ") // .append(this.getNumFinishedTasks(jip.getValue(), type)); // } // builder.append("]"); // LOG.debug(builder.toString()); for (Entry<JobDurationInfo, JobInProgress> entry : sizeBasedJobs.entrySet()) { JobInProgress jip = entry.getValue(); JobDurationInfo jdi = entry.getKey(); TaskStatuses taskStatuses = taskStatusesSizeBased.get(jdi); if (!this.isJobReadyForTypeScheduling(jip, type)) { if (LOG.isDebugEnabled() && jip.getStatus().getRunState() != JobStatus.SUCCEEDED) { LOG.debug( "SIZEBASED(" + jip.getJobID() + ":" + type + "):" + "job is not ready for scheduling (" + "status: " + JobStatus.getJobRunState(jip.getStatus().getRunState()) + ", mapProgress: " + jip.getStatus().mapProgress() + ", reduceProgress: " + jip.getStatus().reduceProgress() + ", scheduleReduces: " + jip.scheduleReduces() + ")"); } continue; } // NEW int pendingNewTasks = this.getNumPendingNewTasks(jip, type); int pendingResumableTasks = (taskStatuses == null) ? 0 : taskStatuses.suspendedTaskStatuses.size(); int totAvailableSizeBasedSlots = helper.totAvailableSizeBasedSlots(); // missing slots for resumable int missingResumableSlots = 0; if (pendingResumableTasks > 0 && pendingResumableTasks > totAvailableSizeBasedSlots) { if (totAvailableSizeBasedSlots <= 0) missingResumableSlots = pendingResumableTasks; else missingResumableSlots = pendingResumableTasks - totAvailableSizeBasedSlots; totAvailableSizeBasedSlots = (pendingResumableTasks > totAvailableSizeBasedSlots) ? 0 : totAvailableSizeBasedSlots - pendingResumableTasks; } int missingNewSlots = 0; if (pendingNewTasks > 0 && pendingNewTasks > totAvailableSizeBasedSlots) { if (totAvailableSizeBasedSlots <= 0) missingNewSlots = pendingNewTasks; else missingNewSlots = pendingNewTasks - totAvailableSizeBasedSlots; totAvailableSizeBasedSlots = (pendingNewTasks > totAvailableSizeBasedSlots) ? 0 : totAvailableSizeBasedSlots - pendingNewTasks; } TreeMap<TaskAttemptID, TaskStatus> suspended = null; if (taskStatuses != null) suspended = taskStatuses.suspendedTaskStatuses; if (pendingNewTasks > 0 || pendingResumableTasks > 0 || (suspended != null && !suspended.isEmpty())) { LOG.debug(jip.getJobID() + ":" + type + " (d: " + jdi.getPhaseDuration() + "/" + jdi.getPhaseTotalDuration() + "):" + " pendingNewTasks: " + pendingNewTasks + " pendingResumableTasks: " + pendingResumableTasks // + " notResumableTasksOnThisTT: " + notResumableTasks + " totAvailableSizeBasedSlots: " + (helper.totAvailableSizeBasedSlots() <= 0 ? 0 : helper.totAvailableSizeBasedSlots()) + " currAvailableSlots: " + helper.currAvailableSlots + " => missingNewSlots: " + missingNewSlots + " missingResumableSlots: " + missingResumableSlots); } if (this.preemptionStrategy.isPreemptionActive() && (missingNewSlots > 0 || missingResumableSlots > 0)) { ClaimedSlots claimedSlots = this.claimSlots(helper, Phase.SIZE_BASED, jip, missingNewSlots, missingResumableSlots, totClaimedSlots, sizeBasedJobs, taskStatusesSizeBased); totClaimedSlots += claimedSlots.getNumPreemptedForNewTasks() + claimedSlots.getNumPreemptedForResumableTasks(); LOG.debug(jip.getJobID() + " taskStatusesOnTT: " + taskStatusesSizeBased.get(jdi) + " pendingNewTasks: " + pendingNewTasks + " pendingResumableTasks: " + pendingResumableTasks + " missingNewSlots: " + missingNewSlots + " missingResumableSlots: " + missingResumableSlots); } while (pendingNewTasks > 0 || pendingResumableTasks > 0 || (suspended != null && !suspended.isEmpty())) { if (helper.currAvailableSlots <= 0) { LOG.debug("SIZEBASED(" + jip.getJobID() + ":" + type + "):" + " no slots available on " + taskHelper.ttStatus.getTrackerName()); return; } LOG.debug("SIZEBASED(" + jip.getJobID() + ":" + type + "):" + " totAvailableSizeBasedSlots(): " + helper.totAvailableSizeBasedSlots() + " pendingNewTasks: " + pendingNewTasks + " pendingResumableTasks: " + pendingResumableTasks + " suspended(" + (suspended == null ? 0 : suspended.size()) + "): " + suspended); if (this.preemptionStrategy.isPreemptionActive() && (suspended != null && !suspended.isEmpty())) { TaskStatus toResume = suspended.remove(suspended.firstKey()); // LOG.debug("RESUME: " + toResume.getTaskID() + " " + // toResume.getRunState()); TaskAttemptID tAID = toResume.getTaskID(); JobInProgress rJIP = this.taskTrackerManager.getJob(tAID.getTaskID().getJobID()); TaskInProgress tip = rJIP.getTaskInProgress(tAID.getTaskID()); if (this.preemptionStrategy.resume(tip, toResume)) { taskHelper.resume(tAID, Phase.SIZE_BASED); pendingResumableTasks -= 1; } else { LOG.debug("SIZEBASED(" + jip.getJobID() + ":" + type + "):" + " cannot resume " + tAID + " on " + taskHelper.ttStatus.getTrackerName()); } } else { Task task = this.obtainNewTask(jip, taskHelper.ttStatus, isMap, taskHelper.currentTime); if (task == null) { LOG.debug("SIZEBASED(" + jip.getJobID() + ":" + type + "):" + " cannot obtain slot for new task on " + taskHelper.ttStatus.getTrackerName() + " (#pendingNew: " + pendingNewTasks + ", #pendingResumable: " + pendingResumableTasks + ", #free_" + type + "_slots: " + helper.currAvailableSlots + ")"); break; } taskHelper.slotObtained(task, Phase.SIZE_BASED); pendingNewTasks -= 1; } } } }
From source file:com.clust4j.algo.HDBSCANTests.java
@Test public void testPrimLinkage() { KDTree k = new KDTree(iris); double[] core_dists = MatUtils.getColumn(k.query(iris.getDataRef(), 5, true, true).getDistances(), 4); double[][] X = iris.getData(); DistanceMetric metric = Distance.EUCLIDEAN; double alpha = 1.0; double[][] cdist = HDBSCAN.LinkageTreeUtils.minSpanTreeLinkageCore_cdist(X, core_dists, metric, alpha); double[][] expected_cdists = new double[][] { new double[] { 0.00000000e+00, 3.90000000e+01, 1.41421356e-01 }, new double[] { 3.90000000e+01, 1.70000000e+01, 1.73205081e-01 }, new double[] { 1.70000000e+01, 2.70000000e+01, 1.73205081e-01 }, new double[] { 2.70000000e+01, 2.80000000e+01, 1.73205081e-01 }, new double[] { 2.80000000e+01, 7.00000000e+00, 2.00000000e-01 }, new double[] { 7.00000000e+00, 4.90000000e+01, 2.23606798e-01 }, new double[] { 4.90000000e+01, 4.00000000e+00, 2.23606798e-01 }, new double[] { 4.00000000e+00, 2.60000000e+01, 2.44948974e-01 }, new double[] { 2.60000000e+01, 4.00000000e+01, 2.44948974e-01 }, new double[] { 4.00000000e+01, 4.80000000e+01, 2.44948974e-01 }, new double[] { 4.80000000e+01, 9.00000000e+00, 2.64575131e-01 }, new double[] { 9.00000000e+00, 1.00000000e+00, 1.73205081e-01 }, new double[] { 1.00000000e+00, 3.00000000e+01, 1.73205081e-01 }, new double[] { 3.00000000e+01, 3.40000000e+01, 1.73205081e-01 }, new double[] { 3.40000000e+01, 3.70000000e+01, 1.73205081e-01 }, new double[] { 3.70000000e+01, 1.20000000e+01, 1.73205081e-01 }, new double[] { 1.20000000e+01, 2.50000000e+01, 2.23606798e-01 }, new double[] { 2.50000000e+01, 2.90000000e+01, 2.23606798e-01 }, new double[] { 2.90000000e+01, 4.70000000e+01, 2.23606798e-01 }, new double[] { 4.70000000e+01, 3.00000000e+00, 2.44948974e-01 }, new double[] { 3.00000000e+00, 1.90000000e+01, 2.64575131e-01 }, new double[] { 1.90000000e+01, 2.00000000e+00, 2.64575131e-01 }, new double[] { 2.00000000e+00, 2.10000000e+01, 2.64575131e-01 }, new double[] { 2.10000000e+01, 4.50000000e+01, 2.64575131e-01 }, new double[] { 4.50000000e+01, 3.80000000e+01, 3.00000000e-01 }, new double[] { 3.80000000e+01, 1.10000000e+01, 3.00000000e-01 }, new double[] { 1.10000000e+01, 4.20000000e+01, 3.00000000e-01 }, new double[] { 4.20000000e+01, 4.60000000e+01, 3.00000000e-01 }, new double[] { 4.60000000e+01, 6.00000000e+00, 3.16227766e-01 }, new double[] { 6.00000000e+00, 3.10000000e+01, 3.16227766e-01 }, new double[] { 3.10000000e+01, 3.50000000e+01, 3.31662479e-01 }, new double[] { 3.50000000e+01, 1.00000000e+01, 3.31662479e-01 }, new double[] { 1.00000000e+01, 8.00000000e+00, 3.46410162e-01 }, new double[] { 8.00000000e+00, 3.60000000e+01, 3.46410162e-01 }, new double[] { 3.60000000e+01, 2.00000000e+01, 3.60555128e-01 }, new double[] { 2.00000000e+01, 4.30000000e+01, 3.74165739e-01 }, new double[] { 4.30000000e+01, 5.00000000e+00, 3.74165739e-01 }, new double[] { 5.00000000e+00, 2.30000000e+01, 3.87298335e-01 }, new double[] { 2.30000000e+01, 1.60000000e+01, 3.87298335e-01 }, new double[] { 1.60000000e+01, 4.40000000e+01, 4.12310563e-01 }, new double[] { 4.40000000e+01, 3.30000000e+01, 4.12310563e-01 }, new double[] { 3.30000000e+01, 3.20000000e+01, 4.24264069e-01 }, new double[] { 3.20000000e+01, 2.40000000e+01, 4.24264069e-01 }, new double[] { 2.40000000e+01, 1.30000000e+01, 4.79583152e-01 }, new double[] { 1.30000000e+01, 1.80000000e+01, 5.09901951e-01 }, new double[] { 1.80000000e+01, 2.20000000e+01, 5.38516481e-01 }, new double[] { 2.20000000e+01, 1.40000000e+01, 5.56776436e-01 }, new double[] { 1.40000000e+01, 1.50000000e+01, 6.16441400e-01 }, new double[] { 1.50000000e+01, 4.10000000e+01, 7.81024968e-01 }, new double[] { 4.10000000e+01, 9.80000000e+01, 1.64012195e+00 }, new double[] { 9.80000000e+01, 5.70000000e+01, 7.93725393e-01 }, new double[] { 5.70000000e+01, 6.00000000e+01, 7.21110255e-01 }, new double[] { 6.00000000e+01, 8.00000000e+01, 7.14142843e-01 }, new double[] { 8.00000000e+01, 6.90000000e+01, 3.00000000e-01 }, new double[] { 6.90000000e+01, 9.20000000e+01, 2.64575131e-01 }, new double[] { 9.20000000e+01, 9.90000000e+01, 2.64575131e-01 }, new double[] { 9.90000000e+01, 9.60000000e+01, 2.44948974e-01 }, new double[] { 9.60000000e+01, 8.20000000e+01, 3.00000000e-01 }, new double[] { 8.20000000e+01, 8.90000000e+01, 3.00000000e-01 }, new double[] { 8.90000000e+01, 9.40000000e+01, 3.00000000e-01 }, new double[] { 9.40000000e+01, 8.80000000e+01, 3.16227766e-01 }, new double[] { 8.80000000e+01, 5.50000000e+01, 3.31662479e-01 }, new double[] { 5.50000000e+01, 9.50000000e+01, 3.31662479e-01 }, new double[] { 9.50000000e+01, 6.70000000e+01, 3.60555128e-01 }, new double[] { 6.70000000e+01, 6.10000000e+01, 3.60555128e-01 }, new double[] { 6.10000000e+01, 7.80000000e+01, 3.60555128e-01 }, new double[] { 7.80000000e+01, 9.10000000e+01, 3.46410162e-01 }, new double[] { 9.10000000e+01, 9.70000000e+01, 3.46410162e-01 }, new double[] { 9.70000000e+01, 7.40000000e+01, 3.87298335e-01 }, new double[] { 7.40000000e+01, 5.40000000e+01, 3.87298335e-01 }, new double[] { 5.40000000e+01, 5.80000000e+01, 3.74165739e-01 }, new double[] { 5.80000000e+01, 7.50000000e+01, 3.16227766e-01 }, new double[] { 7.50000000e+01, 8.60000000e+01, 3.31662479e-01 }, new double[] { 8.60000000e+01, 6.50000000e+01, 3.46410162e-01 }, new double[] { 6.50000000e+01, 5.20000000e+01, 3.46410162e-01 }, new double[] { 5.20000000e+01, 5.10000000e+01, 3.74165739e-01 }, new double[] { 5.10000000e+01, 7.60000000e+01, 3.74165739e-01 }, new double[] { 7.60000000e+01, 7.10000000e+01, 4.00000000e-01 }, new double[] { 7.10000000e+01, 6.60000000e+01, 4.12310563e-01 }, new double[] { 6.60000000e+01, 7.70000000e+01, 4.24264069e-01 }, new double[] { 7.70000000e+01, 1.47000000e+02, 4.24264069e-01 }, new double[] { 1.47000000e+02, 1.45000000e+02, 3.74165739e-01 }, new double[] { 1.45000000e+02, 1.12000000e+02, 3.74165739e-01 }, new double[] { 1.12000000e+02, 1.20000000e+02, 3.74165739e-01 }, new double[] { 1.20000000e+02, 1.40000000e+02, 3.46410162e-01 }, new double[] { 1.40000000e+02, 1.43000000e+02, 3.46410162e-01 }, new double[] { 1.43000000e+02, 1.39000000e+02, 3.74165739e-01 }, new double[] { 1.39000000e+02, 1.24000000e+02, 3.74165739e-01 }, new double[] { 1.24000000e+02, 1.15000000e+02, 3.87298335e-01 }, new double[] { 1.15000000e+02, 1.11000000e+02, 3.87298335e-01 }, new double[] { 1.11000000e+02, 1.03000000e+02, 3.87298335e-01 }, new double[] { 1.03000000e+02, 1.16000000e+02, 3.87298335e-01 }, new double[] { 1.16000000e+02, 1.28000000e+02, 3.87298335e-01 }, new double[] { 1.28000000e+02, 1.04000000e+02, 3.87298335e-01 }, new double[] { 1.04000000e+02, 1.44000000e+02, 4.00000000e-01 }, new double[] { 1.44000000e+02, 1.46000000e+02, 4.12310563e-01 }, new double[] { 1.46000000e+02, 1.23000000e+02, 4.12310563e-01 }, new double[] { 1.23000000e+02, 1.27000000e+02, 3.60555128e-01 }, new double[] { 1.27000000e+02, 1.38000000e+02, 3.16227766e-01 }, new double[] { 1.38000000e+02, 1.49000000e+02, 3.31662479e-01 }, new double[] { 1.49000000e+02, 1.01000000e+02, 3.31662479e-01 }, new double[] { 1.01000000e+02, 1.42000000e+02, 3.31662479e-01 }, new double[] { 1.42000000e+02, 8.30000000e+01, 3.74165739e-01 }, new double[] { 8.30000000e+01, 1.26000000e+02, 3.87298335e-01 }, new double[] { 1.26000000e+02, 7.00000000e+01, 4.24264069e-01 }, new double[] { 7.00000000e+01, 7.20000000e+01, 4.24264069e-01 }, new double[] { 7.20000000e+01, 1.10000000e+02, 4.24264069e-01 }, new double[] { 1.10000000e+02, 9.00000000e+01, 4.24264069e-01 }, new double[] { 9.00000000e+01, 6.30000000e+01, 4.24264069e-01 }, new double[] { 6.30000000e+01, 1.33000000e+02, 4.35889894e-01 }, new double[] { 1.33000000e+02, 5.30000000e+01, 4.35889894e-01 }, new double[] { 5.30000000e+01, 8.10000000e+01, 4.35889894e-01 }, new double[] { 8.10000000e+01, 1.32000000e+02, 4.35889894e-01 }, new double[] { 1.32000000e+02, 1.37000000e+02, 4.35889894e-01 }, new double[] { 1.37000000e+02, 7.30000000e+01, 4.35889894e-01 }, new double[] { 7.30000000e+01, 1.36000000e+02, 4.35889894e-01 }, new double[] { 1.36000000e+02, 7.90000000e+01, 4.47213595e-01 }, new double[] { 7.90000000e+01, 5.60000000e+01, 4.58257569e-01 }, new double[] { 5.60000000e+01, 1.21000000e+02, 4.58257569e-01 }, new double[] { 1.21000000e+02, 5.00000000e+01, 4.58257569e-01 }, new double[] { 5.00000000e+01, 1.02000000e+02, 4.58257569e-01 }, new double[] { 1.02000000e+02, 8.50000000e+01, 4.69041576e-01 }, new double[] { 8.50000000e+01, 1.25000000e+02, 4.69041576e-01 }, new double[] { 1.25000000e+02, 8.40000000e+01, 4.89897949e-01 }, new double[] { 8.40000000e+01, 1.30000000e+02, 5.09901951e-01 }, new double[] { 1.30000000e+02, 1.41000000e+02, 5.09901951e-01 }, new double[] { 1.41000000e+02, 6.40000000e+01, 5.19615242e-01 }, new double[] { 6.40000000e+01, 1.13000000e+02, 5.19615242e-01 }, new double[] { 1.13000000e+02, 1.14000000e+02, 5.19615242e-01 }, new double[] { 1.14000000e+02, 5.90000000e+01, 5.29150262e-01 }, new double[] { 5.90000000e+01, 1.07000000e+02, 5.47722558e-01 }, new double[] { 1.07000000e+02, 1.05000000e+02, 5.47722558e-01 }, new double[] { 1.05000000e+02, 1.29000000e+02, 5.56776436e-01 }, new double[] { 1.29000000e+02, 1.00000000e+02, 5.56776436e-01 }, new double[] { 1.00000000e+02, 1.19000000e+02, 5.83095189e-01 }, new double[] { 1.19000000e+02, 6.20000000e+01, 5.83095189e-01 }, new double[] { 6.20000000e+01, 8.70000000e+01, 6.08276253e-01 }, new double[] { 8.70000000e+01, 1.48000000e+02, 6.16441400e-01 }, new double[] { 1.48000000e+02, 1.08000000e+02, 6.16441400e-01 }, new double[] { 1.08000000e+02, 9.30000000e+01, 6.48074070e-01 }, new double[] { 9.30000000e+01, 1.34000000e+02, 6.63324958e-01 }, new double[] { 1.34000000e+02, 6.80000000e+01, 6.78232998e-01 }, new double[] { 6.80000000e+01, 1.35000000e+02, 6.78232998e-01 }, new double[] { 1.35000000e+02, 1.22000000e+02, 6.78232998e-01 }, new double[] { 1.22000000e+02, 1.09000000e+02, 7.54983444e-01 }, new double[] { 1.09000000e+02, 1.06000000e+02, 8.77496439e-01 }, new double[] { 1.06000000e+02, 1.18000000e+02, 9.27361850e-01 }, new double[] { 1.18000000e+02, 1.31000000e+02, 9.32737905e-01 }, new double[] { 1.31000000e+02, 1.17000000e+02, 1.00498756e+00 } }; assertTrue(MatUtils.equalsWithTolerance(cdist, expected_cdists, 1e-8)); double[][] srtd_cdists = MatUtils.sortAscByCol(cdist, 2); double[][] expected_srted = new double[][] { new double[] { 0.00000000e+00, 3.90000000e+01, 1.41421356e-01 }, new double[] { 3.90000000e+01, 1.70000000e+01, 1.73205081e-01 }, new double[] { 1.70000000e+01, 2.70000000e+01, 1.73205081e-01 }, new double[] { 2.70000000e+01, 2.80000000e+01, 1.73205081e-01 }, new double[] { 3.40000000e+01, 3.70000000e+01, 1.73205081e-01 }, new double[] { 3.00000000e+01, 3.40000000e+01, 1.73205081e-01 }, new double[] { 9.00000000e+00, 1.00000000e+00, 1.73205081e-01 }, new double[] { 1.00000000e+00, 3.00000000e+01, 1.73205081e-01 }, new double[] { 3.70000000e+01, 1.20000000e+01, 1.73205081e-01 }, new double[] { 2.80000000e+01, 7.00000000e+00, 2.00000000e-01 }, new double[] { 1.20000000e+01, 2.50000000e+01, 2.23606798e-01 }, new double[] { 7.00000000e+00, 4.90000000e+01, 2.23606798e-01 }, new double[] { 4.90000000e+01, 4.00000000e+00, 2.23606798e-01 }, new double[] { 2.90000000e+01, 4.70000000e+01, 2.23606798e-01 }, new double[] { 2.50000000e+01, 2.90000000e+01, 2.23606798e-01 }, new double[] { 4.00000000e+00, 2.60000000e+01, 2.44948974e-01 }, new double[] { 2.60000000e+01, 4.00000000e+01, 2.44948974e-01 }, new double[] { 4.00000000e+01, 4.80000000e+01, 2.44948974e-01 }, new double[] { 4.70000000e+01, 3.00000000e+00, 2.44948974e-01 }, new double[] { 9.90000000e+01, 9.60000000e+01, 2.44948974e-01 }, new double[] { 4.80000000e+01, 9.00000000e+00, 2.64575131e-01 }, new double[] { 3.00000000e+00, 1.90000000e+01, 2.64575131e-01 }, new double[] { 1.90000000e+01, 2.00000000e+00, 2.64575131e-01 }, new double[] { 2.00000000e+00, 2.10000000e+01, 2.64575131e-01 }, new double[] { 2.10000000e+01, 4.50000000e+01, 2.64575131e-01 }, new double[] { 9.20000000e+01, 9.90000000e+01, 2.64575131e-01 }, new double[] { 6.90000000e+01, 9.20000000e+01, 2.64575131e-01 }, new double[] { 4.50000000e+01, 3.80000000e+01, 3.00000000e-01 }, new double[] { 4.20000000e+01, 4.60000000e+01, 3.00000000e-01 }, new double[] { 3.80000000e+01, 1.10000000e+01, 3.00000000e-01 }, new double[] { 1.10000000e+01, 4.20000000e+01, 3.00000000e-01 }, new double[] { 8.00000000e+01, 6.90000000e+01, 3.00000000e-01 }, new double[] { 8.90000000e+01, 9.40000000e+01, 3.00000000e-01 }, new double[] { 8.20000000e+01, 8.90000000e+01, 3.00000000e-01 }, new double[] { 9.60000000e+01, 8.20000000e+01, 3.00000000e-01 }, new double[] { 4.60000000e+01, 6.00000000e+00, 3.16227766e-01 }, new double[] { 1.27000000e+02, 1.38000000e+02, 3.16227766e-01 }, new double[] { 6.00000000e+00, 3.10000000e+01, 3.16227766e-01 }, new double[] { 9.40000000e+01, 8.80000000e+01, 3.16227766e-01 }, new double[] { 5.80000000e+01, 7.50000000e+01, 3.16227766e-01 }, new double[] { 8.80000000e+01, 5.50000000e+01, 3.31662479e-01 }, new double[] { 3.10000000e+01, 3.50000000e+01, 3.31662479e-01 }, new double[] { 7.50000000e+01, 8.60000000e+01, 3.31662479e-01 }, new double[] { 1.38000000e+02, 1.49000000e+02, 3.31662479e-01 }, new double[] { 1.49000000e+02, 1.01000000e+02, 3.31662479e-01 }, new double[] { 1.01000000e+02, 1.42000000e+02, 3.31662479e-01 }, new double[] { 5.50000000e+01, 9.50000000e+01, 3.31662479e-01 }, new double[] { 3.50000000e+01, 1.00000000e+01, 3.31662479e-01 }, new double[] { 8.60000000e+01, 6.50000000e+01, 3.46410162e-01 }, new double[] { 1.00000000e+01, 8.00000000e+00, 3.46410162e-01 }, new double[] { 8.00000000e+00, 3.60000000e+01, 3.46410162e-01 }, new double[] { 7.80000000e+01, 9.10000000e+01, 3.46410162e-01 }, new double[] { 9.10000000e+01, 9.70000000e+01, 3.46410162e-01 }, new double[] { 1.20000000e+02, 1.40000000e+02, 3.46410162e-01 }, new double[] { 1.40000000e+02, 1.43000000e+02, 3.46410162e-01 }, new double[] { 6.50000000e+01, 5.20000000e+01, 3.46410162e-01 }, new double[] { 9.50000000e+01, 6.70000000e+01, 3.60555128e-01 }, new double[] { 1.23000000e+02, 1.27000000e+02, 3.60555128e-01 }, new double[] { 3.60000000e+01, 2.00000000e+01, 3.60555128e-01 }, new double[] { 6.10000000e+01, 7.80000000e+01, 3.60555128e-01 }, new double[] { 6.70000000e+01, 6.10000000e+01, 3.60555128e-01 }, new double[] { 1.12000000e+02, 1.20000000e+02, 3.74165739e-01 }, new double[] { 1.45000000e+02, 1.12000000e+02, 3.74165739e-01 }, new double[] { 1.47000000e+02, 1.45000000e+02, 3.74165739e-01 }, new double[] { 1.42000000e+02, 8.30000000e+01, 3.74165739e-01 }, new double[] { 1.43000000e+02, 1.39000000e+02, 3.74165739e-01 }, new double[] { 1.39000000e+02, 1.24000000e+02, 3.74165739e-01 }, new double[] { 5.20000000e+01, 5.10000000e+01, 3.74165739e-01 }, new double[] { 5.10000000e+01, 7.60000000e+01, 3.74165739e-01 }, new double[] { 2.00000000e+01, 4.30000000e+01, 3.74165739e-01 }, new double[] { 5.40000000e+01, 5.80000000e+01, 3.74165739e-01 }, new double[] { 4.30000000e+01, 5.00000000e+00, 3.74165739e-01 }, new double[] { 7.40000000e+01, 5.40000000e+01, 3.87298335e-01 }, new double[] { 9.70000000e+01, 7.40000000e+01, 3.87298335e-01 }, new double[] { 1.24000000e+02, 1.15000000e+02, 3.87298335e-01 }, new double[] { 1.16000000e+02, 1.28000000e+02, 3.87298335e-01 }, new double[] { 1.03000000e+02, 1.16000000e+02, 3.87298335e-01 }, new double[] { 1.11000000e+02, 1.03000000e+02, 3.87298335e-01 }, new double[] { 1.15000000e+02, 1.11000000e+02, 3.87298335e-01 }, new double[] { 8.30000000e+01, 1.26000000e+02, 3.87298335e-01 }, new double[] { 1.28000000e+02, 1.04000000e+02, 3.87298335e-01 }, new double[] { 5.00000000e+00, 2.30000000e+01, 3.87298335e-01 }, new double[] { 2.30000000e+01, 1.60000000e+01, 3.87298335e-01 }, new double[] { 7.60000000e+01, 7.10000000e+01, 4.00000000e-01 }, new double[] { 1.04000000e+02, 1.44000000e+02, 4.00000000e-01 }, new double[] { 1.46000000e+02, 1.23000000e+02, 4.12310563e-01 }, new double[] { 1.44000000e+02, 1.46000000e+02, 4.12310563e-01 }, new double[] { 1.60000000e+01, 4.40000000e+01, 4.12310563e-01 }, new double[] { 4.40000000e+01, 3.30000000e+01, 4.12310563e-01 }, new double[] { 7.10000000e+01, 6.60000000e+01, 4.12310563e-01 }, new double[] { 3.30000000e+01, 3.20000000e+01, 4.24264069e-01 }, new double[] { 1.26000000e+02, 7.00000000e+01, 4.24264069e-01 }, new double[] { 7.00000000e+01, 7.20000000e+01, 4.24264069e-01 }, new double[] { 3.20000000e+01, 2.40000000e+01, 4.24264069e-01 }, new double[] { 7.70000000e+01, 1.47000000e+02, 4.24264069e-01 }, new double[] { 6.60000000e+01, 7.70000000e+01, 4.24264069e-01 }, new double[] { 7.20000000e+01, 1.10000000e+02, 4.24264069e-01 }, new double[] { 1.10000000e+02, 9.00000000e+01, 4.24264069e-01 }, new double[] { 9.00000000e+01, 6.30000000e+01, 4.24264069e-01 }, new double[] { 6.30000000e+01, 1.33000000e+02, 4.35889894e-01 }, new double[] { 5.30000000e+01, 8.10000000e+01, 4.35889894e-01 }, new double[] { 1.33000000e+02, 5.30000000e+01, 4.35889894e-01 }, new double[] { 8.10000000e+01, 1.32000000e+02, 4.35889894e-01 }, new double[] { 1.32000000e+02, 1.37000000e+02, 4.35889894e-01 }, new double[] { 7.30000000e+01, 1.36000000e+02, 4.35889894e-01 }, new double[] { 1.37000000e+02, 7.30000000e+01, 4.35889894e-01 }, new double[] { 1.36000000e+02, 7.90000000e+01, 4.47213595e-01 }, new double[] { 7.90000000e+01, 5.60000000e+01, 4.58257569e-01 }, new double[] { 5.60000000e+01, 1.21000000e+02, 4.58257569e-01 }, new double[] { 1.21000000e+02, 5.00000000e+01, 4.58257569e-01 }, new double[] { 5.00000000e+01, 1.02000000e+02, 4.58257569e-01 }, new double[] { 1.02000000e+02, 8.50000000e+01, 4.69041576e-01 }, new double[] { 8.50000000e+01, 1.25000000e+02, 4.69041576e-01 }, new double[] { 2.40000000e+01, 1.30000000e+01, 4.79583152e-01 }, new double[] { 1.25000000e+02, 8.40000000e+01, 4.89897949e-01 }, new double[] { 1.30000000e+01, 1.80000000e+01, 5.09901951e-01 }, new double[] { 8.40000000e+01, 1.30000000e+02, 5.09901951e-01 }, new double[] { 1.30000000e+02, 1.41000000e+02, 5.09901951e-01 }, new double[] { 1.41000000e+02, 6.40000000e+01, 5.19615242e-01 }, new double[] { 6.40000000e+01, 1.13000000e+02, 5.19615242e-01 }, new double[] { 1.13000000e+02, 1.14000000e+02, 5.19615242e-01 }, new double[] { 1.14000000e+02, 5.90000000e+01, 5.29150262e-01 }, new double[] { 1.80000000e+01, 2.20000000e+01, 5.38516481e-01 }, new double[] { 5.90000000e+01, 1.07000000e+02, 5.47722558e-01 }, new double[] { 1.07000000e+02, 1.05000000e+02, 5.47722558e-01 }, new double[] { 1.05000000e+02, 1.29000000e+02, 5.56776436e-01 }, new double[] { 2.20000000e+01, 1.40000000e+01, 5.56776436e-01 }, new double[] { 1.29000000e+02, 1.00000000e+02, 5.56776436e-01 }, new double[] { 1.00000000e+02, 1.19000000e+02, 5.83095189e-01 }, new double[] { 1.19000000e+02, 6.20000000e+01, 5.83095189e-01 }, new double[] { 6.20000000e+01, 8.70000000e+01, 6.08276253e-01 }, new double[] { 8.70000000e+01, 1.48000000e+02, 6.16441400e-01 }, new double[] { 1.48000000e+02, 1.08000000e+02, 6.16441400e-01 }, new double[] { 1.40000000e+01, 1.50000000e+01, 6.16441400e-01 }, new double[] { 1.08000000e+02, 9.30000000e+01, 6.48074070e-01 }, new double[] { 9.30000000e+01, 1.34000000e+02, 6.63324958e-01 }, new double[] { 1.34000000e+02, 6.80000000e+01, 6.78232998e-01 }, new double[] { 6.80000000e+01, 1.35000000e+02, 6.78232998e-01 }, new double[] { 1.35000000e+02, 1.22000000e+02, 6.78232998e-01 }, new double[] { 6.00000000e+01, 8.00000000e+01, 7.14142843e-01 }, new double[] { 5.70000000e+01, 6.00000000e+01, 7.21110255e-01 }, new double[] { 1.22000000e+02, 1.09000000e+02, 7.54983444e-01 }, new double[] { 1.50000000e+01, 4.10000000e+01, 7.81024968e-01 }, new double[] { 9.80000000e+01, 5.70000000e+01, 7.93725393e-01 }, new double[] { 1.09000000e+02, 1.06000000e+02, 8.77496439e-01 }, new double[] { 1.06000000e+02, 1.18000000e+02, 9.27361850e-01 }, new double[] { 1.18000000e+02, 1.31000000e+02, 9.32737905e-01 }, new double[] { 1.31000000e+02, 1.17000000e+02, 1.00498756e+00 }, new double[] { 4.10000000e+01, 9.80000000e+01, 1.64012195e+00 } }; //System.out.println(Arrays.toString(VecUtils.argSort(MatUtils.getColumn(cdist, 2)))); //fail();// www . j av a 2s . co m /* * In comparison to sklearn, this can get off by 1 or 2 due to * rounding errors in the sort. So lets just make sure there is a * discrepancy less than one or two. */ int wrong_ct = 0; for (int i = 0; i < srtd_cdists.length; i++) { if (!VecUtils.equalsWithTolerance(srtd_cdists[i], expected_srted[i], 1e-8)) { if (!Precision.equals(srtd_cdists[i][2], expected_srted[i][2], 1e-8)) wrong_ct++; } } assertTrue(wrong_ct < 2); // Do labeling double[][] labMat = HDBSCAN.label(srtd_cdists); double[][] expected_labMat = new double[][] { new double[] { 0.00000000e+00, 3.90000000e+01, 1.41421356e-01, 2.00000000e+00 }, new double[] { 1.50000000e+02, 1.70000000e+01, 1.73205081e-01, 3.00000000e+00 }, new double[] { 1.51000000e+02, 2.70000000e+01, 1.73205081e-01, 4.00000000e+00 }, new double[] { 1.52000000e+02, 2.80000000e+01, 1.73205081e-01, 5.00000000e+00 }, new double[] { 3.40000000e+01, 3.70000000e+01, 1.73205081e-01, 2.00000000e+00 }, new double[] { 3.00000000e+01, 1.54000000e+02, 1.73205081e-01, 3.00000000e+00 }, new double[] { 9.00000000e+00, 1.00000000e+00, 1.73205081e-01, 2.00000000e+00 }, new double[] { 1.56000000e+02, 1.55000000e+02, 1.73205081e-01, 5.00000000e+00 }, new double[] { 1.57000000e+02, 1.20000000e+01, 1.73205081e-01, 6.00000000e+00 }, new double[] { 1.53000000e+02, 7.00000000e+00, 2.00000000e-01, 6.00000000e+00 }, new double[] { 1.58000000e+02, 2.50000000e+01, 2.23606798e-01, 7.00000000e+00 }, new double[] { 1.59000000e+02, 4.90000000e+01, 2.23606798e-01, 7.00000000e+00 }, new double[] { 1.61000000e+02, 4.00000000e+00, 2.23606798e-01, 8.00000000e+00 }, new double[] { 2.90000000e+01, 4.70000000e+01, 2.23606798e-01, 2.00000000e+00 }, new double[] { 1.60000000e+02, 1.63000000e+02, 2.23606798e-01, 9.00000000e+00 }, new double[] { 1.62000000e+02, 2.60000000e+01, 2.44948974e-01, 9.00000000e+00 }, new double[] { 1.65000000e+02, 4.00000000e+01, 2.44948974e-01, 1.00000000e+01 }, new double[] { 1.66000000e+02, 4.80000000e+01, 2.44948974e-01, 1.10000000e+01 }, new double[] { 1.64000000e+02, 3.00000000e+00, 2.44948974e-01, 1.00000000e+01 }, new double[] { 9.90000000e+01, 9.60000000e+01, 2.44948974e-01, 2.00000000e+00 }, new double[] { 1.67000000e+02, 1.68000000e+02, 2.64575131e-01, 2.10000000e+01 }, new double[] { 1.70000000e+02, 1.90000000e+01, 2.64575131e-01, 2.20000000e+01 }, new double[] { 1.71000000e+02, 2.00000000e+00, 2.64575131e-01, 2.30000000e+01 }, new double[] { 1.72000000e+02, 2.10000000e+01, 2.64575131e-01, 2.40000000e+01 }, new double[] { 1.73000000e+02, 4.50000000e+01, 2.64575131e-01, 2.50000000e+01 }, new double[] { 9.20000000e+01, 1.69000000e+02, 2.64575131e-01, 3.00000000e+00 }, new double[] { 6.90000000e+01, 1.75000000e+02, 2.64575131e-01, 4.00000000e+00 }, new double[] { 1.74000000e+02, 3.80000000e+01, 3.00000000e-01, 2.60000000e+01 }, new double[] { 4.20000000e+01, 4.60000000e+01, 3.00000000e-01, 2.00000000e+00 }, new double[] { 1.77000000e+02, 1.10000000e+01, 3.00000000e-01, 2.70000000e+01 }, new double[] { 1.79000000e+02, 1.78000000e+02, 3.00000000e-01, 2.90000000e+01 }, new double[] { 8.00000000e+01, 1.76000000e+02, 3.00000000e-01, 5.00000000e+00 }, new double[] { 8.90000000e+01, 9.40000000e+01, 3.00000000e-01, 2.00000000e+00 }, new double[] { 8.20000000e+01, 1.82000000e+02, 3.00000000e-01, 3.00000000e+00 }, new double[] { 1.81000000e+02, 1.83000000e+02, 3.00000000e-01, 8.00000000e+00 }, new double[] { 1.80000000e+02, 6.00000000e+00, 3.16227766e-01, 3.00000000e+01 }, new double[] { 1.27000000e+02, 1.38000000e+02, 3.16227766e-01, 2.00000000e+00 }, new double[] { 1.85000000e+02, 3.10000000e+01, 3.16227766e-01, 3.10000000e+01 }, new double[] { 1.84000000e+02, 8.80000000e+01, 3.16227766e-01, 9.00000000e+00 }, new double[] { 5.80000000e+01, 7.50000000e+01, 3.16227766e-01, 2.00000000e+00 }, new double[] { 1.88000000e+02, 5.50000000e+01, 3.31662479e-01, 1.00000000e+01 }, new double[] { 1.87000000e+02, 3.50000000e+01, 3.31662479e-01, 3.20000000e+01 }, new double[] { 1.89000000e+02, 8.60000000e+01, 3.31662479e-01, 3.00000000e+00 }, new double[] { 1.86000000e+02, 1.49000000e+02, 3.31662479e-01, 3.00000000e+00 }, new double[] { 1.93000000e+02, 1.01000000e+02, 3.31662479e-01, 4.00000000e+00 }, new double[] { 1.94000000e+02, 1.42000000e+02, 3.31662479e-01, 5.00000000e+00 }, new double[] { 1.90000000e+02, 9.50000000e+01, 3.31662479e-01, 1.10000000e+01 }, new double[] { 1.91000000e+02, 1.00000000e+01, 3.31662479e-01, 3.30000000e+01 }, new double[] { 1.92000000e+02, 6.50000000e+01, 3.46410162e-01, 4.00000000e+00 }, new double[] { 1.97000000e+02, 8.00000000e+00, 3.46410162e-01, 3.40000000e+01 }, new double[] { 1.99000000e+02, 3.60000000e+01, 3.46410162e-01, 3.50000000e+01 }, new double[] { 7.80000000e+01, 9.10000000e+01, 3.46410162e-01, 2.00000000e+00 }, new double[] { 2.01000000e+02, 9.70000000e+01, 3.46410162e-01, 3.00000000e+00 }, new double[] { 1.20000000e+02, 1.40000000e+02, 3.46410162e-01, 2.00000000e+00 }, new double[] { 2.03000000e+02, 1.43000000e+02, 3.46410162e-01, 3.00000000e+00 }, new double[] { 1.98000000e+02, 5.20000000e+01, 3.46410162e-01, 5.00000000e+00 }, new double[] { 1.96000000e+02, 6.70000000e+01, 3.60555128e-01, 1.20000000e+01 }, new double[] { 1.23000000e+02, 1.95000000e+02, 3.60555128e-01, 6.00000000e+00 }, new double[] { 2.00000000e+02, 2.00000000e+01, 3.60555128e-01, 3.60000000e+01 }, new double[] { 6.10000000e+01, 2.02000000e+02, 3.60555128e-01, 4.00000000e+00 }, new double[] { 2.06000000e+02, 2.09000000e+02, 3.60555128e-01, 1.60000000e+01 }, new double[] { 1.12000000e+02, 2.04000000e+02, 3.74165739e-01, 4.00000000e+00 }, new double[] { 1.45000000e+02, 2.11000000e+02, 3.74165739e-01, 5.00000000e+00 }, new double[] { 1.47000000e+02, 2.12000000e+02, 3.74165739e-01, 6.00000000e+00 }, new double[] { 2.07000000e+02, 8.30000000e+01, 3.74165739e-01, 7.00000000e+00 }, new double[] { 2.13000000e+02, 1.39000000e+02, 3.74165739e-01, 7.00000000e+00 }, new double[] { 2.15000000e+02, 1.24000000e+02, 3.74165739e-01, 8.00000000e+00 }, new double[] { 2.05000000e+02, 5.10000000e+01, 3.74165739e-01, 6.00000000e+00 }, new double[] { 2.17000000e+02, 7.60000000e+01, 3.74165739e-01, 7.00000000e+00 }, new double[] { 2.08000000e+02, 4.30000000e+01, 3.74165739e-01, 3.70000000e+01 }, new double[] { 5.40000000e+01, 2.18000000e+02, 3.74165739e-01, 8.00000000e+00 }, new double[] { 2.19000000e+02, 5.00000000e+00, 3.74165739e-01, 3.80000000e+01 }, new double[] { 7.40000000e+01, 2.20000000e+02, 3.87298335e-01, 9.00000000e+00 }, new double[] { 2.10000000e+02, 2.22000000e+02, 3.87298335e-01, 2.50000000e+01 }, new double[] { 2.16000000e+02, 1.15000000e+02, 3.87298335e-01, 9.00000000e+00 }, new double[] { 1.16000000e+02, 1.28000000e+02, 3.87298335e-01, 2.00000000e+00 }, new double[] { 1.03000000e+02, 2.25000000e+02, 3.87298335e-01, 3.00000000e+00 }, new double[] { 1.11000000e+02, 2.26000000e+02, 3.87298335e-01, 4.00000000e+00 }, new double[] { 2.24000000e+02, 2.27000000e+02, 3.87298335e-01, 1.30000000e+01 }, new double[] { 2.14000000e+02, 1.26000000e+02, 3.87298335e-01, 8.00000000e+00 }, new double[] { 2.28000000e+02, 1.04000000e+02, 3.87298335e-01, 1.40000000e+01 }, new double[] { 2.21000000e+02, 2.30000000e+01, 3.87298335e-01, 3.90000000e+01 }, new double[] { 2.31000000e+02, 1.60000000e+01, 3.87298335e-01, 4.00000000e+01 }, new double[] { 2.23000000e+02, 7.10000000e+01, 4.00000000e-01, 2.60000000e+01 }, new double[] { 2.30000000e+02, 1.44000000e+02, 4.00000000e-01, 1.50000000e+01 }, new double[] { 1.46000000e+02, 2.29000000e+02, 4.12310563e-01, 9.00000000e+00 }, new double[] { 2.34000000e+02, 2.35000000e+02, 4.12310563e-01, 2.40000000e+01 }, new double[] { 2.32000000e+02, 4.40000000e+01, 4.12310563e-01, 4.10000000e+01 }, new double[] { 2.37000000e+02, 3.30000000e+01, 4.12310563e-01, 4.20000000e+01 }, new double[] { 2.33000000e+02, 6.60000000e+01, 4.12310563e-01, 2.70000000e+01 }, new double[] { 2.38000000e+02, 3.20000000e+01, 4.24264069e-01, 4.30000000e+01 }, new double[] { 2.36000000e+02, 7.00000000e+01, 4.24264069e-01, 2.50000000e+01 }, new double[] { 2.41000000e+02, 7.20000000e+01, 4.24264069e-01, 2.60000000e+01 }, new double[] { 2.40000000e+02, 2.40000000e+01, 4.24264069e-01, 4.40000000e+01 }, new double[] { 7.70000000e+01, 2.42000000e+02, 4.24264069e-01, 2.70000000e+01 }, new double[] { 2.39000000e+02, 2.44000000e+02, 4.24264069e-01, 5.40000000e+01 }, new double[] { 2.45000000e+02, 1.10000000e+02, 4.24264069e-01, 5.50000000e+01 }, new double[] { 2.46000000e+02, 9.00000000e+01, 4.24264069e-01, 5.60000000e+01 }, new double[] { 2.47000000e+02, 6.30000000e+01, 4.24264069e-01, 5.70000000e+01 }, new double[] { 2.48000000e+02, 1.33000000e+02, 4.35889894e-01, 5.80000000e+01 }, new double[] { 5.30000000e+01, 8.10000000e+01, 4.35889894e-01, 2.00000000e+00 }, new double[] { 2.49000000e+02, 2.50000000e+02, 4.35889894e-01, 6.00000000e+01 }, new double[] { 2.51000000e+02, 1.32000000e+02, 4.35889894e-01, 6.10000000e+01 }, new double[] { 2.52000000e+02, 1.37000000e+02, 4.35889894e-01, 6.20000000e+01 }, new double[] { 7.30000000e+01, 1.36000000e+02, 4.35889894e-01, 2.00000000e+00 }, new double[] { 2.53000000e+02, 2.54000000e+02, 4.35889894e-01, 6.40000000e+01 }, new double[] { 2.55000000e+02, 7.90000000e+01, 4.47213595e-01, 6.50000000e+01 }, new double[] { 2.56000000e+02, 5.60000000e+01, 4.58257569e-01, 6.60000000e+01 }, new double[] { 2.57000000e+02, 1.21000000e+02, 4.58257569e-01, 6.70000000e+01 }, new double[] { 2.58000000e+02, 5.00000000e+01, 4.58257569e-01, 6.80000000e+01 }, new double[] { 2.59000000e+02, 1.02000000e+02, 4.58257569e-01, 6.90000000e+01 }, new double[] { 2.60000000e+02, 8.50000000e+01, 4.69041576e-01, 7.00000000e+01 }, new double[] { 2.61000000e+02, 1.25000000e+02, 4.69041576e-01, 7.10000000e+01 }, new double[] { 2.43000000e+02, 1.30000000e+01, 4.79583152e-01, 4.50000000e+01 }, new double[] { 2.62000000e+02, 8.40000000e+01, 4.89897949e-01, 7.20000000e+01 }, new double[] { 2.63000000e+02, 1.80000000e+01, 5.09901951e-01, 4.60000000e+01 }, new double[] { 2.64000000e+02, 1.30000000e+02, 5.09901951e-01, 7.30000000e+01 }, new double[] { 2.66000000e+02, 1.41000000e+02, 5.09901951e-01, 7.40000000e+01 }, new double[] { 2.67000000e+02, 6.40000000e+01, 5.19615242e-01, 7.50000000e+01 }, new double[] { 2.68000000e+02, 1.13000000e+02, 5.19615242e-01, 7.60000000e+01 }, new double[] { 2.69000000e+02, 1.14000000e+02, 5.19615242e-01, 7.70000000e+01 }, new double[] { 2.70000000e+02, 5.90000000e+01, 5.29150262e-01, 7.80000000e+01 }, new double[] { 2.65000000e+02, 2.20000000e+01, 5.38516481e-01, 4.70000000e+01 }, new double[] { 2.71000000e+02, 1.07000000e+02, 5.47722558e-01, 7.90000000e+01 }, new double[] { 2.73000000e+02, 1.05000000e+02, 5.47722558e-01, 8.00000000e+01 }, new double[] { 2.74000000e+02, 1.29000000e+02, 5.56776436e-01, 8.10000000e+01 }, new double[] { 2.72000000e+02, 1.40000000e+01, 5.56776436e-01, 4.80000000e+01 }, new double[] { 2.75000000e+02, 1.00000000e+02, 5.56776436e-01, 8.20000000e+01 }, new double[] { 2.77000000e+02, 1.19000000e+02, 5.83095189e-01, 8.30000000e+01 }, new double[] { 2.78000000e+02, 6.20000000e+01, 5.83095189e-01, 8.40000000e+01 }, new double[] { 2.79000000e+02, 8.70000000e+01, 6.08276253e-01, 8.50000000e+01 }, new double[] { 2.80000000e+02, 1.48000000e+02, 6.16441400e-01, 8.60000000e+01 }, new double[] { 2.81000000e+02, 1.08000000e+02, 6.16441400e-01, 8.70000000e+01 }, new double[] { 2.76000000e+02, 1.50000000e+01, 6.16441400e-01, 4.90000000e+01 }, new double[] { 2.82000000e+02, 9.30000000e+01, 6.48074070e-01, 8.80000000e+01 }, new double[] { 2.84000000e+02, 1.34000000e+02, 6.63324958e-01, 8.90000000e+01 }, new double[] { 2.85000000e+02, 6.80000000e+01, 6.78232998e-01, 9.00000000e+01 }, new double[] { 2.86000000e+02, 1.35000000e+02, 6.78232998e-01, 9.10000000e+01 }, new double[] { 2.87000000e+02, 1.22000000e+02, 6.78232998e-01, 9.20000000e+01 }, new double[] { 6.00000000e+01, 2.88000000e+02, 7.14142843e-01, 9.30000000e+01 }, new double[] { 5.70000000e+01, 2.89000000e+02, 7.21110255e-01, 9.40000000e+01 }, new double[] { 2.90000000e+02, 1.09000000e+02, 7.54983444e-01, 9.50000000e+01 }, new double[] { 2.83000000e+02, 4.10000000e+01, 7.81024968e-01, 5.00000000e+01 }, new double[] { 9.80000000e+01, 2.91000000e+02, 7.93725393e-01, 9.60000000e+01 }, new double[] { 2.93000000e+02, 1.06000000e+02, 8.77496439e-01, 9.70000000e+01 }, new double[] { 2.94000000e+02, 1.18000000e+02, 9.27361850e-01, 9.80000000e+01 }, new double[] { 2.95000000e+02, 1.31000000e+02, 9.32737905e-01, 9.90000000e+01 }, new double[] { 2.96000000e+02, 1.17000000e+02, 1.00498756e+00, 1.00000000e+02 }, new double[] { 2.92000000e+02, 2.97000000e+02, 1.64012195e+00, 1.50000000e+02 } }; // ensure the labeling method works and gets what the sklearn method would... assertTrue(MatUtils.equalsExactly(expected_labMat, HDBSCAN.label(expected_srted))); // expected sorted... ArrayList<CompQuadTup<Integer, Integer, Double, Integer>> expected_hlist = new ArrayList<>(); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(150, 151, 0.6097107608496923, 50)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(150, 152, 0.6097107608496923, 100)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 2, 3.7796447300922726, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 5, 2.6726124191242397, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 6, 3.1622776601683857, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 8, 2.886751345948128, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 10, 3.015113445777631, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 11, 3.3333333333333353, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 13, 2.0851441405707485, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 14, 1.796053020267749, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 15, 1.6222142113076248, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 16, 2.5819888974716076, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 18, 1.9611613513818411, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 19, 3.7796447300922766, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 20, 2.773500981126144, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 21, 3.7796447300922726, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 22, 1.85695338177052, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 23, 2.581988897471612, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 24, 2.35702260395516, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 31, 3.1622776601683804, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 32, 2.3570226039551616, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 33, 2.42535625036333, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 35, 3.0151134457776374, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 36, 2.8867513459481273, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 38, 3.3333333333333384, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 41, 1.2803687993289594, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 42, 3.3333333333333353, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 43, 2.6726124191242437, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 44, 2.4253562503633304, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 45, 3.7796447300922726, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 46, 3.3333333333333353, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 153, 3.7796447300922766, 11)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(151, 154, 3.7796447300922766, 10)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 50, 2.1821789023599227, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 53, 2.294157338705618, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 56, 2.1821789023599236, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 57, 1.386750490563073, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 59, 1.8898223650461363, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 60, 1.4002800840280099, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 62, 1.7149858514250882, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 63, 2.357022603955156, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 64, 1.9245008972987536, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 68, 1.4744195615489724, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 73, 2.2941573387056153, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 79, 2.2360679774997894, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 81, 2.294157338705618, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 84, 2.041241452319315, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 85, 2.132007163556105, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 87, 1.6439898730535734, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 90, 2.3570226039551567, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 93, 1.5430334996209187, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 98, 1.2598815766974234, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 100, 1.796053020267749, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 102, 2.1821789023599227, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 105, 1.8257418583505527, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 106, 1.1396057645963797, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 107, 1.8257418583505547, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 108, 1.6222142113076254, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 109, 1.3245323570650438, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 110, 2.3570226039551576, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 113, 1.9245008972987536, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 114, 1.9245008972987536, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 117, 0.995037190209989, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 118, 1.0783277320343838, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 119, 1.7149858514250889, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 121, 2.1821789023599227, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 122, 1.4744195615489704, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 125, 2.132007163556103, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 129, 1.7960530202677494, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 130, 1.9611613513818407, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 131, 1.0721125348377945, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 132, 2.294157338705618, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 133, 2.2941573387056184, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 134, 1.5075567228888174, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 135, 1.474419561548971, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 136, 2.2941573387056153, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 137, 2.294157338705617, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 141, 1.9611613513818398, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 148, 1.6222142113076257, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 155, 2.3570226039551576, 27)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(152, 156, 2.3570226039551576, 27)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 0, 5.773502691896247, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 4, 4.472135954999576, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 7, 5.000000000000003, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 17, 5.773502691896247, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 26, 4.082482904638632, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 27, 5.773502691896247, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 28, 5.773502691896247, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 39, 5.773502691896247, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 40, 4.08248290463863, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 48, 4.0824829046386295, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(153, 49, 4.47213595499958, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 1, 5.773502691896246, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 3, 4.082482904638627, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 9, 5.773502691896246, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 12, 5.773502691896245, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 25, 4.47213595499958, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 29, 4.472135954999572, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 30, 5.773502691896246, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 34, 5.773502691896246, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 37, 5.773502691896246, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(154, 47, 4.472135954999572, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(155, 66, 2.4253562503633277, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(155, 71, 2.5000000000000013, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(155, 157, 2.5819888974716125, 16)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(155, 158, 2.5819888974716125, 9)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 70, 2.3570226039551603, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 72, 2.3570226039551603, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 77, 2.3570226039551576, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 159, 2.425356250363331, 15)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(156, 160, 2.425356250363331, 9)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 55, 3.0151134457776374, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 61, 2.7735009811261433, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 67, 2.773500981126145, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 69, 3.333333333333332, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 78, 2.7735009811261433, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 80, 3.333333333333332, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 82, 3.3333333333333317, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 88, 3.162277660168379, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 89, 3.3333333333333317, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 91, 2.7735009811261433, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 92, 3.333333333333332, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 94, 3.3333333333333317, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 95, 3.015113445777636, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 96, 3.333333333333332, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 97, 2.7735009811261433, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(157, 99, 3.333333333333332, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 51, 2.672612419124244, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 52, 2.886751345948124, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 54, 2.6726124191242406, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 58, 2.886751345948124, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 65, 2.886751345948124, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 74, 2.5819888974716125, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 75, 2.886751345948124, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 76, 2.672612419124244, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(158, 86, 2.886751345948124, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 103, 2.581988897471612, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 104, 2.581988897471612, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 111, 2.581988897471612, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 112, 2.6726124191242464, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 115, 2.5819888974716125, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 116, 2.581988897471612, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 120, 2.6726124191242464, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 124, 2.6726124191242446, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 128, 2.581988897471612, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 139, 2.6726124191242455, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 140, 2.6726124191242464, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 143, 2.6726124191242464, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 144, 2.5000000000000004, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 145, 2.6726124191242464, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(159, 147, 2.6726124191242464, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 83, 2.672612419124246, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 101, 3.0151134457776365, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 123, 2.7735009811261446, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 126, 2.581988897471612, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 127, 3.0151134457776365, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 138, 3.0151134457776365, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 142, 3.0151134457776365, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 146, 2.425356250363331, 1)); expected_hlist.add(new CompQuadTup<Integer, Integer, Double, Integer>(160, 149, 3.0151134457776365, 1)); // test the condense tree label ArrayList<CompQuadTup<Integer, Integer, Double, Integer>> condensed = HDBSCAN.LinkageTreeUtils .condenseTree(expected_labMat, 5); // Now sort it for the sake of comparing to the sklearn res... Collections.sort(condensed, new Comparator<QuadTup<Integer, Integer, Double, Integer>>() { @Override public int compare(QuadTup<Integer, Integer, Double, Integer> q1, QuadTup<Integer, Integer, Double, Integer> q2) { int cmp = q1.getFirst().compareTo(q2.getFirst()); if (cmp == 0) { cmp = q1.getSecond().compareTo(q2.getSecond()); if (cmp == 0) { cmp = q1.getThird().compareTo(q2.getThird()); if (cmp == 0) { return q1.getFourth().compareTo(q2.getFourth()); } return cmp; } return cmp; } return cmp; } }); for (int i = 0; i < condensed.size(); i++) { if (!condensed.get(i).almostEquals(expected_hlist.get(i))) { System.out.println(condensed.get(i)); System.out.println(expected_hlist.get(i)); fail(); } } // If we get here, the condensed labels works!! TreeMap<Integer, Double> stability = HDBSCAN.LinkageTreeUtils.computeStability(condensed); TreeMap<Integer, Double> exp_stab = new TreeMap<>(); exp_stab.put(150, Double.NaN); exp_stab.put(151, 128.9165546745262); exp_stab.put(152, 150.98635723043549); exp_stab.put(153, 13.48314205238124); exp_stab.put(154, 14.343459620092055); exp_stab.put(155, 5.8354683803643868); exp_stab.put(156, 1.6400075137961618); exp_stab.put(157, 8.4148537644752253); exp_stab.put(158, 1.7956828073404498); exp_stab.put(159, 2.99248898237368); exp_stab.put(160, Double.NaN); /* * Assert near equality... */ for (Map.Entry<Integer, Double> entry : exp_stab.entrySet()) { int key = entry.getKey(); double stab = entry.getValue(); if (Double.isNaN(stab) && Double.isNaN(stability.get(key))) continue; if (!Precision.equals(stab, stability.get(key), 1e-6)) { System.out.println(key + ", " + stab); System.out.println(key + ", " + stability.get(key)); fail(); } } // test the treeToLabels method... final int[] labs = new NoiseyLabelEncoder(HDBSCAN.treeToLabels(iris.getData(), labMat, 5)).fit() .getEncodedLabels(); assertTrue(VecUtils.equalsExactly(labs, expected_iris_labs)); }
From source file:com.nextgis.ngm_clink_monitoring.fragments.MapFragment.java
@Override public void onSingleTapUp(MotionEvent event) { double dMinX = event.getX() - mTolerancePX; double dMaxX = event.getX() + mTolerancePX; double dMinY = event.getY() - mTolerancePX; double dMaxY = event.getY() + mTolerancePX; GeoEnvelope mapEnv = mMapView.screenToMap(new GeoEnvelope(dMinX, dMaxX, dMinY, dMaxY)); if (null == mapEnv) { return;/* ww w. j a v a 2s. co m*/ } //show actions dialog List<ILayer> layers = mMapView.getVectorLayersByType(GeoConstants.GTAnyCheck); TreeMap<Integer, Integer> priorityMap = new TreeMap<>(); List<FoclVectorLayer> foclVectorLayers = new ArrayList<>(); for (ILayer layer : layers) { if (!layer.isValid()) { continue; } ILayerView layerView = (ILayerView) layer; if (!layerView.isVisible()) { continue; } FoclVectorLayer foclVectorLayer = (FoclVectorLayer) layer; List<Long> items = foclVectorLayer.query(mapEnv); if (!items.isEmpty()) { foclVectorLayers.add(foclVectorLayer); int type = foclVectorLayer.getFoclLayerType(); int priority; switch (type) { case FoclConstants.LAYERTYPE_FOCL_UNKNOWN: default: priority = 0; break; case FoclConstants.LAYERTYPE_FOCL_OPTICAL_CABLE: priority = 1; break; case FoclConstants.LAYERTYPE_FOCL_SPECIAL_TRANSITION: priority = 2; break; case FoclConstants.LAYERTYPE_FOCL_FOSC: priority = 3; break; case FoclConstants.LAYERTYPE_FOCL_OPTICAL_CROSS: priority = 4; break; case FoclConstants.LAYERTYPE_FOCL_ACCESS_POINT: priority = 5; break; case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CABLE_POINT: priority = 6; break; case FoclConstants.LAYERTYPE_FOCL_REAL_FOSC: priority = 7; break; case FoclConstants.LAYERTYPE_FOCL_REAL_OPTICAL_CROSS: priority = 8; break; case FoclConstants.LAYERTYPE_FOCL_REAL_ACCESS_POINT: priority = 9; break; case FoclConstants.LAYERTYPE_FOCL_REAL_SPECIAL_TRANSITION_POINT: priority = 10; break; } if (!priorityMap.containsKey(priority)) { priorityMap.put(priority, type); } } } Integer type = null; if (!priorityMap.isEmpty()) { Integer key = priorityMap.lastKey(); type = priorityMap.get(key); } if (null != type) { for (FoclVectorLayer layer : foclVectorLayers) { if (type == layer.getFoclLayerType()) { List<Long> items = layer.query(mapEnv); AttributesDialog attributesDialog = new AttributesDialog(); attributesDialog.setKeepInstance(true); attributesDialog.setParams(layer, items.get(0)); attributesDialog.show(getActivity().getSupportFragmentManager(), FoclConstants.FRAGMENT_ATTRIBUTES); break; } } } }
From source file:ca.myewb.frame.servlet.GraphServlet.java
private JFreeChart getListMemberships(Session s, int groupId, UserModel currentUser) { final int NUM_MONTHS = 6; Logger log = Logger.getLogger(this.getClass()); JFreeChart chart;/* w w w . java 2s. c o m*/ Date startDate; TreeMap<Day, Integer> memberChange = new TreeMap<Day, Integer>(); GroupModel g = (GroupModel) s.get(GroupModel.class, groupId); if (g == null) { log.warn("Someone requested chapter stats with a bad group id"); } else if (!Permissions.canAdministerGroupMembership(currentUser, g)) { log.warn(currentUser.getUsername() + "tried to access list memberships graph!"); } Calendar cal = GregorianCalendar.getInstance(); Date now = cal.getTime(); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 1); cal.add(Calendar.MONTH, -NUM_MONTHS); startDate = cal.getTime(); //Set Initial Number of Members int initMembers = g.getNumMembers() + g.getNumRecipients(); //Pull a list of all of the membership start dates List starts = s.createQuery("SELECT rm.start, count(*) " + "FROM RoleModel as rm " + "WHERE rm.group = :group " + "AND (rm.level = 'r' OR rm.level = 'm') " + "AND rm.start > :startDate " + "GROUP BY rm.start ").setEntity("group", g) .setDate("startDate", startDate).list(); for (Object o : starts) { Day date = new Day((Date) (((Object[]) o)[0])); int change = ((Long) (((Object[]) o)[1])).intValue(); memberChange.put(date, change); initMembers -= change; } //Pull a list of all of the membership end dates List ends = s.createQuery("SELECT rm.end, count(*) " + "FROM RoleModel as rm " + "WHERE rm.group = :group " + "AND (rm.level = 'r' OR rm.level = 'm') " + "AND rm.end > :startDate " + "GROUP BY rm.end ") .setEntity("group", g).setDate("startDate", startDate).list(); for (Object o : ends) { Day date = new Day((Date) (((Object[]) o)[0])); int change = ((Long) (((Object[]) o)[1])).intValue(); if (memberChange.containsKey(date)) { memberChange.put(date, memberChange.get(date) - change); } else { memberChange.put(date, -change); } initMembers += change; } TimeSeriesCollection theData = new TimeSeriesCollection(); TimeSeries signups = new TimeSeries("List Membership", Day.class); theData.addSeries(signups); while (startDate.before(now)) { Day d = new Day(startDate); if (memberChange.containsKey(d)) { initMembers += memberChange.get(d); } signups.add(d, initMembers); cal.add(Calendar.DATE, 1); startDate = cal.getTime(); } chart = ChartFactory.createTimeSeriesChart("List Members", "Day", "Number of Members", theData, true, true, true); XYPlot plot = (XYPlot) chart.getPlot(); XYLineAndShapeRenderer renderer = (XYLineAndShapeRenderer) plot.getRenderer(); renderer.setSeriesStroke(0, new BasicStroke(2.0f)); return chart; }
From source file:jp.zippyzip.impl.GeneratorServiceImpl.java
public void updateZips() { Date timestamp = getLzhDao().getZipInfo().getTimestamp(); LinkedList<Pref> prefs = getPrefs(); TreeMap<String, TreeSet<String>> zips = new TreeMap<String, TreeSet<String>>(); int cnt = 0;//from w w w .ja v a 2 s.c o m try { for (Pref pref : prefs) { ParentChild data = getParentChildDao().get("pre" + pref.getCode()); if (data != null) { for (String json : data.getChildren()) { JSONArray ja = new JSONArray(json); for (int i = 0; i < ja.length(); ++i) { JSONObject jo = ja.getJSONObject(i); String zip = jo.optString("zip", ""); String key = jo.optString("key", ""); if (!zips.containsKey(zip)) { zips.put(zip, new TreeSet<String>()); } zips.get(zip).add(key); } } } } ParentChild data = null; LinkedList<String> zip1s = new LinkedList<String>(); String prev = null; for (String code : zips.keySet()) { String zip1 = code.substring(0, 3); String zip2 = code.substring(3); if (!zip1.equals(prev)) { if (data != null) { getParentChildDao().store(data); } LinkedList<String> parents = new LinkedList<String>(); parents.add(zip1); data = new ParentChild(zip1, timestamp, parents); zip1s.add(new JSONStringer().object().key("zip1").value(zip1).endObject().toString()); prev = zip1; } for (String key : zips.get(code)) { data.getChildren().add(new JSONStringer().object().key("zip2").value(zip2).key("key").value(key) .endObject().toString()); ++cnt; } } if (data != null) { getParentChildDao().store(data); } getParentChildDao().store(new ParentChild("zip1s", timestamp, new LinkedList<String>(), zip1s)); log.info("count:" + cnt); } catch (JSONException e) { log.log(Level.WARNING, "", e); } return; }
From source file:org.apache.nutch.segment.SegmentMerger.java
/** * NOTE: in selecting the latest version we rely exclusively on the segment * name (not all segment data contain time information). Therefore it is extremely * important that segments be named in an increasing lexicographic order as * their creation time increases./*from w ww . j a v a 2s . c o m*/ */ public void reduce(Text key, Iterator<MetaWrapper> values, OutputCollector<Text, MetaWrapper> output, Reporter reporter) throws IOException { CrawlDatum lastG = null; CrawlDatum lastF = null; CrawlDatum lastSig = null; Content lastC = null; ParseData lastPD = null; ParseText lastPT = null; String lastGname = null; String lastFname = null; String lastSigname = null; String lastCname = null; String lastPDname = null; String lastPTname = null; TreeMap<String, ArrayList<CrawlDatum>> linked = new TreeMap<String, ArrayList<CrawlDatum>>(); while (values.hasNext()) { MetaWrapper wrapper = values.next(); Object o = wrapper.get(); String spString = wrapper.getMeta(SEGMENT_PART_KEY); if (spString == null) { throw new IOException("Null segment part, key=" + key); } SegmentPart sp = SegmentPart.parse(spString); if (o instanceof CrawlDatum) { CrawlDatum val = (CrawlDatum) o; // check which output dir it belongs to if (sp.partName.equals(CrawlDatum.GENERATE_DIR_NAME)) { if (lastG == null) { lastG = val; lastGname = sp.segmentName; } else { // take newer if (lastGname.compareTo(sp.segmentName) < 0) { lastG = val; lastGname = sp.segmentName; } } } else if (sp.partName.equals(CrawlDatum.FETCH_DIR_NAME)) { if (lastF == null) { lastF = val; lastFname = sp.segmentName; } else { // take newer if (lastFname.compareTo(sp.segmentName) < 0) { lastF = val; lastFname = sp.segmentName; } } } else if (sp.partName.equals(CrawlDatum.PARSE_DIR_NAME)) { if (val.getStatus() == CrawlDatum.STATUS_SIGNATURE) { if (lastSig == null) { lastSig = val; lastSigname = sp.segmentName; } else { // take newer if (lastSigname.compareTo(sp.segmentName) < 0) { lastSig = val; lastSigname = sp.segmentName; } } continue; } // collect all LINKED values from the latest segment ArrayList<CrawlDatum> segLinked = linked.get(sp.segmentName); if (segLinked == null) { segLinked = new ArrayList<CrawlDatum>(); linked.put(sp.segmentName, segLinked); } segLinked.add(val); } else { throw new IOException("Cannot determine segment part: " + sp.partName); } } else if (o instanceof Content) { if (lastC == null) { lastC = (Content) o; lastCname = sp.segmentName; } else { if (lastCname.compareTo(sp.segmentName) < 0) { lastC = (Content) o; lastCname = sp.segmentName; } } } else if (o instanceof ParseData) { if (lastPD == null) { lastPD = (ParseData) o; lastPDname = sp.segmentName; } else { if (lastPDname.compareTo(sp.segmentName) < 0) { lastPD = (ParseData) o; lastPDname = sp.segmentName; } } } else if (o instanceof ParseText) { if (lastPT == null) { lastPT = (ParseText) o; lastPTname = sp.segmentName; } else { if (lastPTname.compareTo(sp.segmentName) < 0) { lastPT = (ParseText) o; lastPTname = sp.segmentName; } } } } // perform filtering based on full merge record if (mergeFilters != null && !mergeFilters.filter(key, lastG, lastF, lastSig, lastC, lastPD, lastPT, linked.isEmpty() ? null : linked.lastEntry().getValue())) { return; } curCount++; String sliceName = null; MetaWrapper wrapper = new MetaWrapper(); if (sliceSize > 0) { sliceName = String.valueOf(curCount / sliceSize); wrapper.setMeta(SEGMENT_SLICE_KEY, sliceName); } SegmentPart sp = new SegmentPart(); // now output the latest values if (lastG != null) { wrapper.set(lastG); sp.partName = CrawlDatum.GENERATE_DIR_NAME; sp.segmentName = lastGname; wrapper.setMeta(SEGMENT_PART_KEY, sp.toString()); output.collect(key, wrapper); } if (lastF != null) { wrapper.set(lastF); sp.partName = CrawlDatum.FETCH_DIR_NAME; sp.segmentName = lastFname; wrapper.setMeta(SEGMENT_PART_KEY, sp.toString()); output.collect(key, wrapper); } if (lastSig != null) { wrapper.set(lastSig); sp.partName = CrawlDatum.PARSE_DIR_NAME; sp.segmentName = lastSigname; wrapper.setMeta(SEGMENT_PART_KEY, sp.toString()); output.collect(key, wrapper); } if (lastC != null) { wrapper.set(lastC); sp.partName = Content.DIR_NAME; sp.segmentName = lastCname; wrapper.setMeta(SEGMENT_PART_KEY, sp.toString()); output.collect(key, wrapper); } if (lastPD != null) { wrapper.set(lastPD); sp.partName = ParseData.DIR_NAME; sp.segmentName = lastPDname; wrapper.setMeta(SEGMENT_PART_KEY, sp.toString()); output.collect(key, wrapper); } if (lastPT != null) { wrapper.set(lastPT); sp.partName = ParseText.DIR_NAME; sp.segmentName = lastPTname; wrapper.setMeta(SEGMENT_PART_KEY, sp.toString()); output.collect(key, wrapper); } if (linked.size() > 0) { String name = linked.lastKey(); sp.partName = CrawlDatum.PARSE_DIR_NAME; sp.segmentName = name; wrapper.setMeta(SEGMENT_PART_KEY, sp.toString()); ArrayList<CrawlDatum> segLinked = linked.get(name); for (int i = 0; i < segLinked.size(); i++) { CrawlDatum link = segLinked.get(i); wrapper.set(link); output.collect(key, wrapper); } } }
From source file:com.joliciel.jochre.analyser.BeamSearchImageAnalyser.java
public void analyseInternal(JochreImage image) { LOG.debug("Analysing image " + image.getId()); if (currentMonitor != null) { currentMonitor.setCurrentAction("imageMonitor.analysingImage", new Object[] { image.getPage().getIndex() }); }/*from w w w.j av a2 s . c om*/ for (LetterGuessObserver observer : observers) { observer.onImageStart(image); } if (totalShapeCount < 0) totalShapeCount = image.getShapeCount(); for (Paragraph paragraph : image.getParagraphs()) { LOG.debug("Analysing paragraph " + paragraph.getIndex() + " (id=" + paragraph.getId() + ")"); List<LetterSequence> holdoverSequences = null; for (RowOfShapes row : paragraph.getRows()) { LOG.debug("Analysing row " + row.getIndex() + " (id=" + row.getId() + ")"); for (GroupOfShapes group : row.getGroups()) { if (group.isSkip()) { LOG.debug("Skipping group " + group.getIndex() + " (id=" + group.getId() + ")"); continue; } LOG.debug("Analysing group " + group.getIndex() + " (id=" + group.getId() + ")"); int width = group.getRight() - group.getLeft() + 1; List<ShapeSequence> shapeSequences = null; if (boundaryDetector != null) { shapeSequences = boundaryDetector.findBoundaries(group); } else { // simply add this groups shape's shapeSequences = new ArrayList<ShapeSequence>(); ShapeSequence shapeSequence = boundaryService.getEmptyShapeSequence(); for (Shape shape : group.getShapes()) shapeSequence.addShape(shape); shapeSequences.add(shapeSequence); } // Perform a beam search to guess the most likely sequence for this word TreeMap<Integer, PriorityQueue<LetterSequence>> heaps = new TreeMap<Integer, PriorityQueue<LetterSequence>>(); // prime a starter heap with the n best shape boundary analyses for this group PriorityQueue<LetterSequence> starterHeap = new PriorityQueue<LetterSequence>(1); for (ShapeSequence shapeSequence : shapeSequences) { LetterSequence emptySequence = this.getLetterGuesserService() .getEmptyLetterSequence(shapeSequence); starterHeap.add(emptySequence); } heaps.put(0, starterHeap); PriorityQueue<LetterSequence> finalHeap = null; while (heaps.size() > 0) { Entry<Integer, PriorityQueue<LetterSequence>> heapEntry = heaps.pollFirstEntry(); if (LOG.isTraceEnabled()) LOG.trace("heap for index: " + heapEntry.getKey().intValue() + ", width: " + width); if (heapEntry.getKey().intValue() == width) { finalHeap = heapEntry.getValue(); break; } PriorityQueue<LetterSequence> previousHeap = heapEntry.getValue(); // limit the breadth to K int maxSequences = previousHeap.size() > this.beamWidth ? this.beamWidth : previousHeap.size(); for (int j = 0; j < maxSequences; j++) { LetterSequence history = previousHeap.poll(); ShapeInSequence shapeInSequence = history.getNextShape(); Shape shape = shapeInSequence.getShape(); if (LOG.isTraceEnabled()) { LOG.trace("Sequence " + history + ", shape: " + shape); } LogUtils.logMemory(LOG); int position = 0; if (Linguistics.getInstance(image.getPage().getDocument().getLocale()) .isLeftToRight()) { position = shape.getRight() - group.getLeft() + 1; } else { position = group.getRight() - shape.getLeft() + 1; } PriorityQueue<LetterSequence> heap = heaps.get(position); if (heap == null) { heap = new PriorityQueue<LetterSequence>(); heaps.put(position, heap); } MONITOR.startTask("guess letter"); try { letterGuesser.guessLetter(shapeInSequence, history); } finally { MONITOR.endTask(); } MONITOR.startTask("heap sort"); try { for (Decision<Letter> letterGuess : shape.getLetterGuesses()) { // leave out very low probability outcomes if (letterGuess.getProbability() > this.minOutcomeWeight) { LetterSequence sequence = this.getLetterGuesserService() .getLetterSequencePlusOne(history); sequence.add(letterGuess.getOutcome()); sequence.addDecision(letterGuess); heap.add(sequence); } // weight big enough to include } // next letter guess for this shape } finally { MONITOR.endTask(); } } // next history in heap } // any more heaps? LetterSequence bestSequence = null; boolean shouldCombineWithHoldover = false; boolean isHoldover = false; MONITOR.startTask("best sequence"); try { List<LetterSequence> finalSequences = new ArrayList<LetterSequence>(); for (int i = 0; i < this.beamWidth; i++) { if (finalHeap.isEmpty()) break; finalSequences.add(finalHeap.poll()); } if (this.getMostLikelyWordChooser() == null) { // most likely sequence is on top of the last heap bestSequence = finalSequences.get(0); } else { // get most likely sequence using lexicon if (holdoverSequences != null) { // we have a holdover from the previous row ending with a dash bestSequence = this.getMostLikelyWordChooser().chooseMostLikelyWord(finalSequences, holdoverSequences, this.beamWidth); shouldCombineWithHoldover = true; } else { // check if this is the last group on the row and could end with a dash boolean shouldBeHeldOver = false; if (group.getIndex() == row.getGroups().size() - 1 && row.getIndex() < paragraph.getRows().size() - 1) { for (LetterSequence letterSequence : finalSequences) { if (letterSequence.toString().endsWith("-")) { shouldBeHeldOver = true; break; } } } if (shouldBeHeldOver) { holdoverSequences = finalSequences; isHoldover = true; } else { // simplest case: no holdover bestSequence = this.getMostLikelyWordChooser() .chooseMostLikelyWord(finalSequences, this.beamWidth); } } // have we holdover sequences? } // have we a most likely word chooser? if (!isHoldover) { for (LetterGuessObserver observer : observers) { observer.onBeamSearchEnd(bestSequence, finalSequences, holdoverSequences); } } } finally { MONITOR.endTask(); } MONITOR.startTask("assign letter"); try { if (shouldCombineWithHoldover) { holdoverSequences = null; } if (!isHoldover) { for (LetterGuessObserver observer : observers) { observer.onStartSequence(bestSequence); } group.setBestLetterSequence(bestSequence); int i = 0; for (ShapeInSequence shapeInSequence : bestSequence.getUnderlyingShapeSequence()) { String bestOutcome = bestSequence.get(i).getString(); this.assignLetter(shapeInSequence, bestOutcome); i++; } // next shape for (LetterGuessObserver observer : observers) { observer.onGuessSequence(bestSequence); } } this.shapeCount += group.getShapes().size(); if (this.currentMonitor != null) { double progress = (double) shapeCount / (double) totalShapeCount; LOG.debug("progress: " + progress); currentMonitor.setPercentComplete(progress); } } finally { MONITOR.endTask(); } } // next group } // next row } // next paragraph for (LetterGuessObserver observer : observers) { observer.onImageEnd(); } }
From source file:com.sec.ose.osi.thread.ui_related.UserCommandExecutionThread.java
@Override public void run() { long startTime = System.currentTimeMillis(); log.info(UserRequestHandler.getCommandName(mRequestCode) + " - start"); isDone = false;/* ww w . ja v a 2 s.c o m*/ this.mObserver.pushMessage("Preparing to request to server"); Property prop = Property.getInstance(); switch (mRequestCode) { case UserRequestHandler.DELETE_IDENTIFICATION_TABLE: if (IdentifyQueue.getInstance().size() > 0) { return; } Collection<OSIProjectInfo> infoList = OSIProjectInfoMgr.getInstance().getAllProjects(); for (OSIProjectInfo info : infoList) { if (info.getProjectName().equals(IdentifyMediator.getInstance().getSelectedProjectName())) { continue; } if (info.isManaged() == true) { continue; } mObserver.setMessageHeader("Deleting identification table...\n"); mObserver.pushMessageWithHeader(" > target project : " + info.getProjectName() + "\n"); // Drop identification tables IdentificationDBManager.dropTable(info.getProjectName()); // Remove memory ProjectDiscoveryControllerMap.removeProjectDiscoveryController(info.getProjectName()); } break; case UserRequestHandler.GET_PROTEX_PROJECT_INFO: UEProtexProjectInfo uap = (UEProtexProjectInfo) mEntity; OSIProjectInfo protexProjectInfo = UISDKInterfaceManager.getSDKInterface() .getProjectInfoByName(uap.getProjectName()); this.mObserver.setReturnValue(protexProjectInfo); this.mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); break; case UserRequestHandler.LOAD_IDENTIFICATION_DATA: { UEComboProjectName uei = (UEComboProjectName) mEntity; String projectName = uei.getProjectName(); log.info("loading project [" + projectName + "]"); mObserver.setMessageHeader("Loading Identification Data ...\n"); // Local Component Loading mObserver.pushMessageWithHeader(" > Loading local component info ...\n"); ComponentAPIWrapper.loadLocalComponent(ProjectAPIWrapper.getProjectID(projectName), false); ProjectDiscoveryControllerMap.loadProjectDiscoveryController(projectName, this.mObserver); CodeTreeAPIWrapper.setCodeTree(projectName, this.mObserver); log.debug("Selected Project : " + projectName); mObserver.pushMessageWithHeader(" > Loading sql dat to memory ...\n"); AbstractDiscoveryController stringMatchDiscovery = ProjectDiscoveryControllerMap .getDiscoveryController(projectName, IdentificationConstantValue.STRING_MATCH_TYPE); AbstractDiscoveryController codeMatchDiscovery = ProjectDiscoveryControllerMap .getDiscoveryController(projectName, IdentificationConstantValue.CODE_MATCH_TYPE); AbstractDiscoveryController patternMatchDiscovery = ProjectDiscoveryControllerMap .getDiscoveryController(projectName, IdentificationConstantValue.PATTERN_MATCH_TYPE); int displayedMatchedType = IdentificationConstantValue.STRING_MATCH_TYPE; if (stringMatchDiscovery.getNumOfPendingFiles() > 0) { displayedMatchedType = IdentificationConstantValue.STRING_MATCH_TYPE; } else if (codeMatchDiscovery.getNumOfPendingFiles() > 0) { displayedMatchedType = IdentificationConstantValue.CODE_MATCH_TYPE; } else if (patternMatchDiscovery.getNumOfPendingFiles() > 0) { displayedMatchedType = IdentificationConstantValue.PATTERN_MATCH_TYPE; } else if (stringMatchDiscovery.getNumOfDiscoveryFiles() > 0) { displayedMatchedType = IdentificationConstantValue.STRING_MATCH_TYPE; } else if (codeMatchDiscovery.getNumOfDiscoveryFiles() > 0) { displayedMatchedType = IdentificationConstantValue.CODE_MATCH_TYPE; } else if (patternMatchDiscovery.getNumOfDiscoveryFiles() > 0) { displayedMatchedType = IdentificationConstantValue.PATTERN_MATCH_TYPE; } mObserver.pushMessageWithHeader(" > Updating Panel ...\n"); IdentifyMediator.getInstance().changeSelectedIdentificationPanel(displayedMatchedType); // Tree & List Identification mObserver.pushMessageWithHeader(" > Updating Tree and List ...\n"); IdentifyMediator.getInstance().refreshIdentificationInfoForTreeListChildFrames(projectName, null, displayedMatchedType); this.mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); } break; case UserRequestHandler.SYNC_TO_SERVER: { syncToServer(); } break; case UserRequestHandler.SYNC_FROM_SERVER: { syncFromServer(); } break; case UserRequestHandler.GET_ALL_PROJECT_NAMES: { ArrayList<String> projectNames = UISDKInterfaceManager.getSDKInterface() .getProjectNames(this.mObserver); this.mObserver.setReturnValue(projectNames); } break; case UserRequestHandler.LOGIN: UELogin ueLogin = (UELogin) mEntity; this.mObserver.pushMessage("Sending login request to server"); mSDKInterface.userLogin(ueLogin.getUserID(), ueLogin.getPassword(), ueLogin.getProtexServerIP(), this.mObserver); if (this.mObserver.getResult() == UIResponseObserver.RESULT_SUCCESS) { IdentifyQueue.getInstance().makeBackup(); loadMainFrame(ueLogin, this.mObserver); } break; case UserRequestHandler.GENERATE_BOTH_REPORT: generateBothReport(); break; case UserRequestHandler.GENERATE_IDENTIFY_REPORT: generateIdentifyReport(); break; case UserRequestHandler.GENERATE_SPDX_REPORT: generateSPDXReport(); break; case UserRequestHandler.GET_BOM_LIST_FROM_SERVER: { UEProjectName ueProjetName = (UEProjectName) mEntity; String projectName = ueProjetName.getProjectName(); UISDKInterfaceManager.getSDKInterface().getBOMListFromProjectName(projectName, this.mObserver); } break; case UserRequestHandler.GET_BOM_LIST_MAP_FROM_SERVER: { UEProjectName ueProjetName = (UEProjectName) mEntity; ArrayList<String> projectNames = ueProjetName.getProjectNames(); UISDKInterfaceManager.getSDKInterface().getBOMListMapFromProjectNames(projectNames, this.mObserver); } break; case UserRequestHandler.PROJECT_CLONE: { UEProjectClone ueProjectClone = (UEProjectClone) mEntity; if (ueProjectClone.getOriginalProjectName() == null) { this.mObserver.setResult(UIResponseObserver.RESULT_FAIL); return; } String projectID = null; String newProjectName = ueProjectClone.getNewProjectName(); String originalProjectName = ueProjectClone.getOriginalProjectName(); projectID = SDKInterfaceImpl.getInstance().cloneProject(newProjectName, originalProjectName, mObserver); ArrayList<OSIProjectInfo> osiProjectInfoList = new ArrayList<OSIProjectInfo>(); if (projectID != null) { String sourceLocation = ueProjectClone.getSourceLocation(); boolean isAnalyzed = false; if (OSIProjectInfoMgr.getInstance().getProjectInfo(originalProjectName) != null) { isAnalyzed = OSIProjectInfoMgr.getInstance().getProjectInfo(originalProjectName).isAnalyzed(); } OSIProjectInfo curCreateProjectInfo = createOSIProjectInfo(projectID, newProjectName, sourceLocation, isAnalyzed); osiProjectInfoList.add(curCreateProjectInfo); this.mObserver.setReturnValue(osiProjectInfoList); this.mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); } else { this.mObserver.setResult(UIResponseObserver.RESULT_FAIL); } } break; case UserRequestHandler.PROJECT_CREATE: { UEProjectCreate ueProjectCreate = (UEProjectCreate) mEntity; String projectID = null; TreeMap<String, ProjectSplitInfo> mapOfAnalyzeTarget = ueProjectCreate.getMapOfAnalyzeTarget(); String newProjectName = ueProjectCreate.getProjectName(); ArrayList<OSIProjectInfo> osiProjectInfoList = new ArrayList<OSIProjectInfo>(); if (mapOfAnalyzeTarget == null) { // one project, no source path this.mObserver.pushMessage("Creating project [ " + newProjectName + " ] ..."); projectID = SDKInterfaceImpl.getInstance().createProject(newProjectName, null, mObserver); if (projectID != null) { String sourceLocation = ""; boolean isAnalyzed = false; OSIProjectInfo curCreateProjectInfo = createOSIProjectInfo(projectID, newProjectName, sourceLocation, isAnalyzed); osiProjectInfoList.add(curCreateProjectInfo); this.mObserver.setReturnValue(osiProjectInfoList); this.mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); } else { this.mObserver.setResult(UIResponseObserver.RESULT_FAIL); } } else { // split or no split int curProjectNum = 0; int totalProjectNum = mapOfAnalyzeTarget.size(); Iterator<Map.Entry<String, ProjectSplitInfo>> iter = mapOfAnalyzeTarget.entrySet().iterator(); if (iter == null) { return; } while (iter.hasNext()) { String strProjectName = iter.next().getKey(); ++curProjectNum; if (mapOfAnalyzeTarget.size() <= 1) { this.mObserver.pushMessage("Creating project [ " + newProjectName + " ] ..."); } else { this.mObserver.pushMessage("Creating project [ (" + curProjectNum + "/" + totalProjectNum + ") " + newProjectName + " ] ..."); } String sourceLocation = mapOfAnalyzeTarget.get(strProjectName).getAnalyzeTargetPath(); projectID = SDKInterfaceImpl.getInstance().createProject(strProjectName, sourceLocation, mObserver); if (projectID != null) { boolean isAnalyzed = false; OSIProjectInfo curCreateProjectInfo = createOSIProjectInfo(projectID, strProjectName, sourceLocation, isAnalyzed); osiProjectInfoList.add(curCreateProjectInfo); this.mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); } else { this.mObserver.setResult(UIResponseObserver.RESULT_FAIL); } } this.mObserver.setReturnValue(osiProjectInfoList); } } break; case UserRequestHandler.PROCESS_IDENTIFY: { IdentifyThread thread = BackgroundJobManager.getInstance().getIdentifyThread(); if (thread != null) thread.setIsStopByUser(true); mObserver.setMessageHeader("Identify processing... \n"); mObserver.pushMessageWithHeader(" > Update local database.\n"); boolean result = ActionIdentifyOrReset.requestIdentify(mObserver, (UEIdentifyResetComment) mEntity); if (result) { mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); } else { mObserver.setResult(UIResponseObserver.RESULT_FAIL); } thread.setIsStopByUser(false); } break; case UserRequestHandler.PROCESS_RESET: { IdentifyThread thread = BackgroundJobManager.getInstance().getIdentifyThread(); if (thread != null) thread.setIsStopByUser(true); mObserver.setMessageHeader("Reset processing... \n"); mObserver.pushMessageWithHeader(" > Update local database.\n"); boolean result = ActionIdentifyOrReset.requestReset(mObserver, (UEIdentifyResetComment) mEntity); if (result) { mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); } else { mObserver.setResult(UIResponseObserver.RESULT_FAIL); } thread.setIsStopByUser(false); } break; case UserRequestHandler.PROJECT_SPLIT: { mObserver.setMessageHeader("Assessing Project Size... \n"); boolean result = splitProject(mObserver); if (result) { mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); mObserver.setSuccessMessage("Complete splitting!!"); } else { mObserver.setResult(UIResponseObserver.RESULT_FAIL); mObserver.setFailMessage("Fail splitting!!"); } } break; case UserRequestHandler.PROJECT_INFO: { UEProjectInfo ue = (UEProjectInfo) mEntity; String projectName = ue.getProjectName(); mObserver.setMessageHeader("Getting Project information... \n"); boolean result = getProjectAnalysisInfo(projectName, mObserver); if (result) { mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); mObserver.setSuccessMessage("Complete!!"); } else { mObserver.setResult(UIResponseObserver.RESULT_FAIL); mObserver.setFailMessage("Fail!!"); } } break; case UserRequestHandler.SPDX_AUTO_IDENTIFY: { mObserver.setMessageHeader("Ready to start SPDX Auto Identify ... \n"); UESPDXAutoIdentify ue = (UESPDXAutoIdentify) mEntity; SPDXAutoIdentifyController controller = new SPDXAutoIdentifyController(); AutoIdentifyResult autoIdentifyResultReport = controller.startAutoIdentifyFromSPDX(ue, mObserver); if (mObserver.getResult() != UIResponseObserver.RESULT_FAIL) { mObserver.setSuccessMessage(autoIdentifyResultReport.toString()); mObserver.setResult(UIResponseObserver.RESULT_SUCCESS); } else { mObserver.setFailMessage(autoIdentifyResultReport.toString()); } mObserver.setReturnValue(autoIdentifyResultReport); } break; } mObserver.pushMessage("Execution Thread - execution is completed"); isDone = true; long finishTime = System.currentTimeMillis(); log.info(UserRequestHandler.getCommandName(mRequestCode) + " - finish: (" + (finishTime - startTime) + " ms.)"); closeAction(); }
From source file:net.spfbl.core.Analise.java
public TreeSet<String> getResultFullSet() throws InterruptedException { TreeMap<String, String> map = new TreeMap<String, String>(); whiteFullSet(map);//from ww w . j a va2 s . c om File resultFile = getResultFile(); if (resultFile.exists()) { try { FileReader fileReader = new FileReader(resultFile); BufferedReader bufferedReader = new BufferedReader(fileReader); try { String line; while ((line = bufferedReader.readLine()) != null) { int index = line.indexOf(' '); if (index > 0) { String ip = line.substring(0, index); try { if (containsResultSet(ip)) { String result = line.substring(index + 1); map.put(ip, result); } } catch (InterruptedException ex) { Server.logError(ex); } } } } finally { bufferedReader.close(); } } catch (Exception ex) { Server.logError(ex); } } TreeSet<String> set = new TreeSet<String>(); for (String ip : map.keySet()) { String result = map.get(ip); set.add(ip + " " + result); } return set; }
From source file:com.brejza.matt.habmodem.Dsp_service.java
@Override public void HabitatRx(TreeMap<Long, Telemetry_string> data, boolean success, String callsign, long startTime, long endTime, AscentRate as, double maxAltitude) { mapPayloads.get(callsign.toUpperCase()).setQueryOngoing(0); if (success) { String call = callsign.toUpperCase(); System.out.println("DEBUG: Got " + data.size() + " sentences for payload " + callsign); logEvent("Habitat Query Got " + data.size() + " Sentences For Payload " + callsign, true); if (mapPayloads.containsKey(call)) { Payload p = mapPayloads.get(call); //if havnt already got a telem_config, see if one exists in hab_con if (p.telemetryConfig == null) { if (hab_con.getTelemConfigs().containsKey(call)) { p.telemetryConfig = hab_con.getTelemConfigs().get(call); }/*from w w w . j a v a 2 s .c o m*/ } long lt = p.getLastTime(); p.setLastUpdated(endTime); p.putPackets(data); p.setIsActivePayload(true); if (p.colour == 0) p.setNewColour(newColour()); if (data.size() > 0) { if (lt < Long.valueOf(data.lastKey())) { if (as != null) { if (as.valid()) p.ascentRate = as; } } } } else { Payload p = new Payload(callsign, newColour(), true); if (hab_con.getTelemConfigs().containsKey(call)) { p.telemetryConfig = hab_con.getTelemConfigs().get(call); } p.setLastUpdated(endTime); p.data = data; mapPayloads.put(call, p); if (as != null) { if (as.valid()) mapPayloads.get(call).ascentRate = as; } } mapPayloads.get(call).putMaxAltitude(maxAltitude); Intent i = new Intent(HABITAT_NEW_DATA); if (data.size() > 0) i.putExtra(TELEM_STR, data.get(data.lastKey()).getSentence()); sendBroadcast(i); } else { logEvent("Habitat Query Failed - " + callsign, true); } }