/** * Finds all the pairs of eucleidean distances between cluster 1 and cluster 2 * * @param cluster 1 * @param cluster 2 * @return list of all distances */ public List<Double> findAllEucleideanDistances(Cluster cl1, Cluster cl2) { List<Double> values = new ArrayList<Double>(); for (int i = 0; i < cl1.size(); i++) { for (int j = 0; j < cl2.size(); j++) { values.add(findEucleideanDistance(cl1.getRecordPointsAt(i), cl2.getRecordPointsAt(j))); } } return values; }
public List<String[]> findPoints(Cluster data, List<AttributeCluster> attrbs) { List<String[]> list = new ArrayList<String[]>(); for (int i = 0; i < data.size(); i++) { list.add(getPoints(attrbs, data.getRecords().get(i))); } return list; }
public double findEucleideanDistance(String[] p1, Cluster cluster) { double sum = 0.0; for (int i = 0; i < cluster.size(); i++) { sum += findEucleideanDistance(p1, cluster.getRecordPointsAt(i)); } return sum; }
private void alterCentroid(Cluster cluster, List<AttributeCluster> attrb) { if (cluster.size() > 0) { List<Double> attr = new ArrayList<>(); for (int i = 0; i < attrb.size(); i++) { if (attrb.get(i).getType() == TypeAttribute.continuous) { List<Double> mean = cluster.getColumnAt(i); attr.add(new CommonLogics().mean(mean)); } } cluster.setCentroid(new Centroid(attr)); } }
/** * Calculates SSE * * @param cluster */ public void calculateSSEForCluster(Cluster cluster) { double SSE = 0.0; for (int i = 0; i < cluster.size(); i++) { double temp = findEucleideanDistance( cluster.getCentroid().getAttrList(), getPoints(cluster.getAttributes(), cluster.getRecords().get(i))); SSE += temp * temp; } cluster.setSSE(SSE); }
/** * Add points from cluster to Bisect Cluster data model * * @param bisect * @param data */ public void addClusterPoints(BisectCluster bisect, Cluster data) { CluseterList list = new CluseterList(); list.addCluster(bisect.getC1()); list.addCluster(bisect.getC2()); list.clearsClusterPoints(); for (int i = 0; i < data.size(); i++) { int temp = findClosestClusterAndAddPoint( list, getPoints(data.getAttributes(), data.getRecords().get(i))); list.getClusterAt(temp).addPoints(data.getRecords().get(i)); } calculateSSEForCluster(bisect.getC1()); // System.out.println(bisect.getC1().getSSE()); calculateSSEForCluster(bisect.getC2()); bisect.setTotalSSE(bisect.getC1().getSSE() + bisect.getC2().getSSE()); }