Exemplo n.º 1
0
  /**
   * Fits the mixture (or mixing) distribution to the data.
   *
   * @param data the data supposedly generated from the mixture
   * @param method the method to be used. Refer to the static final variables of this class.
   */
  public void fit(DoubleVector data, int method) {
    DoubleVector data2 = (DoubleVector) data.clone();
    if (data2.unsorted()) data2.sort();

    int n = data2.size();
    int start = 0;
    DoubleVector subset;
    DiscreteFunction d = new DiscreteFunction();
    for (int i = 0; i < n - 1; i++) {
      if (separable(data2, start, i, data2.get(i + 1))
          && separable(data2, i + 1, n - 1, data2.get(i))) {
        subset = (DoubleVector) data2.subvector(start, i);
        d.plusEquals(fitForSingleCluster(subset, method).timesEquals(i - start + 1));
        start = i + 1;
      }
    }
    subset = (DoubleVector) data2.subvector(start, n - 1);
    d.plusEquals(fitForSingleCluster(subset, method).timesEquals(n - start));
    d.sort();
    d.normalize();
    mixingDistribution = d;
  }