Example #1
0
  private boolean matrixDifferencesSmallerThanEpsilon() {
    boolean areAllSmallerThanEpsilon = true;
    for (int p = 0; p < numberOfPoints; p++) {
      for (int c = 0; c < numberOfClusters; c++) {
        double prev = prevMembershipMatrix.get(p, c);
        double curr = membershipMatrix.get(p, c);

        if (Math.abs(curr - prev) > epsilon) {
          areAllSmallerThanEpsilon = false;
          break;
        }
      }
    }

    return areAllSmallerThanEpsilon;
  }
Example #2
0
  private Centroid calculateCentroidOfIndex(int index) {
    double[] values = new double[pointsDimensions];
    double nominator, denominator;

    for (int dim = 0; dim < pointsDimensions; dim++) {
      nominator = 0;
      denominator = 0;

      for (int i = 0; i < numberOfPoints; i++) {
        nominator +=
            Math.pow(membershipMatrix.get(i, index), fuzziness) * points.get(i).getDim(dim);
        denominator += Math.pow(membershipMatrix.get(i, index), fuzziness);
      }

      values[dim] = nominator / denominator;
    }

    return new Centroid(values);
  }