Java Code Examples for org.apache.commons.math3.util.Pair#getKey()

The following examples show how to use org.apache.commons.math3.util.Pair#getKey() . 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: Insert_stmtGenerator.java    From antsdb with GNU Lesser General Public License v3.0 6 votes vote down vote up
private List<InsertOnDuplicate> gen(GeneratorContext ctx, 
                                    TableMeta table, 
                                    List<InsertSingleRow> inserts, 
                                    Insert_duplicate_clauseContext rule) {
    List<InsertOnDuplicate> result = new ArrayList<>();
    Planner planner = GeneratorUtil.getSingleTablePlanner(ctx, table);
    Pair<List<ColumnMeta>, List<Operator>> sets;
    GTable gtable = ctx.getGtable(table.getObjectName());
    sets = Update_stmtGenerator.gen(ctx, planner, table, rule.update_stmt_set());
    planner.run();
    for (InsertSingleRow insert:inserts) {
        InsertOnDuplicate iod = new InsertOnDuplicate(ctx.getOrca(), table, gtable, sets.getKey(), sets.getValue());
        iod.setInsert(insert);
        result.add(iod);
    }
    return result;
}
 
Example 2
Source File: FixedWidthReader.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
private Table read(FixedWidthReadOptions options, boolean headerOnly) throws IOException {
  Pair<Reader, ColumnType[]> pair = getReaderAndColumnTypes(options);
  Reader reader = pair.getKey();
  ColumnType[] types = pair.getValue();

  FixedWidthParser parser = fixedWidthParser(options);

  try {
    return parseRows(options, headerOnly, reader, types, parser);
  } finally {
    if (options.source().reader() == null) {
      // if we get a reader back from options it means the client opened it, so let the client
      // close it
      // if it's null, we close it here.
      parser.stopParsing();
      reader.close();
    }
  }
}
 
Example 3
Source File: CsvReader.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
private Table read(CsvReadOptions options, boolean headerOnly) throws IOException {
  Pair<Reader, ColumnType[]> pair = getReaderAndColumnTypes(options.source(), options);
  Reader reader = pair.getKey();
  ColumnType[] types = pair.getValue();

  AbstractParser<?> parser = csvParser(options);

  try {
    return parseRows(options, headerOnly, reader, types, parser, options.sampleSize());
  } finally {
    if (options.source().reader() == null) {
      // if we get a reader back from options it means the client opened it, so let the client
      // close it
      // if it's null, we close it here.
      parser.stopParsing();
      reader.close();
    }
  }
}
 
Example 4
Source File: CsvReader.java    From tablesaw with Apache License 2.0 6 votes vote down vote up
private Table read(CsvReadOptions options, boolean headerOnly) throws IOException {
  Pair<Reader, ColumnType[]> pair = getReaderAndColumnTypes(options.source(), options);
  Reader reader = pair.getKey();
  ColumnType[] types = pair.getValue();

  AbstractParser<?> parser = csvParser(options);

  try {
    return parseRows(options, headerOnly, reader, types, parser, options.sampleSize());
  } finally {
    if (options.source().reader() == null) {
      // if we get a reader back from options it means the client opened it, so let the client
      // close it
      // if it's null, we close it here.
      parser.stopParsing();
      reader.close();
    }
  }
}
 
Example 5
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the highest value with non-zero probability.
 *
 * @return the highest value with non-zero probability.
 */
public double getSupportUpperBound() {
    double max = Double.NEGATIVE_INFINITY;
    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() > max && sample.getValue() > 0) {
            max = sample.getKey();
        }
    }

    return max;
}
 
Example 6
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public double cumulativeProbability(final int x) {
    double probability = 0;

    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() <= x) {
            probability += sample.getValue();
        }
    }

    return probability;
}
 
Example 7
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the highest value with non-zero probability.
 *
 * @return the highest value with non-zero probability.
 */
