gnu.trove.iterator.TIntIterator Java Examples

The following examples show how to use gnu.trove.iterator.TIntIterator. 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: BlockFiltering.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected List<AbstractBlock> restructureUnilateraBlocks(List<AbstractBlock> blocks) {
    final List<AbstractBlock> newBlocks = new ArrayList<>();
    blocks.stream().map((block) -> (UnilateralBlock) block).forEachOrdered((oldBlock) -> {
        final TIntList retainedEntities = new TIntArrayList();
        for (int entityId : oldBlock.getEntities()) {
            if (counterD1[entityId] < limitsD1[entityId]) {
                retainedEntities.add(entityId);
            }
        }
        if (1 < retainedEntities.size()) {
            for (TIntIterator iterator = retainedEntities.iterator(); iterator.hasNext();) {
                counterD1[iterator.next()]++;
            }
            newBlocks.add(new UnilateralBlock(oldBlock.getEntropy(), retainedEntities.toArray()));
        }
    });

    return newBlocks;
}
 
Example #2
Source File: Partition.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
@Override
public String toString() {
	StringBuilder outputBuilder = new StringBuilder();
	outputBuilder.append(String.format("[%s]{", this.indices));

	for(TEquivalence equivalenceGroup : this) {
		outputBuilder.append("{");
		for (TIntIterator valueIt=equivalenceGroup.iterator(); valueIt.hasNext(); ) {
			outputBuilder.append(valueIt.next());
			outputBuilder.append(",");
		}
		outputBuilder.append("}");
	}
	outputBuilder.append("}");

	return outputBuilder.toString();
}
 
Example #3
Source File: StrippedPartition.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
@Override
	public String toString() {
		StringBuilder outputBuilder = new StringBuilder();
		outputBuilder.append("{");

		for(TEquivalence entry : this) {
			outputBuilder.append("{");
			for (TIntIterator valueIt=entry.iterator(); valueIt.hasNext(); ) {
//			for (TIntIteratorInteger value : entry) {
				outputBuilder.append(valueIt.next());
				outputBuilder.append(",");
			}
			outputBuilder.append("}");
		}
		outputBuilder.append("}");

		return outputBuilder.toString();
	}
 
Example #4
Source File: Jaccard.java    From ADW with GNU General Public License v3.0 6 votes vote down vote up
public double compare(
		TIntFloatMap v1,
		TIntFloatMap v2,
		boolean sorted) 
{
           int overlaps = 0;
	
           TIntIterator iter = v1.keySet().iterator();
           while (iter.hasNext())
           {
               int key = iter.next();
               if (v2.containsKey(key))
                   overlaps++;
           }
           
           return overlaps / (double)(v1.size() + v2.size() - overlaps);
}
 
Example #5
Source File: MaterialCounter.java    From PGM with GNU Affero General Public License v3.0 6 votes vote down vote up
public Iterable<MaterialData> materials() {
  return new Iterable<MaterialData>() {
    @Override
    public Iterator<MaterialData> iterator() {
      return new Iterator<MaterialData>() {
        final TIntIterator iter = counts.keySet().iterator();

        @Override
        public boolean hasNext() {
          return iter.hasNext();
        }

        @Override
        public MaterialData next() {
          return decodeMaterial(iter.next());
        }

        @Override
        public void remove() {
          iter.remove();
        }
      };
    }
  };
}
 
Example #6
Source File: ClusterPair.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public boolean fullCheck(List<Predicate> p, Collection<ClusterPair> newClusters) {
	TIntIterator iter = c1.iterator();
	while (iter.hasNext()) {
		int line1 = iter.next();
		Cluster newC = new Cluster();

		TIntIterator iter2 = c2.iterator();
		while (iter2.hasNext()) {
			int line2 = iter2.next();
			if (line1 != line2 && p.stream().allMatch(pr -> pr.satisfies(line1, line2))) {
				newC.add(line2);
			}
		}
		ClusterPair newPair = new ClusterPair(new Cluster(line1), newC);
		if (newPair.containsLinePair())
			newClusters.add(newPair);
	}

	return true;
}
 
