com.carrotsearch.hppc.DoubleArrayList Java Examples

The following examples show how to use com.carrotsearch.hppc.DoubleArrayList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TimeSeriesLoader.java    From SFA with GNU General Public License v3.0 6 votes vote down vote up
public static TimeSeries readSampleSubsequence(File dataset) throws IOException {
  try (BufferedReader br = new BufferedReader(new FileReader(dataset))) {
    DoubleArrayList data = new DoubleArrayList();
    String line = null;
    while ((line = br.readLine()) != null) {
      line = line.trim();
      String[] values = line.split("[ \\t]");
      if (values.length > 0) {
        for (String value : values) {
          try {
            value = value.trim();
            if (isNonEmptyColumn(value)) {
              data.add(Double.parseDouble(value));
            }
          } catch (NumberFormatException nfe) {
            // Parse-Exception ignored
          }
        }
      }
    }
    return new TimeSeries(data.toArray());
  }
}
 
Example #2
Source File: TimeSeriesLoader.java    From SFA with GNU General Public License v3.0 6 votes vote down vote up
public static TimeSeries[] readSamplesQuerySeries(File dataset) throws IOException {
  List<TimeSeries> samples = new ArrayList<>();
  try (BufferedReader br = new BufferedReader(new FileReader(dataset))) {
    String line = null;
    while ((line = br.readLine()) != null) {
      DoubleArrayList data = new DoubleArrayList();
      line = line.trim();
      String[] values = line.split("[ \\t]");
      if (values.length > 0) {
        for (String value : values) {
          try {
            value = value.trim();
            if (isNonEmptyColumn(value)) {
              data.add(Double.parseDouble(value));
            }
          } catch (NumberFormatException nfe) {
            // Parse-Exception ignored
          }
        }
        samples.add(new TimeSeries(data.toArray()));
      }
    }
  }
  return samples.toArray(new TimeSeries[]{});
}
 
Example #3
Source File: SubTaskAverageCalculator.java    From gerbil with GNU Affero General Public License v3.0 6 votes vote down vote up
protected void addAverages(EvaluationResultContainer subTaskResults, EvaluationResultContainer results) {
    Map<String, DoubleArrayList> mapping = createNameValueMapping(subTaskResults.getResults());
    DoubleArrayList values;
    int subTaskCount = subTaskResults.getResults().size();
    double sum;
    for (String name : mapping.keySet()) {
        values = mapping.get(name);
        if (values.elementsCount == subTaskCount) {
            sum = 0;
            for (int i = 0; i < values.elementsCount; ++i) {
                sum += values.buffer[i];
            }
            results.addResult(new DoubleEvaluationResult(name, sum / subTaskCount));
        }
    }
}
 
Example #4
Source File: Median.java    From Palmetto with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public double summarize(double[] values, double[] weights) {
    if (values.length == 0) {
        throw new IllegalArgumentException(
                "The given array has to have at least one element to determine the modus.");
    }
    DoubleArrayList weightedValues = new DoubleArrayList(values.length);
    for (int i = 0; i < values.length; ++i) {
        if (!Double.isNaN(values[i])) {
            weightedValues.add(weights[i] * values[i]);
        }
    }
    if (weightedValues.size() == 0) {
        return 0;
    }
    double weightedValuesAsArray[] = weightedValues.toArray();
    Arrays.sort(weightedValuesAsArray);
    if ((weightedValuesAsArray.length & 1) > 0) {
        return weightedValuesAsArray[weightedValuesAsArray.length / 2];
    } else {
        return (weightedValuesAsArray[weightedValuesAsArray.length / 2] + weightedValuesAsArray[(weightedValuesAsArray.length / 2) - 1]) / 2.0;
    }
}
 
Example #5
Source File: SubTaskAverageCalculator.java    From gerbil with GNU Affero General Public License v3.0 5 votes vote down vote up
private Map<String, DoubleArrayList> createNameValueMapping(List<EvaluationResult> results) {
    Map<String, DoubleArrayList> mapping = new HashMap<String, DoubleArrayList>();
    for (EvaluationResult result : results) {
        addToMapping(mapping, result);
    }
    return mapping;
}
 
Example #6
Source File: PlotBootstrapScores.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private static double[] readArray(File file) throws IOException {
  final Iterable<String> lines = GZIPByteSource.fromCompressed(
      Files.asByteSource(file)).asCharSource(Charsets.UTF_8).readLines();

  final DoubleArrayList ret = new DoubleArrayList();
  for (final String line : lines) {
    ret.add(100.0 * Double.parseDouble(line));
  }
  return ret.toArray();
}
 