public double getSupportUpperBound() {
    double max = Double.NEGATIVE_INFINITY;
    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() > max && sample.getValue() > 0) {
            max = sample.getKey();
        }
    }

    return max;
}
 
Example 8
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code sum((singletons[i] - mean) ^ 2 * probabilities[i])}
 */
public double getNumericalVariance() {
    double mean = 0;
    double meanOfSquares = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        mean += sample.getValue() * sample.getKey();
        meanOfSquares += sample.getValue() * sample.getKey() * sample.getKey();
    }

    return meanOfSquares - mean * mean;
}
 
Example 9
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code sum((singletons[i] - mean) ^ 2 * probabilities[i])}
 */
public double getNumericalVariance() {
    double mean = 0;
    double meanOfSquares = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        mean += sample.getValue() * sample.getKey();
        meanOfSquares += sample.getValue() * sample.getKey() * sample.getKey();
    }

    return meanOfSquares - mean * mean;
}
 
Example 10
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public double cumulativeProbability(final int x) {
    double probability = 0;

    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() <= x) {
            probability += sample.getValue();
        }
    }

    return probability;
}
 
Example 11
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the lowest value with non-zero probability.
 *
 * @return the lowest value with non-zero probability.
 */
public int getSupportLowerBound() {
    int min = Integer.MAX_VALUE;
    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() < min && sample.getValue() > 0) {
            min = sample.getKey();
        }
    }

    return min;
}
 
Example 12
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the lowest value with non-zero probability.
 *
 * @return the lowest value with non-zero probability.
 */
public double getSupportLowerBound() {
    double min = Double.POSITIVE_INFINITY;
    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() < min && sample.getValue() > 0) {
            min = sample.getKey();
        }
    }

    return min;
}
 
Example 13
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public double cumulativeProbability(final int x) {
    double probability = 0;

    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() <= x) {
            probability += sample.getValue();
        }
    }

    return probability;
}
 
Example 14
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code sum(singletons[i] * probabilities[i])}
 */
public double getNumericalMean() {
    double mean = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        mean += sample.getValue() * sample.getKey();
    }

    return mean;
}
 
Example 15
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public double cumulativeProbability(final double x) {
    double probability = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() <= x) {
            probability += sample.getValue();
        }
    }

    return probability;
}
 
Example 16
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the highest value with non-zero probability.
 *
 * @return the highest value with non-zero probability.
 */
public int getSupportUpperBound() {
    int max = Integer.MIN_VALUE;
    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() > max && sample.getValue() > 0) {
            max = sample.getKey();
        }
    }

    return max;
}
 
Example 17
Source File: EnumeratedIntegerDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * Returns the highest value with non-zero probability.
 *
 * @return the highest value with non-zero probability.
 */
public int getSupportUpperBound() {
    int max = Integer.MIN_VALUE;
    for (final Pair<Integer, Double> sample : innerDistribution.getPmf()) {
        if (sample.getKey() > max && sample.getValue() > 0) {
            max = sample.getKey();
        }
    }

    return max;
}
 
Example 18
Source File: EnumeratedRealDistribution.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @return {@code sum(singletons[i] * probabilities[i])}
 */
public double getNumericalMean() {
    double mean = 0;

    for (final Pair<Double, Double> sample : innerDistribution.getPmf()) {
        mean += sample.getValue() * sample.getKey();
    }

    return mean;
}
 
Example 19
Source File: CocktailParty.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
/**
 * Removes dangling mentions (where no candidate entity has a coherence edge)
 * from gaph. They will influence the minimum weighted degree but can
 * never be improved. Set the solution to the entity with the highest
 * mention-entity weight.
 *
 * @param solution Solution will be updated, setting the correct entity using
 *                local similarity for dangling mentions.
 * @return Node ids of nodes to remove.
 */