Example #7
Source File: ClusterPair.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public boolean fullCheck(List<Predicate> p, Consumer<ClusterPair> consumer) {
	TIntIterator iter = c1.iterator();
	while (iter.hasNext()) {
		int line1 = iter.next();
		Cluster newC = new Cluster();

		TIntIterator iter2 = c2.iterator();
		while (iter2.hasNext()) {
			int line2 = iter2.next();
			if (line1 != line2 && p.stream().allMatch(pr -> pr.satisfies(line1, line2))) {
				newC.add(line2);
			}
		}
		ClusterPair newPair = new ClusterPair(new Cluster(line1), newC);
		if (newPair.containsLinePair())
			consumer.accept(newPair);
	}

	return true;
}
 
Example #8
Source File: ClusterPair.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
private void filter(Predicate p, int index, Consumer<ClusterPair> consumer) {
	Cluster c = index == 0 ? c1 : c2;
	boolean didRefine = false;
	Cluster newC = new Cluster();

	TIntIterator iter = c.iterator();
	while (iter.hasNext()) {
		int line = iter.next();
		if (p.satisfies(line, line))
			newC.add(line);
		else
			didRefine = true;

	}

	if (didRefine) {
		ClusterPair newPair = index == 0 ? new ClusterPair(newC, c2) : new ClusterPair(c1, newC);

		if (newPair.containsLinePair())
			consumer.accept(newPair);
	} else {
		newC = null;
		consumer.accept(this);
	}
}
 
Example #9
Source File: SortedNeighborhoodBlocking.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected int[] getMixedSortedEntities(String[] sortedTerms) {
    int datasetLimit = entityProfilesD1.size();
    final TIntList sortedEntityIds = new TIntArrayList();

    for (String blockingKey : sortedTerms) {
        final TIntList sortedIds = new TIntArrayList();
        final TIntList d1EntityIds = invertedIndexD1.get(blockingKey);
        if (d1EntityIds != null) {
            sortedIds.addAll(d1EntityIds);
        }

        final TIntList d2EntityIds = invertedIndexD2.get(blockingKey);
        if (d2EntityIds != null) {
            for (TIntIterator iterator = d2EntityIds.iterator(); iterator.hasNext();) {
                sortedIds.add(datasetLimit + iterator.next());
            }
        }

        sortedIds.shuffle(random);
        sortedEntityIds.addAll(sortedIds);
    }

    return sortedEntityIds.toArray();
}
 
Example #10
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 #11
Source File: ConnectedComponents.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
private void nonRecursiveDFS(TIntIterator[] adj, int s) {
    validateVertex(s);

    // depth-first search using an explicit stack
    final TIntStack stack = new TIntArrayStack();
    marked[s] = true;
    id[s] = count;
    size[count]++;
    stack.push(s);
    while (0 < stack.size()) {
        int v = stack.peek();
        if (adj[v].hasNext()) {
            int w = adj[v].next();
            if (!marked[w]) {
                // discovered vertex w for the first time
                marked[w] = true;
                id[w] = count;
                size[count]++;
                stack.push(w);
            }
        } else {
            stack.pop();
        }
    }
}
 
Example #12
Source File: ConnectedComponents.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
/**
 * Computes the connected components of the undirected graph {@code G}.
 *
 * @param G the undirected graph
 */
public ConnectedComponents(UndirectedGraph G) {
    marked = new boolean[G.V()];
    id = new int[G.V()];
    size = new int[G.V()];

    // to be able to iterate over each adjacency list, keeping track of which
    // vertex in each adjacency list needs to be explored next
    final TIntIterator[] adj = new TIntIterator[G.V()];
    for (int v = 0; v < G.V(); v++) {
        adj[v] = G.adj(v).iterator();
    }

    for (int v = 0; v < G.V(); v++) {
        if (!marked[v]) {
            nonRecursiveDFS(adj, v);
            count++;
        }
    }
}
 
Example #13
Source File: MaterialCounter.java    From ProjectAres with GNU Affero General Public License v3.0 6 votes vote down vote up
public Iterable<MaterialData> materials() {
    return new Iterable<MaterialData>() {
        @Override
        public Iterator<MaterialData> iterator() {
            return new Iterator<MaterialData>() {
                final TIntIterator iter = counts.keySet().iterator();

                @Override
                public boolean hasNext() {
                    return iter.hasNext();
                }

                @Override
                public MaterialData next() {
                    return decodeMaterial(iter.next());
                }

                @Override
                public void remove() {
                    iter.remove();
                }
            };
        }
    };
}
 
