Java Code Examples for gnu.trove.map.TObjectIntMap#size()

The following examples show how to use gnu.trove.map.TObjectIntMap#size() . 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: BagModel.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected float getEnhancedJaccardSimilarity(BagModel oModel) {
    TObjectIntMap<String> itemVector1 = itemsFrequency;
    TObjectIntMap<String> itemVector2 = oModel.getItemsFrequency();
    if (itemVector2.size() < itemVector1.size()) {
        itemVector1 = oModel.getItemsFrequency();
        itemVector2 = itemsFrequency;
    }

    float numerator = 0.0f;
    for (TObjectIntIterator<String> iterator = itemVector1.iterator(); iterator.hasNext();) {
        iterator.advance();
        numerator += Math.min(iterator.value(), itemVector2.get(iterator.key()));
    }

    float denominator = noOfTotalTerms + oModel.getNoOfTotalTerms() - numerator;
    return numerator / (float)denominator;
}
 
Example 2
Source File: BagModel.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected float getTfCosineSimilarity(BagModel oModel) {
    float totalTerms2 = oModel.getNoOfTotalTerms();

    TObjectIntMap<String> itemVector1 = itemsFrequency;
    TObjectIntMap<String> itemVector2 = oModel.getItemsFrequency();
    if (itemVector2.size() < itemVector1.size()) {
        itemVector1 = oModel.getItemsFrequency();
        itemVector2 = itemsFrequency;
    }

    float numerator = 0.0f;
    for (TObjectIntIterator<String> iterator = itemVector1.iterator(); iterator.hasNext();) {
        iterator.advance();
        numerator += iterator.value() * itemVector2.get(iterator.key()) / noOfTotalTerms / totalTerms2;
    }

    float denominator = getVectorMagnitude() * oModel.getVectorMagnitude();
    return (float)(numerator / denominator);
}
 
Example 3
Source File: FuzzySetSimJoin.java    From JedAIToolkit with Apache License 2.0 5 votes vote down vote up
int[][][] transform(Map<String, List<Set<String>>> input, TObjectIntMap<String> tokenDictionary) {
    int[][][] collection = new int[input.size()][][];

    boolean existingDictionary = tokenDictionary.size() > 0;
    int unknownTokenCounter = 0;

    int i = 0, j, k;
    List<Set<String>> elements;
    for (String set : input.keySet()) {
        elements = input.get(set);
        collection[i] = new int[elements.size()][];
        j = 0;
        for (Set<String> element : elements) {
            collection[i][j] = new int[element.size()];
            k = 0;
            for (String token : element) {
                if (!tokenDictionary.containsKey(token)) {
                    if (existingDictionary) {
                        unknownTokenCounter--;
                        tokenDictionary.put(token, unknownTokenCounter);
                    } else {
                        tokenDictionary.put(token, tokenDictionary.size());
                    }
                }
                collection[i][j][k] = tokenDictionary.get(token);
                k++;
            }
            j++;
        }
        i++;
    }

    return collection;
}
 
Example 4
Source File: TroveObjectIntMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final TObjectIntMap<Integer> m_map = new TObjectIntHashMap<>( m_keys.length, m_fillFactor );
    for ( int i = 0; i < m_keys.length; ++i )
       m_map.put( m_keys[ i ], i );
    for ( int i = 0; i < m_keys2.length; ++i )
       m_map.put( m_keys2[ i ], i );
    return m_map.size();
}
 
Example 5
Source File: TroveObjectIntMapTest.java    From hashmapTest with The Unlicense 5 votes vote down vote up
@Override
public int test() {
    final TObjectIntMap<Integer> m_map = new TObjectIntHashMap<>( m_keys.length / 2 + 1, m_fillFactor );
    int add = 0, remove = 0;
    while ( add < m_keys.length )
    {
        m_map.put( m_keys[ add ], add );
        ++add;
        m_map.put( m_keys[ add ], add );
        ++add;
        m_map.remove( m_keys[ remove++ ] );
    }
    return m_map.size();
}