gnu.trove.set.hash.TIntHashSet Java Examples

The following examples show how to use gnu.trove.set.hash.TIntHashSet. 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: FastRandomTest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@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 #2
Source File: DumpVersionJDKGeneric.java    From dkpro-jwpl with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Timestamp timestamp) {
	this.timestamp = Revision.compressTime(timestamp.getTime());

	/**
	 * filled in revisions
	 */
	pageIdRevMap = new HashMap<Integer, Long>();
	textIdPageIdMap = new TIntIntHashMap();

	/**
	 * filled in pages
	 */
	pPageIdNameMap = new HashMap<Integer, String>();
	pNamePageIdMap = new HashMap<KeyType, Integer>();

	cNamePageIdMap = new HashMap<KeyType, Integer>();
	rPageIdNameMap = new HashMap<Integer, String>();

	/**
	 * filled in categories
	 */
	disambiguations = new TIntHashSet();
}
 
Example #3
Source File: ExtendedSortedNeighborhoodBlocking.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
@Override
protected void parseIndex() {
    final Set<String> blockingKeysSet = invertedIndexD1.keySet();
    final String[] sortedTerms = blockingKeysSet.toArray(new String[0]);
    Arrays.sort(sortedTerms);

    //slide window over the sorted list of blocking keys
    int upperLimit = sortedTerms.length - windowSize;
    for (int i = 0; i <= upperLimit; i++) {
        final TIntSet entityIds = new TIntHashSet();
        for (int j = 0; j < windowSize; j++) {
            entityIds.addAll(invertedIndexD1.get(sortedTerms[i + j]));
        }

        if (1 < entityIds.size()) {
            blocks.add(new UnilateralBlock(entityIds.toArray()));
        }
    }
}
 
Example #4
Source File: GraphTracer.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private TIntObjectHashMap<EntityMetaData> loadEntitiesMetaData(String docId) throws EntityLinkingDataAccessException {
  List<String> mentions = new LinkedList<String>(docMentionCandidatesOriginalMap.get(docId).keySet());
  Map<String, List<TracingEntity>> mentionCandidatesOriginalMap = docMentionCandidatesOriginalMap.get(docId);

  TIntSet entities = new TIntHashSet();

  for (String mention : mentions) {
    List<TracingEntity> allCandidites = mentionCandidatesOriginalMap.get(mention);
    for (TracingEntity te : allCandidites) {
      entities.add(te.entityId);
      for (int e : te.connectedEntities.keySet()) {
        entities.add(e);
      }
    }
  }
  return DataAccess.getEntitiesMetaData(entities.toArray());
}
 
Example #5
Source File: PerformInteractionAnalysisPermutationTask.java    From systemsgenetics with GNU General Public License v3.0 6 votes vote down vote up
public PerformInteractionAnalysisPermutationTask(ExpressionDataset datasetGenotypes, ExpressionDataset datasetExpression, ExpressionDataset datasetCovariates, ExpressionDataset datasetCovariatesPCAForceNormal, int covToTest, SkippedInteractionWriter skippedWriter, final TIntHashSet snpsToTest) {
	this.datasetGenotypes = datasetGenotypes;
	this.datasetExpression = datasetExpression;
	this.datasetCovariates = datasetCovariates;
	this.datasetCovariatesPCAForceNormal = datasetCovariatesPCAForceNormal;
	this.covToTest = covToTest;
	this.nrSamples = datasetGenotypes.nrSamples;
	this.skippedTracker = new SkippedInteractionTracker(datasetCovariates.probeNames[covToTest]);
	this.skippedWriter = skippedWriter;
	this.snpsToTest = snpsToTest;

	this.regression = new org.apache.commons.math3.stat.regression.OLSMultipleLinearRegression();
	cern.jet.random.tdouble.engine.DoubleRandomEngine randomEngine = new cern.jet.random.tdouble.engine.DRand();
	this.tDistColt = new cern.jet.random.tdouble.StudentT(this.nrSamples - 4, randomEngine);

}
 
Example #6
Source File: DumpVersionTroveIntKey.java    From dkpro-jwpl with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Timestamp timestamp) {
	this.timestamp = Revision.compressTime(timestamp.getTime());

	/**
	 * filled in revisions
	 */
	pageIdRevMap = new HashMap<Integer, Long>();
	textIdPageIdMap = new TIntIntHashMap();

	/**
	 * filled in pages
	 */
	pPageIdNameMap = new HashMap<Integer, String>();
	pNamePageIdMap = new TIntIntHashMap();

	cNamePageIdMap = new TIntIntHashMap();
	rPageIdNameMap = new HashMap<Integer, String>();

	/**
	 * filled in categories
	 */
	disambiguations = new TIntHashSet();
}
 