Example #14
Source File: Cluster.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public Map<Object, Cluster> refineBy(ParsedColumn<?> target) {
	Map<Object, Cluster> map = new HashMap<>();
	for (TIntIterator iter = array.iterator(); iter.hasNext();) {
		int line = iter.next();
		Object c = target.getValue(line);
		if (c == null)
			continue;
		if (map.containsKey(c)) {
			map.get(c).add(line);
		} else {
			Cluster p = new Cluster(line);
			map.put(c, p);
		}
	}
	return map;
}
 
Example #15
Source File: WeightedEdgePruning.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
protected void processEntity(int entityId) {
    validEntities.clear();
    flags = new int[noOfEntities];
    for (int i = 0; i < noOfEntities; i++) {
        flags[i] = -1;
    }
    
    final int[] associatedBlocks = entityIndex.getEntityBlocks(entityId, 0);
    if (associatedBlocks.length == 0) {
        return;
    }

    for (int blockIndex : associatedBlocks) {
        setNormalizedNeighborEntities(blockIndex, entityId);
        for (TIntIterator tIterator = neighbors.iterator(); tIterator.hasNext();) {
            int neighborId = tIterator.next();
            if (flags[neighborId] != entityId) {
                counters[neighborId] = 0;
                flags[neighborId] = entityId;
            }

            counters[neighborId]++;
            validEntities.add(neighborId);
        }
    }
}
 
Example #16
Source File: EntityCSVReader.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
@Override
public String getMethodConfiguration() {
    final StringBuilder sb = new StringBuilder();
    sb.append("{");
    final TIntIterator iterator = attributesToExclude.iterator();
    while (iterator.hasNext()) {
        int attributeId = iterator.next();
        sb.append(attributeId).append(",");
    }
    sb.append("}");

    return getParameterName(0) + "=" + inputFilePath + "\t"
            + getParameterName(1) + "=" + attributeNamesInFirstRow + "\t"
            + getParameterName(2) + "=" + separator + "\t"
            + getParameterName(3) + "=" + idIndex + "\t"
            + getParameterName(4) + "=" + sb.toString();
}
 
Example #17
Source File: InitialAlgebra.java    From CQL with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean saturate1() {
	boolean changed = false;
	for (Gen gen : col.gens().keySet()) {
		En en = col.gens().get(gen);
		Term<Void, En, Void, Fk, Void, Gen, Void> xx = Term.Gen(gen);
		changed = changed | add(en, xx);
	}
	for (Fk fk : col.fks().keySet()) {
		Pair<En, En> e = schema().fks.get(fk);
		TIntIterator it = ens.get(e.first).iterator();
		while (it.hasNext()) {
			int x = it.next();
			changed = changed | add(e.second, Term.Fk(fk, repr(e.first, x)));
		}
	}
	return changed;
}
 
Example #18
Source File: CardinalityNodePruning.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
@Override
protected void verifyValidEntities(int entityId) {
    if (validEntities.isEmpty()) {
        return;
    }

    topKEdges.clear();
    minimumWeight = Float.MIN_VALUE;
    for (TIntIterator iterator = validEntities.iterator(); iterator.hasNext();) {
        int neighborId = iterator.next();
        float weight = getWeight(entityId, neighborId);
        if (!(weight < minimumWeight)) {
            final Comparison comparison = new Comparison(cleanCleanER, -1, neighborId);
            comparison.setUtilityMeasure(weight);
            topKEdges.add(comparison);
            if (threshold < topKEdges.size()) {
                Comparison lastComparison = topKEdges.poll();
                minimumWeight = lastComparison.getUtilityMeasure();
            }
        }
    }

    nearestEntities[entityId] = new HashSet<>(topKEdges);
}
 
Example #19
Source File: ProgressiveCNP.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
@Override
protected void verifyValidEntities(int entityId) {
    if (validEntities.isEmpty()) {
        return;
    }

    topKEdges.clear();
    minimumWeight = Float.MIN_VALUE;
    for (TIntIterator iterator = validEntities.iterator(); iterator.hasNext();) {
        int neighborId = iterator.next();
        float weight = getWeight(entityId, neighborId);
        if (minimumWeight <= weight) {
            final Comparison comparison = getComparison(entityId, neighborId);
            comparison.setUtilityMeasure(weight);
            topKEdges.add(comparison);
            if (threshold < topKEdges.size()) {
                Comparison lastComparison = topKEdges.poll();
                minimumWeight = lastComparison.getUtilityMeasure();
            }
        }
    }
    
    topComparisons.addAll(topKEdges);
}
 
