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

The following examples show how to use gnu.trove.map.TObjectIntMap#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: 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 2
Source File: CharacterNGramsWithGlobalWeights.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected float getSigmaSimilarity(CharacterNGramsWithGlobalWeights oModel) {
    float totalTerms2 = oModel.getNoOfTotalTerms();
    final TObjectIntMap<String> itemVector2 = oModel.getItemsFrequency();

    float numerator = 0.0f;
    for (TObjectIntIterator<String> iterator = itemsFrequency.iterator(); iterator.hasNext();) {
        iterator.advance();
        int frequency2 = itemVector2.get(iterator.key());
        if (0 < frequency2) {
            numerator += iterator.value() / noOfTotalTerms * getIdfWeight(iterator.key())
                       + frequency2 / totalTerms2 * oModel.getIdfWeight(iterator.key());
        }
    }

    final Set<String> allKeys = new HashSet<>(itemsFrequency.keySet());
    allKeys.addAll(itemVector2.keySet());
    float denominator = 0.0f;
    denominator = allKeys.stream().map((key) -> itemsFrequency.get(key) / noOfTotalTerms  * getIdfWeight(key) + 
            itemVector2.get(key) / totalTerms2 * oModel.getIdfWeight(key)).reduce(denominator, (accumulator, _item) -> accumulator + _item);

    return (float)(numerator / denominator);
}
 
Example 3
Source File: CharacterNGramsWithGlobalWeights.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected float getTfIdfCosineSimilarity(CharacterNGramsWithGlobalWeights oModel) {
    float totalTerms2 = oModel.getNoOfTotalTerms();
    final TObjectIntMap<String> itemVector2 = oModel.getItemsFrequency();

    float numerator = 0.0f;
    for (TObjectIntIterator<String> iterator = itemsFrequency.iterator(); iterator.hasNext();) {
        iterator.advance();
        int frequency2 = itemVector2.get(iterator.key());
        if (0 < frequency2) {
            numerator += (iterator.value() / noOfTotalTerms) * getIdfWeight(iterator.key())
                       * (frequency2 / totalTerms2) * oModel.getIdfWeight(iterator.key());
        }
    }

    float denominator = getVectorMagnitude() * oModel.getVectorMagnitude();
    return (float)(numerator / denominator);
}
 
Example 4
Source File: CharacterNGramsWithGlobalWeights.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected float getTfIdfGeneralizedJaccardSimilarity(CharacterNGramsWithGlobalWeights oModel) {
    float totalTerms2 = oModel.getNoOfTotalTerms();
    final TObjectIntMap<String> itemVector2 = oModel.getItemsFrequency();

    float numerator = 0.0f;
    for (TObjectIntIterator<String> iterator = itemsFrequency.iterator(); iterator.hasNext();) {
        iterator.advance();
        int frequency2 = itemVector2.get(iterator.key());
        if (0 < frequency2) {
            numerator += Math.min(iterator.value() / noOfTotalTerms * getIdfWeight(iterator.key()),
                                  frequency2 / totalTerms2 * oModel.getIdfWeight(iterator.key()));
        }
    }

    final Set<String> allKeys = new HashSet<>(itemsFrequency.keySet());
    allKeys.addAll(itemVector2.keySet());
    float denominator = 0.0f;
    denominator = allKeys.stream().map((key) -> Math.max(itemsFrequency.get(key) / noOfTotalTerms  * getIdfWeight(key),
            itemVector2.get(key) / totalTerms2 * oModel.getIdfWeight(key))).reduce(denominator, (accumulator, _item) -> accumulator + _item);

    return (float)(numerator / denominator);
}
 
Example 5
Source File: TokenNGramsWithGlobalWeights.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected float getSigmaSimilarity(TokenNGramsWithGlobalWeights oModel) {
    float totalTerms2 = oModel.getNoOfTotalTerms();
    final TObjectIntMap<String> itemVector2 = oModel.getItemsFrequency();

    float numerator = 0.0f;
    for (TObjectIntIterator<String> iterator = itemsFrequency.iterator(); iterator.hasNext();) {
        iterator.advance();
        int frequency2 = itemVector2.get(iterator.key());
        if (0 < frequency2) {
            numerator += iterator.value() / noOfTotalTerms * getIdfWeight(iterator.key())
                       + frequency2 / totalTerms2 * oModel.getIdfWeight(iterator.key());
        }
    }

    final Set<String> allKeys = new HashSet<>(itemsFrequency.keySet());
    allKeys.addAll(itemVector2.keySet());
    float denominator = 0.0f;
    denominator = allKeys.stream().map((key) -> itemsFrequency.get(key) / noOfTotalTerms  * getIdfWeight(key) + 
            itemVector2.get(key) / totalTerms2 * oModel.getIdfWeight(key)).reduce(denominator, (accumulator, _item) -> accumulator + _item);

    return (float)(numerator / denominator);
}
 