Example #7
Source File: EAScoringObserver.java    From tac-kbp-eal with MIT License 5 votes vote down vote up
private void writeArray(DoubleArrayList numbers, File file) throws IOException {
  final ByteSink sink = GZIPByteSink.gzipCompress(Files.asByteSink(file));
  final PrintWriter out = new PrintWriter(sink.asCharSink(Charsets.UTF_8).openBufferedStream());
  for (final DoubleCursor cursor : numbers) {
    out.println(cursor.value);
  }
  out.close();
  ;
}
 
Example #8
Source File: GoldStandardReader.java    From Palmetto with GNU Affero General Public License v3.0 5 votes vote down vote up
public static double[] readGoldStandard(String file) throws IOException {
    List<String> lines = FileUtils.readLines(new File(file));

    DoubleArrayList ratings = new DoubleArrayList();
    for (String line : lines) {
        try {
            ratings.add(Double.parseDouble(line));
        } catch (NumberFormatException e) {
            throw new IOException("Error while reading gold standard.", e);
        }
    }
    return ratings.toArray();
}
 
Example #9
Source File: DoubleFieldMapper.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public CustomDoubleNumericDocValuesField(String  name, double value) {
    super(name);
    values = new DoubleArrayList();
    add(value);
}
 
Example #10
Source File: EAScoringObserver.java    From tac-kbp-eal with MIT License 4 votes vote down vote up
private void writeSamplesScoringBreakdown(String modeName,
    Collection<BrokenDownSummaryConfusionMatrix<Symbol>> data,
    File outputFile, File rawDir) throws IOException {
  final StringBuilder sb = new StringBuilder();

  sb.append("BREAKDOWN BY ").append(modeName).append("\n");

  for (final Map.Entry<String, Collection<Symbol>> FMeasureSymbol : F_MEASURES_TO_PRINT.asMap()
      .entrySet()) {
    final Multimap<String, FMeasureCounts> fMeasuresToPrint = toFMeasures(data, FMeasureSymbol);

    final ImmutableMap.Builder<String, PercentileComputer.Percentiles> precisionPercentiles =
        ImmutableMap.builder();
    final ImmutableMap.Builder<String, PercentileComputer.Percentiles> recallPercentiles =
        ImmutableMap.builder();
    final ImmutableMap.Builder<String, PercentileComputer.Percentiles> fPercentiles =
        ImmutableMap.builder();

    final PercentileComputer nistComputer = PercentileComputer.nistPercentileComputer();

    for (final Map.Entry<String, Collection<FMeasureCounts>> entry : fMeasuresToPrint.asMap()
        .entrySet()) {
      final DoubleArrayList precisions = new DoubleArrayList(entry.getValue().size());
      final DoubleArrayList recalls = new DoubleArrayList(entry.getValue().size());
      final DoubleArrayList fs = new DoubleArrayList(entry.getValue().size());

      for (final FMeasureCounts counts : entry.getValue()) {
        precisions.add((double) counts.precision());
        recalls.add((double) counts.recall());
        fs.add((double) counts.F1());
      }

      final String rawPrefix = entry.getKey() + "_" + FMeasureSymbol.getKey();
      writeArray(precisions, new File(rawDir, rawPrefix + ".precisions.txt"));
      writeArray(recalls, new File(rawDir, rawPrefix + ".recalls.txt"));
      writeArray(fs, new File(rawDir, rawPrefix + ".fs.txt"));
      precisionPercentiles.put(entry.getKey(),
          nistComputer.calculatePercentilesAdoptingData(precisions.toArray()));
      recallPercentiles.put(entry.getKey(),
          nistComputer.calculatePercentilesAdoptingData(recalls.toArray()));
      fPercentiles.put(entry.getKey(),
          nistComputer.calculatePercentilesAdoptingData(fs.toArray()));
    }

    dumpPercentilesForMetric("Precision", precisionPercentiles.build(), FMeasureSymbol, sb);
    dumpPercentilesForMetric("Recall", recallPercentiles.build(), FMeasureSymbol, sb);
    dumpPercentilesForMetric("F1", fPercentiles.build(), FMeasureSymbol, sb);
  }

  Files.asCharSink(outputFile, Charsets.UTF_8).write(sb.toString());
}