Example #20
Source File: CanopyClustering.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
@Override
protected void verifyValidEntities(int entityId) {
    nearestEntities[entityId] = new HashSet<>();
    for (TIntIterator tIterator = validEntities.iterator(); tIterator.hasNext();) {
        int neighborId = tIterator.next();
        if (excludedEntities.contains(neighborId)) {
            continue;
        }

        float weight = getWeight(entityId, neighborId);
        if (inclusiveThreshold < weight) {
            if (exclusiveThreshold < weight) {
                excludedEntities.add(neighborId);
            }
            final Comparison retainedComparison = new Comparison(cleanCleanER, -1, neighborId);
            nearestEntities[entityId].add(retainedComparison);
        }
    }
}
 
Example #21
Source File: AbstractAttributeClustering.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
private void executeDirtyErComparisons(int attributeId, TIntSet coOccurringAttrs) {
    for (TIntIterator sigIterator = coOccurringAttrs.iterator(); sigIterator.hasNext();) {
        int neighborId = sigIterator.next();
        if (neighborId <= attributeId) { // avoid repeated comparisons & comparison with attributeId
            continue;
        }

        float similarity = attributeModels[DATASET_1][attributeId].getSimilarity(attributeModels[DATASET_1][neighborId]);
        if (globalMaxSimilarities[attributeId] < similarity) {
            globalMaxSimilarities[attributeId] = similarity;
        }

        if (globalMaxSimilarities[neighborId] < similarity) {
            globalMaxSimilarities[neighborId] = similarity;
        }
    }
}
 
Example #22
Source File: ProgressiveWNP.java    From JedAIToolkit with Apache License 2.0 6 votes vote down vote up
@Override
protected void setThreshold(int entityId) {
    threshold = 0;
    int maxCompId = -1;
    float maxWeight = -1;
    for (TIntIterator iterator = validEntities.iterator(); iterator.hasNext();) {
        int neighborId = iterator.next();
        float currentWeight = getWeight(entityId, neighborId);
        if (maxWeight < currentWeight) {
            maxCompId = neighborId;
            maxWeight = currentWeight;
        }
        threshold += getWeight(entityId, neighborId);
    }
    
    if (0 <= maxCompId) {
        final Comparison currentTopComparison = getComparison(entityId, maxCompId);
        currentTopComparison.setUtilityMeasure(maxWeight);
        topComparisons.add(currentTopComparison);
        sortedEntities.add(new VertexWeight(entityId, threshold, validEntities.size(), null));
    } 
}
 
Example #23
Source File: Partition.java    From metanome-algorithms with Apache License 2.0 6 votes vote down vote up
public Collection<Partition> refineBy(int target) {
	HashMap<Cluster, Partition> map = new HashMap<Cluster, Partition>();
	for(TIntIterator iter = array.iterator(); iter.hasNext();) {
		int next = iter.next();
		Cluster c = StrippedPartition.clusters.get(next)[target];
		if(c == null) {
			continue;
		}
		if(map.containsKey(c)) {
			map.get(c).add(next);
		} else {
			Partition p = new Partition();
			p.add(next);
			map.put(c, p);
		}
	}
	return map.values();
}
 
Example #24
Source File: BinarySparseVector.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public float dotProduct(HashSparseVector sv) {
	float v =0f;
	TIntIterator it = data.iterator();			
	while(it.hasNext()){
		int i = it.next();
		v += sv.get(i);
	}
	return v;
}
 
Example #25
Source File: ProcessLinkSearchMap.java    From olca-app with Mozilla Public License 2.0 5 votes vote down vote up
private List<ProcessLink> getLinks(TIntIterator iterator) {
	List<ProcessLink> links = new ArrayList<>();
	while (iterator.hasNext()) {
		ProcessLink next = data.get(iterator.next());
		if (next != null)
			links.add(next);
	}
	return links;
}
 