Example #7
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
@Override public TIntIntHashMap getKeyphraseDocumentFrequencies(TIntHashSet keyphrases) throws EntityLinkingDataAccessException {
  TIntIntHashMap freqs = new TIntIntHashMap();
  for (String[] kpF : allKeyphraseFrequencies) {
    int keyphrase = DataAccess.getIdForWord(kpF[0]);
    int freq = Integer.parseInt(kpF[1]);
    freqs.put(keyphrase, freq);
  }

  for (int kp : keyphrases.toArray()) {
    if (!freqs.containsKey(kp)) {
      System.err.println("allKeyphraseFrequencies does not contain '" + DataAccess.getWordForId(kp) + "'");
    }
  }

  return freqs;
}
 
Example #8
Source File: DataAccessForTesting.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
private TIntIntHashMap getKeywordDocumentFrequencies(TIntHashSet keywords) throws EntityLinkingDataAccessException {
  TIntIntHashMap freqs = new TIntIntHashMap();
  for (String[] kpF : allKeyphraseFrequencies) {
    String[] tokens = kpF[0].split(" ");
    int freq = Integer.parseInt(kpF[1]);
    for (String token : tokens) {
      freqs.put(DataAccess.getIdForWord(token), freq);
    }
  }

  for (int kw : keywords.toArray()) {
    if (!freqs.containsKey(kw)) {
      System.err.println("allKeyphraseFrequencies do not contain token '" + DataAccess.getWordForId(kw) + "'");
    }
  }

  return freqs;
}
 
Example #9
Source File: GraphConfidenceEstimator.java    From ambiverse-nlu with Apache License 2.0 6 votes vote down vote up
/**
 * Will return numElements integers from the input elements. If numElements
 * is larger than elements.size(), everything will be returned.
 *
 * @param elements    Elements to choose from.
 * @param numElements Number of elements to choose.
 * @return numElement random integers from elements.
 */
private TIntSet getRandomElements(TIntSet elements, int numElements) {
  TIntList source = new TIntArrayList(elements.toArray());
  TIntSet randomElements = new TIntHashSet();
  for (int i = 0; i < numElements; ++i) {
    if (source.size() == 0) {
      break;
    }
    // TODO: this is not efficient, as deleting from the ArrayList
    // will copy ... make this more efficient when necessary.
    int elementPosition = random_.nextInt(source.size());
    int element = source.get(elementPosition);
    source.remove(element);
    randomElements.add(element);
  }
  return randomElements;
}
 
Example #10
Source File: SpatialPoolerTest.java    From htm.java with GNU Affero General Public License v3.0 6 votes vote down vote up
@Test
public void testMapPotential1Column1Input() {
    setupParameters();
    parameters.setInputDimensions(new int[] { 1 });
    parameters.setColumnDimensions(new int[] { 1 });
    parameters.setPotentialRadius(2);
    parameters.setPotentialPct(1);
    parameters.set(KEY.WRAP_AROUND, false);
    initSP();

    //Test without wrapAround and potentialPct = 1
    int[] expectedMask = new int[] { 0 }; 
    int[] mask = sp.mapPotential(mem, 0, false);
    TIntHashSet trueIndices = new TIntHashSet(expectedMask);
    TIntHashSet maskSet = new TIntHashSet(mask);
    // The *position* of the one "on" bit expected. 
    // Python version returns [1] which is the on bit in the zero'th position
    assertTrue(trueIndices.equals(maskSet));
}
 
Example #11
Source File: Smooth.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
private static boolean isBoundary(
		final ArrayList<TIntHashSet> vertexTriangleLUT,
		final ArrayList<TIntHashSet> edgeSets,
		final int vertexIndex)
{
	final TIntHashSet vertexTriangles = vertexTriangleLUT.get(vertexIndex);
	final TIntHashSet copy            = new TIntHashSet();
	return edgeSets.get(vertexIndex).forEach(edge ->
	{
		copy.clear();
		copy.addAll(vertexTriangles);
		copy.retainAll(vertexTriangleLUT.get(edge));
		return copy.size() < 2;

	});
}
 
