gnu.trove.map.TObjectIntMap Java Examples
The following examples show how to use
gnu.trove.map.TObjectIntMap.
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: ToJdbcPragmaTransform.java From CQL with GNU Affero General Public License v3.0 | 6 votes |
@Override public void execute() { try { Connection conn = DriverManager.getConnection(jdbcString); deleteThenCreate(conn); int s1 = (int) options1.getOrDefault(AqlOption.start_ids_at); int s2 = (int) options2.getOrDefault(AqlOption.start_ids_at); Pair<TObjectIntMap<X1>, TIntObjectMap<X1>> I = h.src().algebra().intifyX(s1); Pair<TObjectIntMap<X2>, TIntObjectMap<X2>> J = h.dst().algebra().intifyX(s2); for (En en : h.src().schema().ens) { for (X1 x : h.src().algebra().en(en)) { storeMyRecord(I, J, conn, x, prefix + enToString(en), en); } } conn.close(); } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
Example #2
Source File: TokenNGramsWithGlobalWeights.java From JedAIToolkit with Apache License 2.0 | 6 votes |
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 #3
Source File: TokenNGramsWithGlobalWeights.java From JedAIToolkit with Apache License 2.0 | 6 votes |
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 #4
Source File: TokenNGramsWithGlobalWeights.java From JedAIToolkit with Apache License 2.0 | 6 votes |
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 #5
Source File: CharacterNGramsWithGlobalWeights.java From JedAIToolkit with Apache License 2.0 | 6 votes |
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 #6
Source File: CharacterNGramsWithGlobalWeights.java From JedAIToolkit with Apache License 2.0 | 6 votes |
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 #7
Source File: CharacterNGramsWithGlobalWeights.java From JedAIToolkit with Apache License 2.0 | 6 votes |
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 #8
Source File: BagModel.java From JedAIToolkit with Apache License 2.0 | 6 votes |
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 #9
Source File: BagModel.java From JedAIToolkit with Apache License 2.0 | 6 votes |
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 #10
Source File: AbstractAttributeClustering.java From JedAIToolkit with Apache License 2.0 | 6 votes |
protected AttributeClusters clusterAttributes(int datasetId, ConnectedComponents cc) { int firstId = datasetId == DATASET_1 ? 0 : attributesDelimiter; int lastId = 0 < attributesDelimiter && datasetId == DATASET_1 ? attributesDelimiter : noOfAttributes; int glueClusterId = cc.count() + 1; int[] clusterFrequency = new int[glueClusterId + 1]; float[] clusterEntropy = new float[glueClusterId + 1]; final TObjectIntMap<String> clusters = new TObjectIntHashMap<>(); for (int i = firstId; i < lastId; i++) { int ccId = cc.id(i); if (cc.size(i) == 1) { // singleton attribute ccId = glueClusterId; } clusterFrequency[ccId]++; clusterEntropy[ccId] += attributeModels[datasetId][i].getEntropy(true); clusters.put(attributeModels[datasetId][i].getInstanceName(), ccId); } for (int i = 0; i < glueClusterId + 1; i++) { clusterEntropy[i] /= clusterFrequency[i]; } return new AttributeClusters(clusterEntropy, clusters); }
Example #11
Source File: ToJdbcPragmaTransform.java From CQL with GNU Affero General Public License v3.0 | 6 votes |
private void storeMyRecord(Pair<TObjectIntMap<X1>, TIntObjectMap<X1>> i, Pair<TObjectIntMap<X2>, TIntObjectMap<X2>> j, Connection conn, X1 x, String table, En en) throws Exception { List<String> hdrQ = new LinkedList<>(); List<String> hdr = new LinkedList<>(); hdr.add("src" + idCol); hdr.add("dst" + idCol); hdrQ.add("?"); hdrQ.add("?"); String insertSQL = "INSERT INTO " + table + "(" + Util.sep(hdr, ",") + ") values (" + Util.sep(hdrQ, ",") + ")"; PreparedStatement ps = conn.prepareStatement(insertSQL); ps.setObject(1, i.first.get(x), colTy0); ps.setObject(2, j.first.get(h.repr(en, x)), colTy0); ps.executeUpdate(); ps.close(); }
Example #12
Source File: Utils.java From apkfile with Apache License 2.0 | 5 votes |
public static void updateAccessorCounts(TObjectIntMap<String> counts, int[] accessFlags) { for (int accessFlag : accessFlags) { if (Modifier.isPublic(accessFlag)) { counts.adjustOrPutValue("public", 1, 1); } if (Modifier.isProtected(accessFlag)) { counts.adjustOrPutValue("protected", 1, 1); } if (Modifier.isPrivate(accessFlag)) { counts.adjustOrPutValue("private", 1, 1); } if (Modifier.isFinal(accessFlag)) { counts.adjustOrPutValue("final", 1, 1); } if (Modifier.isInterface(accessFlag)) { counts.adjustOrPutValue("interface", 1, 1); } if (Modifier.isNative(accessFlag)) { counts.adjustOrPutValue("native", 1, 1); } if (Modifier.isStatic(accessFlag)) { counts.adjustOrPutValue("static", 1, 1); } if (Modifier.isStrict(accessFlag)) { counts.adjustOrPutValue("strict", 1, 1); } if (Modifier.isSynchronized(accessFlag)) { counts.adjustOrPutValue("synchronized", 1, 1); } if (Modifier.isTransient(accessFlag)) { counts.adjustOrPutValue("transient", 1, 1); } if (Modifier.isVolatile(accessFlag)) { counts.adjustOrPutValue("volatile", 1, 1); } if (Modifier.isAbstract(accessFlag)) { counts.adjustOrPutValue("abstract", 1, 1); } } }
Example #13
Source File: CreateTests.java From morpheus-core with Apache License 2.0 | 5 votes |
@Test() public void testMapCreateTest() { final long t1 = System.nanoTime(); final TObjectIntMap<String> map1 = new TObjectIntHashMap<>(5000000, 0.8f, -1); final long t2 = System.nanoTime(); final TLongIntMap map2 = new TLongIntHashMap(); final long t3 = System.nanoTime(); System.out.println("Map1:" + ((t2-t1)/1000000d) + " Map2:" + ((t3-t2)/100000d)); }
Example #14
Source File: Utils.java From apkfile with Apache License 2.0 | 5 votes |
public static Map<Object, Integer> convertToJava(TObjectIntMap map) { Map<Object, Integer> javaMap = new HashMap<>(); for (Object key : map.keySet()) { javaMap.put(key, map.get(key)); } return javaMap; }
Example #15
Source File: FuzzySetSimJoin.java From JedAIToolkit with Apache License 2.0 | 5 votes |
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 #16
Source File: UpgradeKilling.java From BetterChests with GNU Lesser General Public License v3.0 | 5 votes |
@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 #17
Source File: TroveObjectIntMapTest.java From hashmapTest with The Unlicense | 5 votes |
@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(); }
Example #18
Source File: TroveObjectIntMapTest.java From hashmapTest with The Unlicense | 5 votes |
@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 #19
Source File: Algebra.java From CQL with GNU Affero General Public License v3.0 | 5 votes |
/** * DO NOT close this connection */ // client should not remove public synchronized Connection addIndices(Pair<TObjectIntMap<X>, TIntObjectMap<X>> j, Map<En, List<String>> indices, int vlen) { if (conn == null) { conn = createAndLoad(indices, j, vlen); this.indicesLoaded = new LinkedList<>(); for (List<String> l : indices.values()) { this.indicesLoaded.addAll(l); } return conn; } try (Statement stmt = conn.createStatement()) { for (List<String> ss : indices.values()) { for (String s : ss) { if (!indicesLoaded.contains(s)) { stmt.execute(s); indicesLoaded.add(s); } } } stmt.close(); return conn; } catch (Exception ex) { ex.printStackTrace(); throw new RuntimeException(ex); } }
Example #20
Source File: ToCsvPragmaTransform.java From CQL with GNU Affero General Public License v3.0 | 5 votes |
@Override public void execute() { try { StringBuffer sb = new StringBuffer(); CSVPrinter printer = new CSVPrinter(sb, ToCsvPragmaInstance.getFormat(options1)); int srcId = (int) options1.getOrDefault(AqlOption.start_ids_at); int dstId = (int) options2.getOrDefault(AqlOption.start_ids_at); Pair<TObjectIntMap<X1>, TIntObjectMap<X1>> a = h.src().algebra().intifyX(srcId); Pair<TObjectIntMap<X2>, TIntObjectMap<X2>> b = h.dst().algebra().intifyX(dstId); for (En en : h.src().schema().ens) { for (X1 x1 : h.src().algebra().en(en)) { List<String> row = new LinkedList<>(); row.add(Integer.toString(a.first.get(x1))); X2 x2 = h.repr(en, x1); row.add(Integer.toString(b.first.get(x2))); printer.printRecord(row); } } printer.close(); delete(); if (!file.createNewFile()) { throw new RuntimeException("Could not create new file: " + file); } FileWriter out = new FileWriter(file); out.write(sb.toString()); out.close(); } catch (IOException e) { throw new RuntimeException(e); } }
Example #21
Source File: InvestigateString.java From systemsgenetics with GNU General Public License v3.0 | 4 votes |
/** * @param args the command line arguments * @throws java.io.FileNotFoundException */ public static void main(String[] args) throws FileNotFoundException, IOException, Exception { final File stringFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\String\\9606.protein.links.full.v10.5.txt"); final File ensgEnspFile = new File("C:\\UMCG\\Genetica\\Projects\\GeneNetwork\\ensgGeneProteinV83.txt"); HashMap<String, String> enspToEnsgMap = loadEnspToEnsgMap(ensgEnspFile); final CSVParser parser = new CSVParserBuilder().withSeparator(' ').withIgnoreQuotations(true).build(); final CSVReader sampleFileReader = new CSVReaderBuilder(new BufferedReader(new FileReader(stringFile))).withSkipLines(1).withCSVParser(parser).build(); HashSet<GenePair> observedGenePairs = new HashSet<>(); TObjectIntMap<String> geneCombinedConfidentCount = new TObjectIntHashMap<>(); TObjectIntMap<String> geneCombinedCoexpressionCount = new TObjectIntHashMap<>(); String[] nextLine; while ((nextLine = sampleFileReader.readNext()) != null) { final String protein1 = nextLine[0].substring(5); final String protein2 = nextLine[1].substring(5); final String gene1 = enspToEnsgMap.get(protein1); final String gene2 = enspToEnsgMap.get(protein2); if (gene1 == null || gene2 == null) { continue; } GenePair gene1Gene2Pair = new GenePair(gene1, gene2); if (observedGenePairs.add(gene1Gene2Pair)) { if (Integer.parseInt(nextLine[15]) >= 700) { geneCombinedConfidentCount.adjustOrPutValue(gene1, 1, 1); geneCombinedConfidentCount.adjustOrPutValue(gene2, 1, 1); } if (Integer.parseInt(nextLine[8]) >= 700) { geneCombinedCoexpressionCount.adjustOrPutValue(gene1, 1, 1); geneCombinedCoexpressionCount.adjustOrPutValue(gene2, 1, 1); } } else { // System.out.println("Observed duplicate pair"); // System.out.println(protein1); // System.out.println(protein2); // System.out.println(gene1); // System.out.println(gene2); } } System.out.println("Gene\tCoexpressionCount\tCombinedCount"); for(String gene : geneCombinedConfidentCount.keySet()){ System.out.println(gene + "\t" + geneCombinedCoexpressionCount.get(gene) + "\t" + geneCombinedConfidentCount.get(gene)) ; } System.out.println("Total unique interactions: " + observedGenePairs.size()); }
Example #22
Source File: Utils.java From apkfile with Apache License 2.0 | 4 votes |
public static void rollUp(TObjectIntMap dest, TObjectIntMap src) { for (Object key : src.keySet()) { int value = src.get(key); dest.adjustOrPutValue(key, value, value); } }
Example #23
Source File: TObjectIntHashMapTest.java From baleen with Apache License 2.0 | 4 votes |
@Test public void testPutAllTObjectIntMap() { TObjectIntMap<String> map = new gnu.trove.map.hash.TObjectIntHashMap<>(); tObjectIntHashMap.putAll(map); verify(delegate).putAll(map); }
Example #24
Source File: TObjectIntHashMap.java From baleen with Apache License 2.0 | 4 votes |
/** See {@link gnu.trove.map.hash.TObjectIntHashMap#putAll(TObjectIntMap)} */ public void putAll(TObjectIntMap<? extends K> map) { delegate.putAll(map); }
Example #25
Source File: AttributeClusters.java From JedAIToolkit with Apache License 2.0 | 4 votes |
public AttributeClusters(float[] entropy, TObjectIntMap<String> mapping) { clustersEntropy = entropy; attributeToClusterId = mapping; }
Example #26
Source File: DexMethod.java From apkfile with Apache License 2.0 | 4 votes |
public TObjectIntMap<MethodReference> getFrameworkApiCounts() { return frameworkApiCounts; }
Example #27
Source File: DexMethod.java From apkfile with Apache License 2.0 | 4 votes |
public TObjectIntMap<FieldReference> getFrameworkFieldReferenceCounts() { return frameworkFieldReferenceCounts; }
Example #28
Source File: DexMethod.java From apkfile with Apache License 2.0 | 4 votes |
public TObjectIntMap<StringReference> getStringReferenceCounts() { return stringReferenceCounts; }
Example #29
Source File: DexFile.java From apkfile with Apache License 2.0 | 4 votes |
public TObjectIntMap<String> getClassAccessorCounts() { return classAccessorCounts; }
Example #30
Source File: BagModel.java From JedAIToolkit with Apache License 2.0 | 4 votes |
public TObjectIntMap<String> getItemsFrequency() { return itemsFrequency; }