Java Code Examples for gnu.trove.TIntDoubleHashMap#put()

The following examples show how to use gnu.trove.TIntDoubleHashMap#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: BaseSimilarityFunction.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
public double compute(int doc1, int doc2, IIndex index) {

        TIntDoubleHashMap ar1 = new TIntDoubleHashMap(index.getFeatureDB()
                .getFeaturesCount());
        TIntDoubleHashMap ar2 = new TIntDoubleHashMap(index.getFeatureDB()
                .getFeaturesCount());

        IIntIterator features = index.getFeatureDB().getFeatures();
        while (features.hasNext()) {
            int featID = features.next();

            ar1.put(featID,
                    index.getWeightingDB().getDocumentFeatureWeight(doc1,
                            featID));
            ar2.put(featID,
                    index.getWeightingDB().getDocumentFeatureWeight(doc2,
                            featID));
        }

        features.begin();
        return compute(ar1, ar2, features);
    }
 
Example 2
Source File: BaseSimilarityFunction.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
public double compute(int doc1, IIndex idx1, int doc2, IIndex idx2) {

        TIntDoubleHashMap ar1 = new TIntDoubleHashMap(idx1.getFeatureDB()
                .getFeaturesCount());
        TIntDoubleHashMap ar2 = new TIntDoubleHashMap(idx1.getFeatureDB()
                .getFeaturesCount());

        IIntIterator features = idx1.getFeatureDB().getFeatures();
        while (features.hasNext()) {
            int featID = features.next();

            ar1.put(featID,
                    idx1.getWeightingDB()
                            .getDocumentFeatureWeight(doc1, featID));
            ar2.put(featID,
                    idx2.getWeightingDB()
                            .getDocumentFeatureWeight(doc2, featID));
        }

        features.begin();
        return compute(ar1, ar2, features);
    }
 
Example 3
Source File: ConfidenceBased.java    From jatecs with GNU General Public License v3.0 6 votes vote down vote up
public TIntDoubleHashMap getTable() {
    TIntDoubleHashMap rank = new TIntDoubleHashMap((int) (testSize + testSize * 0.25), (float) 0.75);
    for (int docId = 0; docId < testSize; docId++) {
        Set<Entry<Short, ClassifierRangeWithScore>> entries = classification.getDocumentScoresAsSet(docId);
        Iterator<Entry<Short, ClassifierRangeWithScore>> iterator = entries.iterator();
        double sum = 0.0;
        while (iterator.hasNext()) {
            Entry<Short, ClassifierRangeWithScore> next = iterator.next();
            if (categoriesFilter.contains(next.getKey()) && docCategoriesFilter[docId].contains(next.getKey())) {
                ClassifierRangeWithScore value = next.getValue();
                sum += probability(Math.abs(value.score - value.border), next.getKey());
                //System.out.println(docId + " " + next.getKey() + " " + probability(Math.abs(value.score - value.border), next.getKey()));
                //System.out.println(next.getKey() + " " + slopes[next.getKey()] + " " + value.score);
            }
        }
        rank.put(docId, sum);
    }
    return rank;
}
 
Example 4
Source File: Clustering.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public static TIntDoubleHashMap computeDocumentCentroid(IIntIterator docs,
                                                        IIndex index) {
    TIntDoubleHashMap centroid = new TIntDoubleHashMap(index.getFeatureDB()
            .getFeaturesCount());

    int numDoc = 0;
    docs.begin();
    while (docs.hasNext()) {
        int docID = docs.next();
        IIntIterator feats = index.getContentDB()
                .getDocumentFeatures(docID);
        while (feats.hasNext()) {
            int featID = feats.next();

            centroid.put(
                    featID,
                    centroid.get(featID)
                            + index.getWeightingDB()
                            .getDocumentFeatureWeight(docID, featID));
        }

        numDoc++;
    }

    int keys[] = centroid.keys();
    for (int i = 0; i < keys.length; i++) {
        centroid.put(keys[i], centroid.get(keys[i]) / (double) numDoc);
    }

    return centroid;
}
 
Example 5
Source File: BaseSimilarityFunction.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public double compute(TIntDoubleHashMap doc1, int doc2, IIndex index) {

        TIntDoubleHashMap d2 = new TIntDoubleHashMap(index.getFeatureDB()
                .getFeaturesCount());
        IIntIterator features = index.getFeatureDB().getFeatures();
        while (features.hasNext()) {
            int featID = features.next();
            d2.put(featID,
                    index.getWeightingDB().getDocumentFeatureWeight(doc2,
                            featID));
        }

        features.begin();
        return compute(doc1, d2, features);
    }
 