Example #12
Source File: Convert.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Convert vertex to triangle and triangle to vertex lookups into a vertex to vertex lookup of all edges.
 *
 * @param vertexTriangleLUT vertexTriangleLUT
 * @param triangleVertexLUT triangleVertexLUT
 *
 * @return vertex to edge lookup
 */
public static ArrayList<TIntHashSet> convertToEdgeSets(
		final ArrayList<TIntHashSet> vertexTriangleLUT,
		final ArrayList<TIntArrayList> triangleVertexLUT)
{
	final ArrayList<TIntHashSet> vertexEdgeLUT = new ArrayList<>();
	for (int vertexIndex = 0; vertexIndex < vertexTriangleLUT.size(); ++vertexIndex)
	{
		final int         fVertexIndex = vertexIndex;
		final TIntHashSet edges        = new TIntHashSet();
		vertexEdgeLUT.add(edges);
		final int[] triangles = vertexTriangleLUT.get(vertexIndex).toArray();
		for (int i = 0; i < triangles.length; ++i)
		{
			final TIntArrayList vertices = triangleVertexLUT.get(triangles[i]);
			vertices.forEach(vertex -> {
				if (vertex != fVertexIndex)
					edges.add(vertex);
				return true;
			});
		}
	}
	return vertexEdgeLUT;
}
 
Example #13
Source File: GraphUtil.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
/**
 * Remove from the {@param graph} vertices which are not connected to any edge,
 * and which have no associated object.
 */
public static <V, E> void removeIsolatedVertices(UndirectedGraph<V, E> graph) {
    Objects.requireNonNull(graph, "Graph is null.");

    TIntSet connectedVertices = new TIntHashSet();
    for (int e : graph.getEdges()) {
        connectedVertices.add(graph.getEdgeVertex1(e));
        connectedVertices.add(graph.getEdgeVertex2(e));
    }

    for (int v : graph.getVertices()) {
        if (!connectedVertices.contains(v) && graph.getVertexObject(v) == null) {
            graph.removeVertex(v);
        }
    }
}
 
Example #14
Source File: AbstractNodeBreakerInternalConnectionsTest.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
private InternalConnections findInternalConnections(VoltageLevel vl) {
    InternalConnections cs = new InternalConnections();

    VoltageLevel.NodeBreakerView topo = vl.getNodeBreakerView();
    int[] nodes = topo.getNodes();
    final TIntSet explored = new TIntHashSet();
    for (int n : nodes) {
        if (explored.contains(n)) {
            continue;
        }
        explored.add(n);
        topo.traverse(n, (n1, sw, n2) -> {
            explored.add(n2);
            if (sw == null) {
                cs.add(n1, n2);
            }
            return true;
        });
    }
    return cs;
}
 
Example #15
Source File: SimilaritySlow.java    From fnlp with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void feature(){
	features = new TIntHashSet[docs.size()];

	StringFeatureAlphabet fa = new StringFeatureAlphabet(); 

	for(int i=0;i<docs.size();i++){
		Set<String> set = FingerPrint.featureset(docs.get(i).content,type);
		features[i] = new TIntHashSet(set.size());
		Iterator<String> it = set.iterator();
		while(it.hasNext()){
			String str = it.next();				
			int idx = fa.lookupIndex(str);
			features[i].add(idx);
		}			
	}
	group();
}
 
Example #16
Source File: CutClustering.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
@Override
protected EquivalenceCluster[] getConnectedComponents() {
    // get connected components
    final ConnectivityInspector ci = new ConnectivityInspector(duplicatesGraph);
    final List<Set<Integer>> connectedComponents = ci.connectedSets();

    // prepare output
    int counter = 0;
    final EquivalenceCluster[] equivalenceClusters = new EquivalenceCluster[connectedComponents.size()];
    for (Set<Integer> componentIds : connectedComponents) {
        equivalenceClusters[counter] = new EquivalenceCluster();
        equivalenceClusters[counter++].loadBulkEntityIdsD1(new TIntHashSet(componentIds));
    }

    return equivalenceClusters;
}
 
Example #17
Source File: DenseArrayOfInts.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Override
public final Array<Integer> distinct(int limit) {
    final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
    final TIntSet set = new TIntHashSet(capacity);
    final ArrayBuilder<Integer> builder = ArrayBuilder.of(capacity, Integer.class);
    for (int i=0; i<length(); ++i) {
        final int value = getInt(i);
        if (set.add(value)) {
            builder.addInt(value);
            if (set.size() >= limit) {
                break;
            }
        }
    }
    return builder.toArray();
}
 