Example 6
Source File: TokenNGramsWithGlobalWeights.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected float getTfIdfCosineSimilarity(TokenNGramsWithGlobalWeights oModel) {
    float totalTerms2 = oModel.getNoOfTotalTerms();
    final TObjectIntMap<String> itemVector2 = oModel.getItemsFrequency();

    float numerator = 0.0f;
    for (TObjectIntIterator<String> iterator = itemsFrequency.iterator(); iterator.hasNext();) {
        iterator.advance();
        int frequency2 = itemVector2.get(iterator.key());
        if (0 < frequency2) {
            numerator += (iterator.value() / noOfTotalTerms) * getIdfWeight(iterator.key())
                       * (frequency2 / totalTerms2) * oModel.getIdfWeight(iterator.key());
        }
    }

    float denominator = getVectorMagnitude() * oModel.getVectorMagnitude();
    return (float)(numerator / denominator);
}
 
Example 7
Source File: TokenNGramsWithGlobalWeights.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected float getTfIdfGeneralizedJaccardSimilarity(TokenNGramsWithGlobalWeights oModel) {
    float totalTerms2 = oModel.getNoOfTotalTerms();
    final TObjectIntMap<String> itemVector2 = oModel.getItemsFrequency();

    float numerator = 0.0f;
    for (TObjectIntIterator<String> iterator = itemsFrequency.iterator(); iterator.hasNext();) {
        iterator.advance();
        int frequency2 = itemVector2.get(iterator.key());
        if (0 < frequency2) {
            numerator += Math.min(iterator.value() / noOfTotalTerms * getIdfWeight(iterator.key()),
                                  frequency2 / totalTerms2 * oModel.getIdfWeight(iterator.key()));
        }
    }

    final Set<String> allKeys = new HashSet<>(itemsFrequency.keySet());
    allKeys.addAll(itemVector2.keySet());
    float denominator = 0.0f;
    denominator = allKeys.stream().map((key) -> Math.max(itemsFrequency.get(key) / noOfTotalTerms  * getIdfWeight(key),
            itemVector2.get(key) / totalTerms2 * oModel.getIdfWeight(key))).reduce(denominator, (accumulator, _item) -> accumulator + _item);

    return (float)(numerator / denominator);
}
 
Example 8
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 9
Source File: UpgradeKilling.java    From BetterChests with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void update(IUpgradableBlock chest, ItemStack stack) {
	if (UpgradeHelper.INSTANCE.getFrequencyTick(chest, stack, 100) != 0) {
		return;
	}

	AxisAlignedBB bb = new AxisAlignedBB(chest.getPosition()).grow(RADIUS);

	TObjectIntMap<Class<? extends EntityLiving>> map = new TObjectIntHashMap<>();

	for (EntityLiving entity : chest.getWorldObj().getEntitiesWithinAABB(EntityLiving.class, bb)) {
		if (entity.isDead) {
			continue;
		}

		if (entity instanceof EntityAnimal) {
			EntityAnimal animal = (EntityAnimal) entity;
			if (entity.isChild()) {
				continue;
			}
			int currentAnimals = map.get(animal.getClass());
			if (currentAnimals < ANIMALS_TO_KEEP_ALIVE) {
				map.put(animal.getClass(), currentAnimals + 1);
				continue;
			}
		}

		if (hasUpgradeOperationCost(chest)) {
			EntityPlayer source = null;
			if (chest.isUpgradeInstalled(DummyUpgradeType.AI.getStack())) {
				source = chest.getFakePlayer();
			}
			entity.attackEntityFrom(getDamageSource(source), 10);
			drawUpgradeOperationCode(chest);
		}
	}
}
 
Example 10
Source File: Utils.java    From apkfile with Apache License 2.0 4 votes vote down vote up
public static void rollUp(TObjectIntMap dest, TObjectIntMap src) {
    for (Object key : src.keySet()) {
        int value = src.get(key);
        dest.adjustOrPutValue(key, value, value);
    }
}