Java Code Examples for gnu.trove.map.hash.TIntDoubleHashMap#get()

The following examples show how to use gnu.trove.map.hash.TIntDoubleHashMap#get() . 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: PriorProbability.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the prior probability for the given mention-entity pair.
 * If smoothing is true, it will return the lowest prior among all entities if
 * there is no real prior.
 *
 * @param mention
 * @param entity
 * @param smoothing
 * @return
 */
public double getPriorProbability(Mention mention, Entity entity, boolean smoothing) {
  Integer id = RunningTimer.recordStartTime("PriorProbability");
  TIntDoubleHashMap allMentionPriors = priors.get(mention);
  double entityPrior = allMentionPriors.get(entity.getId());

  if (smoothing && entityPrior == 0.0) {
    double smallestPrior = 1.0;

    for (TIntDoubleIterator it = allMentionPriors.iterator(); it.hasNext(); ) {
      it.advance();
      double currentPrior = it.value();
      if (currentPrior < smallestPrior) {
        smallestPrior = currentPrior;
      }
    }
    entityPrior = smallestPrior;
  }
  RunningTimer.recordEndTime("PriorProbability", id);
  return entityPrior;
}
 
Example 2
Source File: CocktailParty.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
/**
 * Get the best candidate and (normalized) score from the given entity-score map.
 *
 */
private Pair<Integer, Double> getBestLocalCandidateAndScore(TIntDoubleHashMap entityCandidates) {
  if (entityCandidates.size() == 0) {
    return new Pair<Integer, Double>(-100, 0.0);
  }
  double bestScore = -1.0;
  int bestCandidate = -10;
  for (TIntDoubleIterator itr = entityCandidates.iterator(); itr.hasNext(); ) {
    itr.advance();
    int entityId = itr.key();
    double score = itr.value();
    if (score > bestScore) {
      bestScore = score;
      bestCandidate = entityId;
    }
  }

  if (computeConfidence) {
    TIntDoubleHashMap normalizedScores = CollectionUtils.normalizeValuesToSum(entityCandidates);
    bestScore = normalizedScores.get(bestCandidate);
  }

  return new Pair<>(new Integer(bestCandidate), new Double(bestScore));
}
 
Example 3
Source File: GraphGenerator.java    From ambiverse-nlu with Apache License 2.0 5 votes vote down vote up
private double calcL1(TIntDoubleHashMap priorDistribution, TIntDoubleHashMap simDistribution) {
  double l1 = 0.0;

  for (TIntDoubleIterator itr = priorDistribution.iterator(); itr.hasNext(); ) {
    itr.advance();
    double prior = itr.value();
    double sim = simDistribution.get(itr.key());
    double diff = Math.abs(prior - sim);
    l1 += diff;
  }

  return l1;
}
 
Example 4
Source File: DataAccess.java    From ambiverse-nlu with Apache License 2.0 4 votes vote down vote up
public static double getEntityImportance(int entityId) throws EntityLinkingDataAccessException {
  int[] entitiesIds = new int[1];
  entitiesIds[0] = entityId;
  TIntDoubleHashMap results = getEntitiesImportances(entitiesIds);
  return results.get(entityId);
}