Example #18
Source File: MappedArrayWithIntCoding.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Override
public Array<T> distinct(int limit) {
    final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
    final TIntSet set = new TIntHashSet(capacity);
    final ArrayBuilder<T> builder = ArrayBuilder.of(capacity, type());
    for (int i=0; i<length(); ++i) {
        final int code = getInt(i);
        if (set.add(code)) {
            final T value = getValue(i);
            builder.add(value);
            if (set.size() >= limit) {
                break;
            }
        }
    }
    return builder.toArray();
}
 
Example #19
Source File: MappedArrayOfInts.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Override
public final Array<Integer> distinct(int limit) {
    final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
    final TIntSet set = new TIntHashSet(capacity);
    final ArrayBuilder<Integer> builder = ArrayBuilder.of(capacity, Integer.class);
    for (int i=0; i<length(); ++i) {
        final int value = getInt(i);
        if (set.add(value)) {
            builder.addInt(value);
            if (set.size() >= limit) {
                break;
            }
        }
    }
    return builder.toArray();
}
 
Example #20
Source File: SparseArrayWithIntCoding.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Override
public Array<T> distinct(int limit) {
    final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
    final TIntSet set = new TIntHashSet(capacity);
    final ArrayBuilder<T> builder = ArrayBuilder.of(capacity, type());
    for (int i=0; i<length(); ++i) {
        final int code = getInt(i);
        if (set.add(code)) {
            final T value = getValue(i);
            builder.add(value);
            if (set.size() >= limit) {
                break;
            }
        }
    }
    return builder.toArray();
}
 
Example #21
Source File: SparseArrayOfInts.java    From morpheus-core with Apache License 2.0 6 votes vote down vote up
@Override
public final Array<Integer> distinct(int limit) {
    final int capacity = limit < Integer.MAX_VALUE ? limit : 100;
    final TIntSet set = new TIntHashSet(capacity);
    final ArrayBuilder<Integer> builder = ArrayBuilder.of(capacity, Integer.class);
    for (int i=0; i<length(); ++i) {
        final int value = getInt(i);
        if (set.add(value)) {
            builder.addInt(value);
            if (set.size() >= limit) {
                break;
            }
        }
    }
    return builder.toArray();
}
 
Example #22
Source File: AbstractAttributeClustering.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected void compareAttributes() {
    globalMaxSimilarities = new float[noOfAttributes];
    final TIntSet coOccurringAttrs = new TIntHashSet();
    int lastId = 0 < attributesDelimiter ? attributesDelimiter : noOfAttributes;
    for (int i = 0; i < lastId; i++) {
        coOccurringAttrs.clear();

        final Set<String> signatures = attributeModels[DATASET_1][i].getSignatures();
        for (String signature : signatures) {
            final TIntList attrIds = invertedIndex.get(signature);
            if (attrIds == null) {
                continue;
            }
            coOccurringAttrs.addAll(attrIds);
        }

        if (0 < attributesDelimiter) { // Clean-Clean ER
            executeCleanCleanErComparisons(i, coOccurringAttrs);
        } else { // Dirty ER
            executeDirtyErComparisons(i, coOccurringAttrs);
        }
    }
}
 
Example #23
Source File: AbstractMetablocking.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected void setStatistics() {
    distinctComparisons = 0;
    comparisonsPerEntity = new float[noOfEntities];
    final TIntSet distinctNeighbors = new TIntHashSet();
    for (int i = 0; i < noOfEntities; i++) {
        final int[] associatedBlocks = entityIndex.getEntityBlocks(i, 0);
        if (associatedBlocks.length != 0) {
            distinctNeighbors.clear();
            for (int blockIndex : associatedBlocks) {
                for (int neighborId : getNeighborEntities(blockIndex, i)) {
                    distinctNeighbors.add(neighborId);
                }
            }
            comparisonsPerEntity[i] = distinctNeighbors.size();
            if (!cleanCleanER) {
                comparisonsPerEntity[i]--;
            }
            distinctComparisons += comparisonsPerEntity[i];
        }
    }
    distinctComparisons /= 2;
}
 
