From b05dae3da4b9992a8578e9449e859278d307ab5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Mar=C3=ADa=20Mateos?= Date: Mon, 23 Sep 2013 11:20:07 +0200 Subject: [PATCH] Changed LeaderFollower. Now searches for *all* the clusters above the correlation limit and then looks for the one with enough peak amplitude in reverse order --- .../techniques/LeaderFollower.java | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/main/java/jclustering/techniques/LeaderFollower.java b/src/main/java/jclustering/techniques/LeaderFollower.java index 75efe63..12de918 100644 --- a/src/main/java/jclustering/techniques/LeaderFollower.java +++ b/src/main/java/jclustering/techniques/LeaderFollower.java @@ -238,12 +238,12 @@ public JPanel makeConfig() { * A number i >= 0 if good correlation and amplitude are found */ private int _getClosestCluster(double [] tac) { - - int i = -1; + double max_score = this.threshold; int size = clusters.size(); - // Find the cluster with the highest correlation with this TAC + // Find clusters with a correlation above the threshold + ArrayList selected = new ArrayList(); for (int j = 0; j < size; j++) { Cluster c = clusters.get(j); // Smooth the TAC only for correlation computing purposes, do @@ -255,20 +255,26 @@ private int _getClosestCluster(double [] tac) { else score = pc.correlation(smooth_tac, centroid); if (score > max_score && score > corr_limits.get(c)) { - i = j; + selected.add(j); max_score = score; } } // No cluster found - if (i == -1) return CLUSTER_NOT_FOUND; - - // Cluster found, check amplitude - Cluster c = clusters.get(i); - double peak = StatUtils.max(tac); - double threspeak = c.getPeakMean() - c.getPeakStdev(); - // Peak amplitude above threshold - if (peak >= threspeak) return i; + if (selected.size() == 0) return CLUSTER_NOT_FOUND; + + // Clusters found, check amplitude + // Sort first, we want the maximum amplitued with the most + // similar voxels + Collections.sort(selected); + Collections.reverse(selected); // Highest correlation first + for (int s : selected) { + Cluster c = clusters.get(s); + double peak = StatUtils.max(tac); + double threspeak = c.getPeakMean() - 1.96 * c.getPeakStdev(); + // Peak amplitude above threshold + if (peak >= threspeak) return s; + } // Not enough amplitude: not found return CLUSTER_NOT_FOUND;