Example #26
Source File: WordClusterM.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
	 * merge clusters
	 */
	public void mergeCluster() {
		maxc1 = -1;
		maxc2 = -1;
		maxL = Float.NEGATIVE_INFINITY;
		TIntIterator it1 = slots.iterator();
		
		while(it1.hasNext()){
			int i = it1.next();
			TIntIterator it2 = slots.iterator();
//			System.out.print(i+": ");
			while(it2.hasNext()){
				int j= it2.next();
				
				if(i>=j)
					continue;
//				System.out.print(j+" ");
				Multiplesolve c = new Multiplesolve(i,j);
				count.incrementAndGet();
				pool.execute(c);				
			}
//			System.out.println();
		}
		
			while(count.get()!=0){//等待所有子线程执行完  
				try {
					Thread.sleep(slotsize*slotsize/1000);
				} catch (InterruptedException e) {
					e.printStackTrace();
				}  
			}  

		merge(maxc1,maxc2);
	}
 
Example #27
Source File: LocalProgressiveSortedNeighborhood.java    From JedAIToolkit with Apache License 2.0 5 votes vote down vote up
protected void getWindowComparisons() {
    currentWindow++;
    int limit = isCleanCleanER ? datasetLimit : noOfEntities;
    final List<Comparison> windowComparisons = new ArrayList<>();
    for (int entityId = 0; entityId < limit; entityId++) {
        distinctNeighbors.clear();

        for (int position : positionIndex.getEntityPositions(entityId)) {
            if (position + currentWindow < sortedEntityIds.length) {
                if (isCleanCleanER && datasetLimit <= sortedEntityIds[position + currentWindow]
                        || !isCleanCleanER && sortedEntityIds[position + currentWindow] < entityId) {
                    updateCounters(entityId, sortedEntityIds[position + currentWindow]);
                }
            }

            if (0 <= position - currentWindow) {
                if (isCleanCleanER && datasetLimit <= sortedEntityIds[position - currentWindow]
                        || !isCleanCleanER && sortedEntityIds[position - currentWindow] < entityId) {
                    updateCounters(entityId, sortedEntityIds[position - currentWindow]);
                }
            }
        }

        for (TIntIterator iterator = distinctNeighbors.iterator(); iterator.hasNext();) {
            int neighborId = iterator.next();
            flags[neighborId] = -1;

            int entityId2 = isCleanCleanER ? neighborId - datasetLimit : neighborId;
            final Comparison c = new Comparison(isCleanCleanER, entityId, entityId2);
            c.setUtilityMeasure(getWeight(entityId, neighborId));
            windowComparisons.add(c);
        }
    }

    windowComparisons.sort(new DecComparisonWeightComparator());
    compIterator = windowComparisons.iterator();
}
 
Example #28
Source File: Region.java    From vethrfolnir-mu with GNU General Public License v3.0 5 votes vote down vote up
public void broadcastToKnown(GameObject broadcaster, WritePacket packet, Object... params) {
	KnownCreatures knownCreatures = broadcaster.get(PlayerMapping.KnownCreatures);
	TIntIterator iter = knownCreatures.knownIds.iterator();
	
	while(iter.hasNext()) {
		int id = iter.next();
		
		GameObject entity = entityWorld.getEntitys().get(id);
		entity.sendPacket(packet, params);
	}
}
 
Example #29
Source File: WordCluster.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * merge clusters
 */
public void mergeCluster() {
	int maxc1 = -1;
	int maxc2 = -1;
	float maxL = Float.NEGATIVE_INFINITY;
	TIntIterator it1 = slots.iterator();		
	while(it1.hasNext()){
		int i = it1.next();
		TIntIterator it2 = slots.iterator();
		//			System.out.print(i+": ");
		while(it2.hasNext()){
			int j= it2.next();

			if(i>=j)
				continue;
			//				System.out.print(j+" ");
			float L = calcL(i, j);
			//				System.out.print(L+" ");
			if (L > maxL) {
				maxL = L;
				maxc1 = i;
				maxc2 = j;
			}
		}
		//			System.out.println();
	}
	//		if(maxL == Float.NEGATIVE_INFINITY )
	//			return;

	merge(maxc1,maxc2);
}
 
Example #30
Source File: SimilaritySlow.java    From fnlp with GNU Lesser General Public License v3.0 5 votes vote down vote up
public double simJaccard(TIntHashSet s1, TIntHashSet s2) {
	int com = 0;
	if(s1==null||s2==null)
		return 0;
	TIntIterator it = s1.iterator();
	for ( int i = s1.size(); i-- > 0; ) {
		int v = it.next();
		if(s2.contains(v))
			com++;
	}
	double sim = com*1.0/(s1.size()+s2.size()-com);
	return sim;
}