Java Code Examples for gnu.trove.map.hash.TObjectDoubleHashMap#put()

The following examples show how to use gnu.trove.map.hash.TObjectDoubleHashMap#put() . 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: CollectionUtils.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
/**
 * Normalizes values so that they sum up to 1.
 *
 * @param values
 * @param <T>
 * @return Normalized values.
 */
public static <T> TObjectDoubleHashMap<T> normalizeValuesToSum(TObjectDoubleHashMap<T> values) {
  TObjectDoubleHashMap<T> normalizedScores = new TObjectDoubleHashMap<T>();
  double total = 0;
  for (TObjectDoubleIterator<T> itr = values.iterator(); itr.hasNext(); ) {
    itr.advance();
    total += itr.value();
  }
  if (total == 0) {
    return values;
  }
  for (TObjectDoubleIterator<T> itr = values.iterator(); itr.hasNext(); ) {
    itr.advance();
    Double normalizedScore = itr.value() / total;
    normalizedScores.put(itr.key(), normalizedScore);
  }
  return normalizedScores;
}
 
Example 2
Source File: RetrieverConfig.java    From cineast with MIT License 6 votes vote down vote up
public TObjectDoubleHashMap<Retriever> getRetrieversByCategory(String category){
	List<DoublePair<Class<? extends Retriever>>> list = this.retrieverCategories.get(category);
	if(list == null){
		return new TObjectDoubleHashMap<>(1);
	}

	TObjectDoubleHashMap<Retriever> _return = new TObjectDoubleHashMap<>(list.size());
	for(DoublePair<Class<? extends Retriever>> pair : list){
		Retriever rev = ReflectionHelper.instanciate(pair.key);
		if(rev != null){
			_return.put(rev, pair.value);
		}
	}

	return _return;
}
 
Example 3
Source File: LexemeCooccurrenceScorer.java    From spf with GNU General Public License v2.0 6 votes vote down vote up
protected static TObjectDoubleHashMap<String> readStats(
		BufferedReader reader) throws IOException {
	final TObjectDoubleHashMap<String> pmis = new TObjectDoubleHashMap<String>();

	String line = reader.readLine();
	while (line != null) { // for each line in the file
		line = line.trim();
		if (!line.equals("")) {
			final String[] tokens = line.split("..\\:\\:..");
			final String id = tokens[0] + "  ::  " + tokens[1];
			final double score = Double.parseDouble(tokens[2]);
			pmis.put(id, new Double(score));
		}
		line = reader.readLine();
	}

	return pmis;
}
 
Example 4
Source File: SimpleEstimationContext.java    From rheem with Apache License 2.0 5 votes vote down vote up
@Override
public SimpleEstimationContext deserialize(JSONObject json, Class<? extends SimpleEstimationContext> cls) {
    final List<CardinalityEstimate> inCards = JsonSerializables.deserializeAllAsList(
            json.getJSONArray("inCards"),
            CardinalityEstimate.class
    );
    final List<CardinalityEstimate> outCards = JsonSerializables.deserializeAllAsList(
            json.getJSONArray("outCards"),
            CardinalityEstimate.class
    );

    final TObjectDoubleHashMap<String> doubleProperties = new TObjectDoubleHashMap<>();
    final JSONObject doublePropertiesJson = json.optJSONObject("properties");
    if (doublePropertiesJson != null) {
        for (String key : doublePropertiesJson.keySet()) {
            doubleProperties.put(key, doublePropertiesJson.getDouble(key));
        }
    }

    final int numExecutions = json.getInt("executions");

    return new SimpleEstimationContext(
            inCards.toArray(new CardinalityEstimate[inCards.size()]),
            outCards.toArray(new CardinalityEstimate[outCards.size()]),
            doubleProperties,
            numExecutions
    );
}
 
Example 5
Source File: ContinuousRetrievalLogic.java    From cineast with MIT License 5 votes vote down vote up
public static List<SegmentScoreElement> retrieveByRetriever(QueryContainer qc,
    Retriever retriever,
    ReadableQueryConfig config) {
  TObjectDoubleHashMap<Retriever> map = new TObjectDoubleHashMap<>();
  map.put(retriever, 1d);
  return ContinuousQueryDispatcher.retrieve(qc, map, API.getInitializer(), config);
}
 
Example 6
Source File: ContinuousRetrievalLogic.java    From cineast with MIT License 4 votes vote down vote up
public static List<SegmentScoreElement> retrieveByRetriever(String id, Retriever retriever,
    ReadableQueryConfig config) {
  TObjectDoubleHashMap<Retriever> map = new TObjectDoubleHashMap<>();
  map.put(retriever, 1d);
  return ContinuousQueryDispatcher.retrieve(id, map, API.getInitializer(), config);
}