protected void searchMedian(Instances instances) {
    medians = new double[instances.numAttributes()];
    imputations = new int[instances.numAttributes()];

    for (int j = 0; j < instances.numAttributes(); ++j) {
      int numPresentValues = 0;
      if (instances.attribute(j).isNumeric()) {
        double[] values = new double[instances.numInstances()];
        for (int i = 0; i < instances.numInstances(); ++i) {
          Instance current = instances.get(i);
          if (Utils.isMissingValue(current.value(j)) == false) {
            values[numPresentValues] = current.value(j);
            numPresentValues += 1;
          }
        }
        if (numPresentValues > 0) {
          double[] goodValues = Arrays.copyOf(values, numPresentValues);
          Median median = new Median();
          medians[j] = median.evaluate(goodValues);
        }
      }
    }

    for (int j = 0; j < instances.numAttributes(); ++j) {
      if (instances.attribute(j).isNumeric()) {
        Conversion.log(
            "OK",
            "Impute Numeric",
            "Attribute " + instances.attribute(j) + " - Median: " + medians[j]);
      }
    }
  }
예제 #2
0
  private Map<String, Double> getSampleMedian(Set<String> samp, List<String> bad) {
    Map<String, Double> sampleMedian = new LinkedHashMap<>();

    for (String s : samp) {
      List<Double> list = new LinkedList<>();
      for (Map.Entry<String, Map<String, Sample>> entry : samples.entrySet()) {
        if (!bad.contains(entry.getKey())) {
          list.add(entry.getValue().get(s).getNorm1());
        }
      }
      sampleMedian.put(s, median.evaluate(toDoubleArray(list)));
    }
    return sampleMedian;
  }
예제 #3
0
  private double getMedDepth(double[] depth, Set<String> samp) {
    int i = 0;

    for (Map.Entry<String, Map<String, Sample>> entry : samples.entrySet()) {
      Map<String, Sample> sampleMap = entry.getValue();

      for (Map.Entry<String, Sample> sampleEntry : sampleMap.entrySet()) {
        Sample sample = sampleEntry.getValue();
        double norm1 = Precision.round((sample.getCov() * factor.get(sample.getSample())), 2);
        sample.setNorm1(norm1);
        depth[i++] = norm1;
        samp.add(sample.getSample());
      }
    }
    return median.evaluate(depth);
  }
예제 #4
0
  /**
   * Main method, makes the statistics calculation according to the algorithm print result to the
   * Standart output
   */
  public void doWork() {
    double[] depth = new double[samples.size()];

    Set<String> samp = new HashSet<>();

    double medDepth = getMedDepth(depth, samp);

    List<String> bad = new LinkedList<>();
    List<Double> gooddepth = new LinkedList<>();

    splitQualitySamples(samp, medDepth, bad, gooddepth);

    medDepth = median.evaluate(toDoubleArray(gooddepth));

    Map<String, Double> factor2 = new LinkedHashMap<>();

    setFactor2(medDepth, bad, factor2);

    Map<String, Double> sampleMedian = getSampleMedian(samp, bad);

    setNorm(medDepth, bad, factor2, sampleMedian);

    printResult(bad);
  }
예제 #5
0
 public static Double median(double[] values) {
   Median medianCalculator = new Median();
   return medianCalculator.evaluate(values);
 }