Java Code Examples for com.google.common.util.concurrent.AtomicDouble#doubleValue()

The following examples show how to use com.google.common.util.concurrent.AtomicDouble#doubleValue() . 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: EF_BaseDistribution_MultinomialParents.java    From toolbox with Apache License 2.0 6 votes vote down vote up
public double dotProduct(SparseVector vec) {
    AtomicDouble sum= new AtomicDouble(0);

    if (this.getNumberNonZeroEntries()<vec.getNumberNonZeroEntries()){
        this.nonZeroEntries().forEach(entry ->{
            Vector outerVector = vec.getVectorByPosition(entry.getKey());
            if (outerVector!=null)
                sum.addAndGet(outerVector.dotProduct(entry.getValue()));
        });
    }else{
        vec.nonZeroEntries().forEach(entry ->{
            Vector localVector = this.getVectorByPosition(entry.getKey());
            if (localVector!=null)
                sum.addAndGet(localVector.dotProduct(entry.getValue()));
        });
    }
    return sum.doubleValue();
}
 
Example 2
Source File: DocumentProjectionService.java    From termsuite-core with Apache License 2.0 5 votes vote down vote up
public double getProjectionScore(TerminologyService referenceTerminology) {
	AtomicDouble sum = new AtomicDouble(0);
	AtomicDouble total = new AtomicDouble(0);
	List<Term> top100 = topN(100).collect(toList());
	for(Term docTerm :top100) {
		total.addAndGet(docTerm.getSpecificity());
		int baseRank = getBaseRankInRefTermino(referenceTerminology, docTerm);
		if(baseRank > 0 && baseRank < 500)
			sum.addAndGet(docTerm.getSpecificity());
	}
	return sum.doubleValue() / total.doubleValue();
}
 
Example 3
Source File: TrainingDataLoader.java    From EasySRL with Apache License 2.0 4 votes vote down vote up
/**
 * Build a chart for the sentence using the specified supertagger beam. If the chart exceeds the maximum size, beta
 * is doubled and the parser will re-try. When the function returns, beta will contain the value of the beam used
 * for the returned chart.
 *
 */
CompressedChart parseSentence(final List<String> sentence, final AtomicDouble beta,
		final Collection<Category> rootCategories) {
	final CompressedChart compressed;

	final List<Collection<Category>> categories = new ArrayList<>();
	final List<List<ScoredCategory>> tagsForSentence = tagger.tag(InputWord.listOf(sentence));
	for (final List<ScoredCategory> tagsForWord : tagsForSentence) {
		final List<Category> tagsForWord2 = new ArrayList<>();

		final double threshold = beta.doubleValue() * Math.exp(tagsForWord.get(0).getScore());

		for (final ScoredCategory leaf : tagsForWord) {
			if (Math.exp(leaf.getScore()) < threshold) {
				break;
			}
			tagsForWord2.add(leaf.getCategory());
		}

		categories.add(tagsForWord2);
	}

	// Find set of all parses
	final ChartCell[][] chart = parser.parse(sentence, categories);

	if (chart == null) {
		if (beta.doubleValue() * 2 < 0.1 && backoff) {
			beta.set(beta.doubleValue() * 2);
			return parseSentence(sentence, beta, rootCategories);
		} else {
			return null;
		}
	}
	if (chart[0][chart.length - 1] == null || chart[0][chart.length - 1].getEntries().size() == 0) {
		return null;
	}

	compressed = CompressedChart.make(InputWord.listOf(sentence), chart, cutoffsDictionary, unaryRules,
			rootCategories);

	return compressed;
}