/** * Creates an instance of a VoltageCluster with the specified parameters. These are mostly * parameters that are passed directly to VoltageScorer and KMeansClusterer. * * @param g the graph whose nodes are to be clustered * @param num_candidates the number of candidate clusters to create */ public VoltageClusterer(Network<N, E> g, int num_candidates) { Preconditions.checkArgument(num_candidates >= 1, "must generate >= 1 candidates"); this.num_candidates = num_candidates; this.kmc = new KMeansClusterer<N>(); rand = new Random(); this.g = g; }
/** * alternative to addTwoCandidateClusters(): cluster nodes by voltages into 2 clusters. We only * consider the smaller of the two clusters returned by k-means to be a 'true' cluster candidate; * the other is a garbage cluster. * * @param candidates the list of clusters to populate * @param voltage_ranks the voltage values for each node */ protected void addOneCandidateCluster( LinkedList<Set<N>> candidates, Map<N, double[]> voltage_ranks) { try { List<Map<N, double[]>> clusters; clusters = new ArrayList<Map<N, double[]>>(kmc.cluster(voltage_ranks, 2)); if (clusters.get(0).size() < clusters.get(1).size()) { candidates.add(clusters.get(0).keySet()); } else { candidates.add(clusters.get(1).keySet()); } } catch (NotEnoughClustersException e) { // no valid candidates, continue } }
double distance = squaredError(location, closest); double dist_cur = squaredError(location, centroid); if (dist_cur < distance) { distance = dist_cur;
Map<double[], Map<T, double[]>> clusterMap = assignToClusters(object_locations, centroids); means[index++] = Stats.meanOf(location); max_movement = Math.max(max_movement, Math.sqrt(squaredError(centroid, means))); new_centroids.add(means); clusterMap = assignToClusters(object_locations, new_centroids);
Map<double[], Map<T, double[]>> clusterMap = assignToClusters(object_locations, centroids); clusterMap = assignToClusters(object_locations, new_centroids);
Map<double[], Map<T, double[]>> clusterMap = assignToClusters(object_locations, centroids); clusterMap = assignToClusters(object_locations, new_centroids);
/** * alternative to addTwoCandidateClusters(): cluster vertices by voltages * into 2 clusters. We only consider the smaller of the two clusters * returned by k-means to be a 'true' cluster candidate; the other is a * garbage cluster. * * @param candidates * @param voltage_ranks */ protected void addOneCandidateCluster(LinkedList<Set<V>> candidates, Map<V, double[]> voltage_ranks) { try { List<Map<V, double[]>> clusters; clusters = new ArrayList<Map<V, double[]>>( kmc.cluster(voltage_ranks, 2)); if (clusters.get(0).size() < clusters.get(1).size()) { candidates.add(clusters.get(0).keySet()); } else { candidates.add(clusters.get(1).keySet()); } } catch (NotEnoughClustersException e) { // no valid candidates, continue } }
/** * Creates an instance of a VoltageCluster with the specified parameters. * These are mostly parameters that are passed directly to VoltageScorer * and KMeansClusterer. * * @param num_candidates the number of candidate clusters to create */ public VoltageClusterer(Graph<V,E> g, int num_candidates) { if (num_candidates < 1) throw new IllegalArgumentException("must generate >=1 candidates"); this.num_candidates = num_candidates; this.kmc = new KMeansClusterer<V>(); rand = new Random(); this.g = g; }
Map<double[], Map<T, double[]>> clusterMap = assignToClusters( object_locations, centroids); clusterMap = assignToClusters(object_locations, new_centroids);
/** * alternative to addTwoCandidateClusters(): cluster vertices by voltages into 2 clusters. * We only consider the smaller of the two clusters returned * by k-means to be a 'true' cluster candidate; the other is a garbage cluster. * @param candidates the list of clusters to populate * @param voltage_ranks the voltage values for each vertex */ protected void addOneCandidateCluster(LinkedList<Set<V>> candidates, Map<V, double[]> voltage_ranks) { try { List<Map<V, double[]>> clusters; clusters = new ArrayList<Map<V, double[]>>(kmc.cluster(voltage_ranks, 2)); if (clusters.get(0).size() < clusters.get(1).size()) candidates.add(clusters.get(0).keySet()); else candidates.add(clusters.get(1).keySet()); } catch (NotEnoughClustersException e) { // no valid candidates, continue } }
/** * Creates an instance of a VoltageCluster with the specified parameters. * These are mostly parameters that are passed directly to VoltageScorer * and KMeansClusterer. * * @param g the graph whose vertices are to be clustered * @param num_candidates the number of candidate clusters to create */ public VoltageClusterer(Graph<V,E> g, int num_candidates) { if (num_candidates < 1) throw new IllegalArgumentException("must generate >=1 candidates"); this.num_candidates = num_candidates; this.kmc = new KMeansClusterer<V>(); rand = new Random(); this.g = g; }
/** * alternative to addTwoCandidateClusters(): cluster vertices by voltages into 2 clusters. * We only consider the smaller of the two clusters returned * by k-means to be a 'true' cluster candidate; the other is a garbage cluster. * @param candidates * @param voltage_ranks */ protected void addOneCandidateCluster(LinkedList<Set<V>> candidates, Map<V, double[]> voltage_ranks) { try { List<Map<V, double[]>> clusters; clusters = new ArrayList<Map<V, double[]>>(kmc.cluster(voltage_ranks, 2)); if (clusters.get(0).size() < clusters.get(1).size()) candidates.add(clusters.get(0).keySet()); else candidates.add(clusters.get(1).keySet()); } catch (NotEnoughClustersException e) { // no valid candidates, continue } }
/** * Creates an instance of a VoltageCluster with the specified parameters. * These are mostly parameters that are passed directly to VoltageScorer and * KMeansClusterer. * * @param num_candidates * the number of candidate clusters to create */ public VoltageClusterer(Graph<V, E> g, int num_candidates) { if (num_candidates < 1) { throw new IllegalArgumentException("must generate >=1 candidates"); } this.num_candidates = num_candidates; this.kmc = new KMeansClusterer<V>(); rand = new Random(); this.g = g; }
/** * Do k-means with three intervals and pick the smaller two clusters * (presumed to be on the ends); this is closer to the Wu-Huberman method. * * @param candidates * @param voltage_ranks */ protected void addTwoCandidateClusters(LinkedList<Set<V>> candidates, Map<V, double[]> voltage_ranks) { try { List<Map<V, double[]>> clusters = new ArrayList<Map<V, double[]>>( kmc.cluster(voltage_ranks, 3)); boolean b01 = clusters.get(0).size() > clusters.get(1).size(); boolean b02 = clusters.get(0).size() > clusters.get(2).size(); boolean b12 = clusters.get(1).size() > clusters.get(2).size(); if (b01 && b02) { candidates.add(clusters.get(1).keySet()); candidates.add(clusters.get(2).keySet()); } else if (!b01 && b12) { candidates.add(clusters.get(0).keySet()); candidates.add(clusters.get(2).keySet()); } else if (!b02 && !b12) { candidates.add(clusters.get(0).keySet()); candidates.add(clusters.get(1).keySet()); } } catch (NotEnoughClustersException e) { // no valid candidates, continue } }
/** * Do k-means with three intervals and pick the smaller two clusters (presumed to be on the ends); * this is closer to the Wu-Huberman method. * * @param candidates the list of clusters to populate * @param voltage_ranks the voltage values for each node */ protected void addTwoCandidateClusters( LinkedList<Set<N>> candidates, Map<N, double[]> voltage_ranks) { try { List<Map<N, double[]>> clusters = new ArrayList<Map<N, double[]>>(kmc.cluster(voltage_ranks, 3)); boolean b01 = clusters.get(0).size() > clusters.get(1).size(); boolean b02 = clusters.get(0).size() > clusters.get(2).size(); boolean b12 = clusters.get(1).size() > clusters.get(2).size(); if (b01 && b02) { candidates.add(clusters.get(1).keySet()); candidates.add(clusters.get(2).keySet()); } else if (!b01 && b12) { candidates.add(clusters.get(0).keySet()); candidates.add(clusters.get(2).keySet()); } else if (!b02 && !b12) { candidates.add(clusters.get(0).keySet()); candidates.add(clusters.get(1).keySet()); } } catch (NotEnoughClustersException e) { // no valid candidates, continue } }
List<Map<V, double[]>> clusters = new ArrayList<Map<V, double[]>>(kmc.cluster(voltage_ranks, 3)); boolean b01 = clusters.get(0).size() > clusters.get(1).size(); boolean b02 = clusters.get(0).size() > clusters.get(2).size();
List<Map<V, double[]>> clusters = new ArrayList<Map<V, double[]>>(kmc.cluster(voltage_ranks, 3)); boolean b01 = clusters.get(0).size() > clusters.get(1).size(); boolean b02 = clusters.get(0).size() > clusters.get(2).size();
Collection<Map<N, double[]>> high_low = kmc.cluster(occur_counts, 2);
Collection<Map<V, double[]>> high_low = kmc.cluster(occur_counts, 2);
Collection<Map<V, double[]>> high_low = kmc.cluster(occur_counts, 2);