Example #24
Source File: Cluster.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public static Cluster minus(Cluster c1, Cluster cNot) {
	if (cNot.size() < 1)
		return c1;

	TIntHashSet set = new TIntHashSet(cNot.array);

	Cluster cNew2 = new Cluster();
	TIntIterator iterOld = c1.iterator();
	while (iterOld.hasNext()) {
		int nextOld = iterOld.next();
		if (!set.contains(nextOld)) {
			cNew2.add(nextOld);
		}
	}
	return cNew2;
}
 
Example #25
Source File: AgreeSets.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public AgreeSets(MaximalEquivalenceClasses maximalEquivalenceClasses, EquivalenceClasses equivalenceClasses, int numberOfColumns, int numberOfRows) {
		TIntHashSet[] comparedCouples = new TIntHashSet[numberOfRows];
		for (int i = 0; i < comparedCouples.length; i++) {
			comparedCouples[i] = new TIntHashSet();
		}
		for (TEquivalence equivalenceGroup : maximalEquivalenceClasses) {
			int[] equivalenceGroupArray = equivalenceGroup.toArray();
			// generate all 2-tuples based on the current equivalence class
			for (int outerIndex = 0; outerIndex < equivalenceGroup.size()-1; outerIndex++) {
				for (int innerIndex = outerIndex+1; innerIndex < equivalenceGroup.size(); innerIndex++) {
					
					// make sure that you don't check the same couples more than one time
					// needs too much space for most datasets
//					if (!comparedCouples[outerIndex].contains(innerIndex)) {
//						comparedCouples[outerIndex].add(innerIndex);
//					
						// create a couple consisting of tuple t and tuple t'
						EquivalenceClass equivalenceClassTupleT = equivalenceClasses.get(equivalenceGroupArray[outerIndex]);
						EquivalenceClass equivalenceClassTupleTPrime = equivalenceClasses.get(equivalenceGroupArray[innerIndex]);
						AgreeSet agreeSet = new AgreeSet(equivalenceClassTupleT, equivalenceClassTupleTPrime, numberOfColumns);
						this.add(agreeSet);
//					}
				}
			}
		}
	}
 
Example #26
Source File: AbstractNodeBreakerInternalConnectionsTest.java    From powsybl-core with Mozilla Public License 2.0 6 votes vote down vote up
private InternalConnections findInternalConnectionsTraverseStoppingAtTerminals(VoltageLevel vl) {
    InternalConnections cs = new InternalConnections();

    VoltageLevel.NodeBreakerView topo = vl.getNodeBreakerView();
    int[] nodes = topo.getNodes();
    final TIntSet explored = new TIntHashSet();
    for (int n : nodes) {
        if (explored.contains(n) || topo.getTerminal(n) == null) {
            continue;
        }
        explored.add(n);
        topo.traverse(n, (n1, sw, n2) -> {
            explored.add(n2);
            if (sw == null) {
                cs.add(n1, n2);
            }
            return topo.getTerminal(n2) == null;
        });
    }
    return cs;
}
 
Example #27
Source File: FoxEatsDemo.java    From htm.java-examples with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 #28
Source File: DumpVersionJDKGeneric.java    From dkpro-jwpl with Apache License 2.0 5 votes vote down vote up
@Override
public void freeAfterRevisonParsing() {
	pageIdRevList = new TIntHashSet(pageIdRevMap.keySet().size());
	for (Integer key : pageIdRevMap.keySet()) {
		pageIdRevList.add(key);
	}

	pageIdRevMap.clear();
}
 
Example #29
Source File: WeightedOverlap.java    From ADW with GNU General Public License v3.0 5 votes vote down vote up
public double compare(SemSig v1, SemSig v2, boolean sortedNormalized) 
{
           TIntSet overlap = new TIntHashSet(v1.getVector().keySet());
           overlap.retainAll(v2.getVector().keySet());
           return compare(overlap,
                          v1.getSortedIndices(),
                          v2.getSortedIndices());
}
 
Example #30
Source File: SDRCategoryEncoder.java    From htm.java with GNU Affero General Public License v3.0 5 votes vote down vote up
private int[] getSortedSample(final int populationSize, final int sampleLength) {
    TIntSet resultSet = new TIntHashSet();
    while (resultSet.size() < sampleLength) {
        resultSet.add(random.nextInt(populationSize));
    }
    int[] result = resultSet.toArray();
    Arrays.sort(result);
    return result;
}