Example 6
Source File: UtilityBased.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public TIntDoubleHashMap getTable(double[][] utilities) {
    TIntDoubleHashMap rank = new TIntDoubleHashMap(
            (int) (testSize + testSize * 0.25), (float) 0.75);
    for (int docId = 0; docId < testSize; docId++) {
        double sum = 0.0;
        for (TIntIterator it = categoriesFilter.iterator(); it.hasNext(); ) {
            int catId = it.next();
            if (docCategoriesFilter[docId].contains(catId)) {
                sum += utilities[docId][catMap.get(catId)];
            }
        }
        rank.put(docId, sum);
    }
    return rank;
}
 
Example 7
Source File: ConfidenceBased.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
private TIntHashSet filterByTopProbabilities(int docId, int topK) {
    TIntDoubleHashMap topProbRank = new TIntDoubleHashMap((int) (testSize + testSize * 0.25), (float) 0.75);
    Set<Entry<Short, ClassifierRangeWithScore>> entries = classification.getDocumentScoresAsSet(docId);
    Iterator<Entry<Short, ClassifierRangeWithScore>> iterator = entries.iterator();
    while (iterator.hasNext()) {
        Entry<Short, ClassifierRangeWithScore> next = iterator.next();
        if (categoriesFilter.contains(next.getKey())) {
            ClassifierRangeWithScore value = next.getValue();
            topProbRank.put(next.getKey(), probability(Math.abs(value.score - value.border), next.getKey()));
        }
    }
    Ranker r = new Ranker();
    return new TIntHashSet(r.get(topProbRank).toNativeArray(0, topK));
}
 
Example 8
Source File: Random.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public TIntDoubleHashMap getTable() {
    TIntDoubleHashMap rank = new TIntDoubleHashMap(testSize);
    for (int i = 0; i < testSize; i++) {
        rank.put(i, Math.random());
    }
    return rank;
}
 
Example 9
Source File: SparseVector.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
public SparseVector(SparseVector other) {
	_dim_value = new TIntDoubleHashMap(other.size());
	int[] dims=other._dim_value.keys();
	for(int dim:dims)
		_dim_value.put(dim, other._dim_value.get(dim));
	_k = other._k;
}
 
Example 10
Source File: BestAutomaticNegativesChooser.java    From jatecs with GNU General Public License v3.0 5 votes vote down vote up
protected TIntDoubleHashMap getDocumentAsMap(int docID, IIndex index) {
    TIntDoubleHashMap d2 = new TIntDoubleHashMap(index.getFeatureDB()
            .getFeaturesCount());
    IIntIterator features = index.getFeatureDB().getFeatures();
    while (features.hasNext()) {
        int featID = features.next();
        d2.put(featID,
                index.getWeightingDB().getDocumentFeatureWeight(docID,
                        featID));
    }

    return d2;
}
 
Example 11
Source File: TroveWeightingDB.java    From jatecs with GNU General Public License v3.0 4 votes vote down vote up
public void removeFeatures(IIntIterator removedFeatures) {
    for (int i = 0; i < _documentsWeights.size(); ++i) {
        TIntDoubleHashMap weigs = _documentsWeights.get(i);
        TIntArrayList feats = new TIntArrayList(weigs.size());
        TDoubleArrayList weigths = new TDoubleArrayList(weigs.size());
        TIntDoubleIterator wit = weigs.iterator();
        while (wit.hasNext()) {
            wit.advance();
            feats.add(wit.key());
            weigths.add(wit.value());
        }
        int j = 0;
        int shift = 0;
        int feat;
        int rem;
        if (j < feats.size() && removedFeatures.hasNext()) {
            feat = feats.getQuick(j);
            rem = removedFeatures.next();

            while (true) {
                if (feat == rem) {
                    feats.remove(j);
                    weigths.remove(j);
                    if (j < feats.size() && removedFeatures.hasNext()) {
                        feat = feats.getQuick(j);
                        rem = removedFeatures.next();
                        ++shift;
                    } else
                        break;
                } else if (feat > rem) {
                    if (removedFeatures.hasNext()) {
                        rem = removedFeatures.next();
                        ++shift;
                    } else
                        break;
                } else {
                    feats.setQuick(j, feat - shift);
                    ++j;
                    if (j < feats.size())
                        feat = feats.getQuick(j);
                    else
                        break;
                }
            }
            ++shift;
        }
        while (j < feats.size()) {
            feats.setQuick(j, feats.getQuick(j) - shift);
            ++j;
        }

        weigs.clear();
        for (j = 0; j < feats.size(); ++j)
            weigs.put(feats.getQuick(j), weigths.getQuick(j));

        removedFeatures.begin();
    }
}