private static void addTfByDocumentToBitSet(final BitSet documentIndices, final int [] tfByDocument) { for (int j = 0; j < tfByDocument.length / 2; j++) { documentIndices.set(tfByDocument[j * 2]); } } }
/** * Adds stem index to the set with a check on the stem's document frequency. */ private void addStemIndex(final int [] wordsStemIndex, int documentCount, int [][] stemsTfByDocument, final BitSet requiredStemIndices, final int featureIndex) { final int stemIndex = wordsStemIndex[featureIndex]; final int df = stemsTfByDocument[stemIndex].length / 2; if (((double) df / documentCount) <= maxWordDf) { requiredStemIndices.set(stemIndex); } }
public SegmentationDefinition getSubsetDefinition(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int conditions[][] = new int[wordsetSize][1]; int segments[] = new int[wordsetSize]; int bit = 1, pos = 0; int mask = (1 << wordsetSize) - 1; BitSet neededCounts = new BitSet(1 << wordsetSize); while (bit < mask) { segments[pos] = mask - bit; neededCounts.set(segments[pos]); conditions[pos] = new int[] { bit }; bit = bit << 1; ++pos; } neededCounts.set(mask); return new SegmentationDefinition(segments, conditions, neededCounts); }
public SegmentationDefinition getSubsetDefinition(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int conditions[][] = new int[wordsetSize][1]; int segments[] = new int[wordsetSize]; int bit = 1, pos = 0; int mask = (1 << wordsetSize) - 1; BitSet neededCounts = new BitSet(1 << wordsetSize); while (bit < mask) { segments[pos] = bit; neededCounts.set(bit); conditions[pos] = new int[] { mask - bit }; bit = bit << 1; ++pos; } neededCounts.set(mask); return new SegmentationDefinition(segments, conditions, neededCounts); }
public SegmentationDefinition getSubsetDefinition(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int conditions[][] = new int[wordsetSize][1]; int segments[] = new int[wordsetSize]; int bit = 1, pos = 0; int mask = (1 << wordsetSize) - 1; BitSet neededCounts = new BitSet(1 << wordsetSize); while (bit < mask) { segments[pos] = bit; neededCounts.set(bit); conditions[pos] = new int[] { mask }; bit = bit << 1; ++pos; } neededCounts.set(mask); return new SegmentationDefinition(segments, conditions, neededCounts); }
public SegmentationDefinition getSubsetDefinition(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int conditions[][] = new int[wordsetSize][]; int segments[] = new int[wordsetSize]; int bit = 1, pos = 0; int mask = (1 << wordsetSize) - 1; BitSet neededCounts = new BitSet(1 << wordsetSize); while (bit < mask) { segments[pos] = bit; neededCounts.set(bit); conditions[pos] = new int[pos]; for (int i = 0; i < pos; ++i) { neededCounts.set(bit + (1 << i)); conditions[pos][i] = 1 << i; } bit = bit << 1; ++pos; } return new SegmentationDefinition(segments, conditions, neededCounts); }
public SegmentationDefinition getSubsetDefinition(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int conditions[][] = new int[wordsetSize][]; int segments[] = new int[wordsetSize]; int bit = 1, pos = 0; int mask = (1 << wordsetSize) - 1; BitSet neededCounts = new BitSet(1 << wordsetSize); while (bit < mask) { segments[pos] = bit; neededCounts.set(bit); conditions[pos] = new int[wordsetSize - (pos + 1)]; for (int i = pos + 1; i < wordsetSize; ++i) { neededCounts.set(bit + (1 << i)); conditions[pos][i - (pos + 1)] = 1 << i; } bit = bit << 1; ++pos; } return new SegmentationDefinition(segments, conditions, neededCounts); }
public SegmentationDefinition getSubsetDefinition(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int conditions[][] = new int[wordsetSize][wordsetSize - 1]; int segments[] = new int[wordsetSize]; int condBit, condPos, bit = 1, pos = 0; int mask = (1 << wordsetSize) - 1; BitSet neededCounts = new BitSet(1 << wordsetSize); while (bit < mask) { segments[pos] = bit; neededCounts.set(bit); condBit = 1; condPos = 0; while (condBit < mask) { if (condBit != bit) { neededCounts.set(bit + condBit); conditions[pos][condPos] = condBit; ++condPos; } condBit = condBit << 1; } bit = bit << 1; ++pos; } return new SegmentationDefinition(segments, conditions, neededCounts); }
public SegmentationDefinition getSubsetDefinition(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int mask = (1 << wordsetSize) - 1; int conditions[][] = new int[][] { { mask } }; int segments[] = new int[] { mask }; BitSet neededCounts = new BitSet(1 << wordsetSize); neededCounts.set(mask); return new SegmentationDefinition(segments, conditions, neededCounts); }
@Override protected SegmentationDefinition getSubsetDefinitionWithRestrictions(int wordsetSize, int maxSingleSubSetSize, int maxSubSetUnionSize) { int maxSegmentSize = maxSubSetUnionSize > maxSingleSubSetSize ? maxSingleSubSetSize : (maxSubSetUnionSize - 1); int mask = (1 << wordsetSize) - 1; int posInResult = 0, segmentBitCount; int segments[] = new int[getNumberOfCombinations(wordsetSize, maxSegmentSize)]; int conditions[][] = new int[segments.length][]; // Go through all possible probabilities for (int i = 1; i < mask; ++i) { segmentBitCount = Integer.bitCount(i); if (segmentBitCount <= maxSegmentSize) { segments[posInResult] = i; // invert the probability elements to get the possible conditions conditions[posInResult] = createRestrictedConditions(mask - i, Math.min(maxSingleSubSetSize, maxSubSetUnionSize - segmentBitCount)); ++posInResult; } } BitSet neededCounts = new BitSet(1 << wordsetSize); neededCounts.set(1, 1 << wordsetSize); return new SegmentationDefinition(segments, conditions, neededCounts); }
private BitSet[] createBitSets(IntOpenHashSet hashSets[], IntOpenHashSet mergedHashSet) { BitSet bitSets[] = new BitSet[hashSets.length]; for (int i = 0; i < bitSets.length; ++i) { bitSets[i] = new BitSet(mergedHashSet.size()); } int pos = 0; for (int i = 0; i < mergedHashSet.keys.length; i++) { if (mergedHashSet.allocated[i]) { for (int j = 0; j < bitSets.length; ++j) { if (hashSets[j].contains(mergedHashSet.keys[i])) { bitSets[j].set(pos); } } ++pos; } } return bitSets; }
@Override protected SegmentationDefinition getSubsetDefinitionWithoutRestrictions(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int mask = (1 << wordsetSize) - 1; int posInResult = 0; int segments[] = new int[mask - 1]; int conditions[][] = new int[segments.length][]; // Go through all possible probabilities for (int i = 1; i < mask; ++i) { segments[posInResult] = i; // invert the probability elements to get the possible conditions conditions[posInResult] = createConditions(mask - i); ++posInResult; } BitSet neededCounts = new BitSet(1 << wordsetSize); neededCounts.set(1, 1 << wordsetSize); return new SegmentationDefinition(segments, conditions, neededCounts); }
@Override protected SegmentationDefinition getSubsetDefinitionWithoutRestrictions(int wordsetSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int mask = (1 << wordsetSize) - 1; int posInResult = 0; int segments[] = new int[wordsetSize]; int conditions[][] = new int[segments.length][]; int bit = 1; // Go through all possible probabilities while (bit < mask) { segments[posInResult] = bit; // invert the probability elements to get the possible conditions conditions[posInResult] = createConditions(mask - bit); bit = bit << 1; ++posInResult; } BitSet neededCounts = new BitSet(1 << wordsetSize); neededCounts.set(1, 1 << wordsetSize); return new SegmentationDefinition(segments, conditions, neededCounts); }
@Override protected SegmentationDefinition getSubsetDefinitionWithRestrictions(int wordsetSize, int maxSingleSubSetSize, int maxSubSetUnionSize) { /* * Code the combinations of elements not with ids but with bits. 01 is * only the first element, 10 is the second and 11 is the combination of * both. */ int mask = (1 << wordsetSize) - 1; int posInResult = 0; int segments[] = new int[wordsetSize]; int conditions[][] = new int[segments.length][]; int bit = 1; int conditionRestriction = maxSubSetUnionSize > maxSingleSubSetSize ? maxSingleSubSetSize : (maxSubSetUnionSize - 1); // Go through all possible probabilities while (bit < mask) { segments[posInResult] = bit; // invert the probability elements to get the possible conditions conditions[posInResult] = createRestrictedConditions(mask - bit, conditionRestriction); bit = bit << 1; ++posInResult; } BitSet neededCounts = new BitSet(1 << wordsetSize); neededCounts.set(1, 1 << wordsetSize); return new SegmentationDefinition(segments, conditions, neededCounts); }
/** * apply consumer to each connected community one time * * @param node node nodeId * @param consumer community nodeId consumer */ private void forEachConnectedCommunity(int node, IntConsumer consumer) { final BitSet visited = new BitSet(nodeCount); graph.forEachRelationship(node, D, (s, t, r) -> { final int c = localCommunities[t]; if (c == NONE) { return true; } if (visited.get(c)) { return true; } visited.set(c); consumer.accept(c); return true; }); }
/** * apply consumer to each connected community one time * * @param node node nodeId * @param consumer community nodeId consumer */ private void forEachConnectedCommunity(int node, IntConsumer consumer) { final BitSet visited = new BitSet(nodeCount); graph.forEachRelationship(node, D, (s, t, r) -> { final int c = localCommunities[t]; if (c == NONE) { return true; } if (visited.get(c)) { return true; } visited.set(c); consumer.accept(c); return true; }); }
private void run(int goal, Direction direction) { while (!queue.isEmpty() && running()) { int node = queue.pop(); if (node == goal) { return; } visited.set(node); double costs = this.costs.getOrDefault(node, Double.MAX_VALUE); graph.forEachRelationship( node, direction, (source, target, relId, weight) -> { updateCosts(source, target, weight + costs); return true; }); progressLogger.logProgress((double) node / (nodeCount - 1)); } }
private void strongConnect(int node) { if (indices.containsKey(node)) { return; } lowLink.put(node, index); indices.put(node, index); index++; stack.push(node); onStack.set(node); graph.forEachRelationship(node, Direction.OUTGOING, this::accept); if (indices.get(node) == lowLink.get(node)) { relax(node); } }
private void strongConnect(int node) { if (indices.containsKey(node)) { return; } lowLink.put(node, index); indices.put(node, index); index++; stack.push(node); onStack.set(node); graph.forEachRelationship(node, Direction.OUTGOING, this::accept); if (indices.get(node) == lowLink.get(node)) { relax(node); } }
private void run(int goal, Direction direction) { while (!queue.isEmpty() && running()) { int node = queue.pop(); if (node == goal) { return; } visited.set(node); double costs = this.costs.getOrDefault(node, Double.MAX_VALUE); graph.forEachRelationship( node, direction, (source, target, relId, weight) -> { boolean oldCostChanged = updateCosts(source, target, weight + costs); if (!visited.get(target)) { if (oldCostChanged) { queue.update(target); } else { queue.add(target, 0); } } return true; }); progressLogger.logProgress((double) node / (nodeCount - 1)); } }