private TIntSet removeUnconnectedMentionEntityPairs(Graph g, Map<ResultMention, List<ResultEntity>> solution) {
  TIntSet mentionsToRemove = new TIntHashSet();
  for (int mentionId : g.getMentionNodesIds().values()) {
    GraphNode mentionNode = g.getNode(mentionId);
    Mention mention = (Mention) mentionNode.getNodeData();
    TIntDoubleHashMap entityCandidates = mentionNode.getSuccessors();
    if (entityCandidates.size() == 0) {
      continue;
    }
    // Remove all mentions without any entities that have coherence edges.
    if (g.isLocalMention(mentionId)) {
      logger.debug("local mention removed: " + mentionId + " " + mention);
      mentionsToRemove.add(mentionId);
      GraphTracer.gTracer.addMentionToDangling(g.getName(), mention.getMention(), mention.getCharOffset());
      // Set solution to best local candidate.
      Pair<Integer, Double> bestEntityScore = getBestLocalCandidateAndScore(entityCandidates);
      int bestEntity = bestEntityScore.getKey();
      double score = bestEntityScore.getValue();
      updateSolution(solution, g, mention, bestEntity, score);
    }

  }
  TIntSet entitiesToRemove = new TIntHashSet();
  // Remove entities that are only connected to removed mentions.
  for (int entityId : g.getEntityNodesIds().values()) {
    GraphNode entityNode = g.getNode(entityId);
    TIntDoubleHashMap successors = entityNode.getSuccessors();
    int removedCount = 0;
    for (TIntDoubleIterator itr = successors.iterator(); itr.hasNext(); ) {
      itr.advance();
      int neighborId = itr.key();
      if (mentionsToRemove.contains(neighborId)) {
        ++removedCount;
      }
    }
    if (removedCount == successors.size()) {
      entitiesToRemove.add(entityId);
    }
  }
  // Remove mentions + entity candidates from graph, trace.
  TIntSet nodesToRemove = new TIntHashSet(mentionsToRemove.size() + entitiesToRemove.size());
  nodesToRemove.addAll(mentionsToRemove);
  nodesToRemove.addAll(entitiesToRemove);
  return nodesToRemove;
}
 
Example 20
Source File: ProductFileChooser.java    From snap-desktop with GNU General Public License v3.0 4 votes vote down vote up
private void openAdvancedDialog() {
    clearCurrentAdvancedProductOptions();
    File inputFile = getSelectedFile();
    boolean canceled = false;
    Pair<ProductReaderPlugIn, Boolean> foundPlugin = findPlugins(inputFile);
    if(foundPlugin != null){
        if(foundPlugin.getKey() == null) {
            canceled = foundPlugin.getValue();
        }else{
            plugin = foundPlugin.getKey();
        }

    }
    boolean addUIComponents = true;
    MetadataInspector metadataInspector = null;
    if (plugin != null) {
        metadataInspector = plugin.getMetadataInspector();
    }else{
        addUIComponents = false;
    }
    //if the product does not support Advanced option action
    if (addUIComponents && metadataInspector == null) {
        int confirm = JOptionPane.showConfirmDialog(null, "The reader does not support the advanced options!\nDo you want to open the product normally?", null, JOptionPane.YES_NO_OPTION);
        //if the user want to open the product normally the Advanced Options window will not be displayed
        if (confirm == JOptionPane.YES_OPTION) {
            addUIComponents = false;
            approveSelection();
        } else {//if the user choose not to open the product normally the Advanced Option window components are removed
            addUIComponents = false;
        }
    }
    if (addUIComponents) {
        boolean approve = openAdvancedProduct(metadataInspector, inputFile);
        if (approve && getDialogType() == JFileChooser.OPEN_DIALOG) {
            approveSelection();
        }
        updateState();
    }else if(plugin == null && !canceled){
        Dialogs.showError(Bundle.LBL_NoReaderFoundText() + String.format("%nFile '%s' can not be opened.", inputFile));
    }
}