Java Code Examples for gnu.trove.set.hash.TIntHashSet#add()
The following examples show how to use
gnu.trove.set.hash.TIntHashSet#add() .
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: SpatialPooler.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
/** * Removes the set of columns who have never been active from the set of * active columns selected in the inhibition round. Such columns cannot * represent learned pattern and are therefore meaningless if only inference * is required. This should not be done when using a random, unlearned SP * since you would end up with no active columns. * * @param activeColumns An array containing the indices of the active columns * @return a list of columns with a chance of activation */ public int[] stripUnlearnedColumns(Connections c, int[] activeColumns) { TIntHashSet active = new TIntHashSet(activeColumns); TIntHashSet aboveZero = new TIntHashSet(); int numCols = c.getNumColumns(); double[] colDutyCycles = c.getActiveDutyCycles(); for(int i = 0;i < numCols;i++) { if(colDutyCycles[i] <= 0) { aboveZero.add(i); } } active.removeAll(aboveZero); TIntArrayList l = new TIntArrayList(active); l.sort(); return Arrays.stream(activeColumns).filter(i -> c.getActiveDutyCycles()[i] > 0).toArray(); }
Example 2
Source File: FastRandomTest.java From htm.java with GNU Affero General Public License v3.0 | 6 votes |
@Test public void testUniquenessAndDeterminance() { Random r = new FastRandom(42); TIntHashSet set = new TIntHashSet(); TIntHashSet knownExpectedRepeats = new TIntHashSet(); knownExpectedRepeats.addAll(new int[] { 9368, 149368, 193310, 194072, 202906, 241908, 249466, 266101, 276853, 289339, 293737 } ); for(int i = 0;i < 300000;i++) { int rndInt = r.nextInt(); if(set.contains(rndInt) && !knownExpectedRepeats.contains(i)) { fail(); } set.add(rndInt); } }
Example 3
Source File: Tracer.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
private void loadEntitiesMetaData() throws EntityLinkingDataAccessException { TIntHashSet entities = new TIntHashSet(); for (MentionTracer m : mentionsList) { for (EntityTracer e : m.getEntityTracers()) { entities.add(e.getEntityId()); } } entitiesMetaData = DataAccess.getEntitiesMetaData(entities.toArray()); }
Example 4
Source File: GraphConfidenceEstimator.java From ambiverse-nlu with Apache License 2.0 | 5 votes |
public Configuration(Map<Integer, Integer> mapping) { mapping_ = mapping; presentGraphNodes_ = new TIntHashSet(); flippedMentions_ = new TIntHashSet(); for (Entry<Integer, Integer> entry : mapping_.entrySet()) { presentGraphNodes_.add(entry.getKey()); presentGraphNodes_.add(entry.getValue()); } }
Example 5
Source File: SourceInfoSerializer.java From paintera with GNU General Public License v2.0 | 5 votes |
private static boolean visit( final TIntHashSet[] nodeEdgeMap, final int node, final TIntHashSet hasVisited) { if (hasVisited.contains(node)) { return true; } hasVisited.add(node); for (final TIntIterator it = nodeEdgeMap[node].iterator(); it.hasNext(); ) { final boolean foundAlreadyVisitedNode = visit(nodeEdgeMap, it.next(), hasVisited); if (foundAlreadyVisitedNode) { return foundAlreadyVisitedNode; } } return false; }
Example 6
Source File: DumpVersionTroveIntKey.java From dkpro-jwpl with Apache License 2.0 | 5 votes |
@Override public void freeAfterRevisonParsing() { pageIdRevList = new TIntHashSet(pageIdRevMap.keySet().size()); for (Integer key : pageIdRevMap.keySet()) { pageIdRevList.add(key); } pageIdRevMap.clear(); }
Example 7
Source File: DumpVersionJDKGeneric.java From dkpro-jwpl with Apache License 2.0 | 5 votes |
@Override public void freeAfterRevisonParsing() { pageIdRevList = new TIntHashSet(pageIdRevMap.keySet().size()); for (Integer key : pageIdRevMap.keySet()) { pageIdRevList.add(key); } pageIdRevMap.clear(); }
Example 8
Source File: FoxEatsDemo.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
/** * Returns a random, sorted, and unique array of the specified sample size of * selections from the specified list of choices. * * @param sampleSize the number of selections in the returned sample * @param choices the list of choices to select from * @param random a random number generator * @return a sample of numbers of the specified size */ int[] sample(int sampleSize, TIntArrayList choices, Random random) { TIntHashSet temp = new TIntHashSet(); int upperBound = choices.size(); for (int i = 0; i < sampleSize; i++) { int randomIdx = random.nextInt(upperBound); while (temp.contains(choices.get(randomIdx))) { randomIdx = random.nextInt(upperBound); } temp.add(choices.get(randomIdx)); } TIntArrayList al = new TIntArrayList(temp); al.sort(); return al.toArray(); }
Example 9
Source File: StrictHackathonAlgorithm.java From htm.java-examples with GNU Affero General Public License v3.0 | 5 votes |
/** * Returns a random, sorted, and unique array of the specified sample size of * selections from the specified list of choices. * * @param sampleSize the number of selections in the returned sample * @param choices the list of choices to select from * @param random a random number generator * @return a sample of numbers of the specified size */ int[] sample(int sampleSize, TIntArrayList choices, Random random) { TIntHashSet temp = new TIntHashSet(); int upperBound = choices.size(); for (int i = 0; i < sampleSize; i++) { int randomIdx = random.nextInt(upperBound); while (temp.contains(choices.get(randomIdx))) { randomIdx = random.nextInt(upperBound); } temp.add(choices.get(randomIdx)); } TIntArrayList al = new TIntArrayList(temp); al.sort(); return al.toArray(); }
Example 10
Source File: FastConnectionsMatrix.java From htm.java with GNU Affero General Public License v3.0 | 5 votes |
@Override public AbstractSparseBinaryMatrix set(int value, int... coordinates) { TIntHashSet input = getColumnInput(coordinates[0]); if (value == 0) { input.remove(coordinates[1]); } else { input.add(coordinates[1]); } return this; }
Example 11
Source File: FixedNodeSetsPartitioning.java From scheduler with GNU Lesser General Public License v3.0 | 5 votes |
private static boolean isDisjoint(Collection<Collection<Node>> p) { TIntHashSet all = new TIntHashSet(); for (Collection<Node> s : p) { for (Node n : s) { if (!all.add(n.id())) { return false; } } } return true; }
Example 12
Source File: DataAccessForTesting.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
@Override public Keyphrases getEntityKeyphrases(Entities entities, Map<String, Double> keyphraseSourceWeights, double minKeyphraseWeight, int maxEntityKeyphraseCount) throws EntityLinkingDataAccessException { Keyphrases keyphrases = new Keyphrases(); TIntObjectHashMap<int[]> eKps = new TIntObjectHashMap<int[]>(); TIntObjectHashMap<int[]> kpTokens = new TIntObjectHashMap<int[]>(); getEntityKeyphraseTokens(entities, eKps, kpTokens); keyphrases.setEntityKeyphrases(eKps); keyphrases.setKeyphraseTokens(kpTokens); TIntObjectHashMap<TIntDoubleHashMap> e2kw2mi = new TIntObjectHashMap<TIntDoubleHashMap>(); keyphrases.setEntityKeywordWeights(e2kw2mi); TIntObjectHashMap<TIntDoubleHashMap> e2kp2mi = new TIntObjectHashMap<TIntDoubleHashMap>(); keyphrases.setEntityKeyphraseWeights(e2kp2mi); for (Entity entity : entities) { int eId = entity.getId(); Entities singleEntity = new Entities(); singleEntity.add(entity); int entityCount = getEntitySuperdocSize(singleEntity).get(eId); TIntDoubleHashMap kp2mi = new TIntDoubleHashMap(); e2kp2mi.put(entity.getId(), kp2mi); TIntDoubleHashMap kw2mi = new TIntDoubleHashMap(); e2kw2mi.put(entity.getId(), kw2mi); if (!eKps.containsKey(eId)) { continue; } for (int kp : eKps.get(eId)) { TIntHashSet singleKp = new TIntHashSet(); singleKp.add(kp); int kpCount = getKeyphraseDocumentFrequencies(singleKp).get(kp); int eKpIcCount = getEntityKeyphraseIntersectionCount(singleEntity).get(eId).get(kp); kp2mi.put(kp, WeightComputation.computeNPMI(entityCount, kpCount, eKpIcCount, TOTAL_ENTITY_COUNT)); for (int kw : kpTokens.get(kp)) { TIntHashSet singleKw = new TIntHashSet(); singleKw.add(kw); int kwCount = getKeywordDocumentFrequencies(singleKw).get(kw); int eKwIcCount = getEntityKeywordIntersectionCount(singleEntity).get(eId).get(kw); kw2mi.put(kw, WeightComputation.computeMI(entityCount, kwCount, eKwIcCount, TOTAL_ENTITY_COUNT, false)); } } } return keyphrases; }
Example 13
Source File: DataAccessSQL.java From ambiverse-nlu with Apache License 2.0 | 4 votes |
@Override public Entities getEntitiesForMentionByFuzzyMatching(String mention, double minSimilarity, boolean isNamedEntity) throws EntityLinkingDataAccessException { Integer id = RunningTimer.recordStartTime("FuzzyEntitiesForMention"); String conflatedMention = EntityLinkingManager.conflateToken(mention, isNamedEntity); TIntHashSet entitiesIds = new TIntHashSet(); EntityType entityType; if (isNamedEntity) { entityType = EntityType.NAMED_ENTITY; } else { entityType = EntityType.CONCEPT; } Connection mentionEntityCon = null; Statement statement = null; try { mentionEntityCon = EntityLinkingManager.getConnectionForDatabase(EntityLinkingManager.DB_AIDA); statement = mentionEntityCon.createStatement(); String sql = null; String query = PostgresUtil.getPostgresEscapedString(conflatedMention); sql = "SELECT mention, entity FROM " + DICTIONARY + ", " + " WHERE mention % '" + query + "'" + " AND similarity(mention, '" + query + "') >= " + minSimilarity + " AND " + DataAccessSQL.DICTIONARY + ".entitytype=" + entityType.getDBId(); System.out.println(sql); ResultSet r = statement.executeQuery(sql); while (r.next()) { int entity = r.getInt(2); entitiesIds.add(entity); } r.close(); statement.close(); EntityLinkingManager.releaseConnection(mentionEntityCon); } catch (Exception e) { logger.error(e.getLocalizedMessage()); throw new EntityLinkingDataAccessException(e); } int[] ids = entitiesIds.toArray(); TIntObjectHashMap<KBIdentifiedEntity> yagoEntityIds = getKnowlegebaseEntitiesForInternalIds(ids); Entities entities = new Entities(); for (int i = 0; i < ids.length; ++i) { entities.add(new Entity(yagoEntityIds.get(ids[i]), ids[i])); } RunningTimer.recordEndTime("FuzzyEntitiesForMention", id); return entities; }