Java Code Examples for org.apache.lucene.util.OpenBitSet#flip()

The following examples show how to use org.apache.lucene.util.OpenBitSet#flip() . 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: Inductor.java    From winter with Apache License 2.0 5 votes vote down vote up
public void updatePositiveCover(FDList nonFds) {
/*		if (nonFds.isEmpty())
			return;
		
		// Sort the negative cover
		Logger.getInstance().writeln("Sorting FD-violations ...");
		Collections.sort(nonFds, new Comparator<OpenBitSet>() {
			@Override
			public int compare(OpenBitSet o1, OpenBitSet o2) {
				return (int)(o1.cardinality() - o2.cardinality());
			}
		});
*/		// THE SORTING IS NOT NEEDED AS THE UCCSet SORTS THE NONUCCS BY LEVEL ALREADY
		
		Logger.getInstance().writeln("Inducing FD candidates ...");
		for (int i = nonFds.getFdLevels().size() - 1; i >= 0; i--) {
			if (i >= nonFds.getFdLevels().size()) // If this level has been trimmed during iteration
				continue;
			
			List<OpenBitSet> nonFdLevel = nonFds.getFdLevels().get(i);
			for (OpenBitSet lhs : nonFdLevel) {
				
				OpenBitSet fullRhs = lhs.clone();
				fullRhs.flip(0, this.posCover.getNumAttributes());
				
				for (int rhs = fullRhs.nextSetBit(0); rhs >= 0; rhs = fullRhs.nextSetBit(rhs + 1))
					this.specializePositiveCover(lhs, rhs, nonFds);
			}
			nonFdLevel.clear();
		}
	}
 
Example 2
Source File: HyFD.java    From winter with Apache License 2.0 4 votes vote down vote up
private FDTree calculatePositiveCover(ArrayList<OpenBitSet> negCover) {
		FDTree posCover = new FDTree(this.numAttributes, this.maxLhsSize);
		posCover.addMostGeneralDependencies();
		
		//
		//int bitsetCounter = 0;
		//long t = System.currentTimeMillis();
		//
		
//		OpenBitSet previous1Lhs = null;
//		OpenBitSet previous2Lhs = null;
		for (int i = negCover.size() - 1; i >= 0; i--) {
			OpenBitSet lhs = negCover.remove(i);

			//
			//bitsetCounter++;
			//if (bitsetCounter % 1 == 0) {
			//	System.out.println("\t\t" + bitsetCounter + "\\" + negCover.size() + " bitsets; " + "- fds; " + (System.currentTimeMillis() - t) + " time");
			//	t = System.currentTimeMillis();
			//}
			//
			
			OpenBitSet fullRhs = lhs.clone();
			fullRhs.flip(0, fullRhs.size());
			
			for (int rhs = fullRhs.nextSetBit(0); rhs >= 0; rhs = fullRhs.nextSetBit(rhs + 1)) {
				// If one of the previous lhs subsumes this lhs with the same rhs, then we can skip it here
//				if ((previous1Lhs != null) && this.subsumes(lhs, previous1Lhs, rhs))
//					continue;
//				if ((previous2Lhs != null) && this.subsumes(lhs, previous2Lhs, rhs))
//					continue;
				
				this.memoryGuardian.memoryChanged(this.specializePositiveCover(posCover, lhs, rhs));
			}
			
			// If dynamic memory management is enabled, frequently check the memory consumption and trim the positive cover if it does not fit anymore
		//	this.memoryGuardian.match(posCover);
			
//			previous2Lhs = previous1Lhs;
//			previous1Lhs = lhs;
		}
		return posCover;
	}
 
Example 3
Source File: FDTreeElement.java    From winter with Apache License 2.0 4 votes vote down vote up
protected void maximizeNegativeRecursive(PositionListIndex currentPli, OpenBitSet currentLhs, int numAttributes, int[][] rhsPlis, FDTree invalidFds) {
	PositionListIndex[] childPlis = new PositionListIndex[numAttributes];
	
	// Traverse the tree depth-first, left-first; generate plis for children and pass them over; store the child plis locally to reuse them for the checking afterwards
	if (this.children != null) {
		for (int attr = 0; attr < numAttributes; attr++) {
			if (this.children[attr] != null) {
				childPlis[attr] = currentPli.intersect(rhsPlis[attr]);
				
				currentLhs.set(attr);
				this.children[attr].maximizeNegativeRecursive(childPlis[attr], currentLhs, numAttributes, rhsPlis, invalidFds);
				currentLhs.clear(attr);
			}
		}
	}
	
	// On the way back, check all rhs-FDs that all their possible supersets are valid FDs; check with refines or, if available, with previously calculated plis
	//     which supersets to consider: add all attributes A with A notIn lhs and A notequal rhs; 
	//         for newLhs->rhs check that no FdOrSpecialization exists, because it is invalid then; this check might be slower than the FD check on high levels but faster on low levels in particular in the root! this check is faster on the negative cover, because we look for a non-FD
	for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) {
		OpenBitSet extensions = currentLhs.clone();
		extensions.flip(0, numAttributes);
		extensions.clear(rhs);
		
		for (int extensionAttr = extensions.nextSetBit(0); extensionAttr >= 0; extensionAttr = extensions.nextSetBit(extensionAttr + 1)) {
			currentLhs.set(extensionAttr);
			if (childPlis[extensionAttr] == null)
				childPlis[extensionAttr] = currentPli.intersect(rhsPlis[extensionAttr]);
			
			// If a superset is a non-FD, mark this as not rhsFD, add the superset as a new node, filterGeneralizations() of the new node, call maximizeNegative() on the new supersets node
			//     if the superset node is in a right node of the tree, it will be checked anyways later; hence, only check supersets that are left or in the same tree path
			if (!childPlis[extensionAttr].refines(rhsPlis[rhs])) {
				this.rhsFds.clear(rhs);

				FDTreeElement newElement = invalidFds.addFunctionalDependency(currentLhs, rhs);
				//invalidFds.filterGeneralizations(currentLhs, rhs); // TODO: test effect
				newElement.maximizeNegativeRecursive(childPlis[extensionAttr], currentLhs, numAttributes, rhsPlis, invalidFds);
			}
			currentLhs.clear(extensionAttr);
		}
	}
}
 
Example 4
Source File: FDTree.java    From winter with Apache License 2.0 4 votes vote down vote up
public void maximizeNegative(List<PositionListIndex> plis, int[][] invertedPlis, int numRecords) {
	// Maximizing negative cover is better than maximizing positive cover, because we do not need to check minimality; inversion does this automatically, i.e., generating a non-FD that creates a valid, non-minimal FD is not possible
	int numAttributes = plis.size();
	OpenBitSet currentLhs = new OpenBitSet(numAttributes);
	
	// Traverse the tree depth-first, left-first
	if (this.getChildren() != null) {
		for (int attr = 0; attr < numAttributes; attr++) {
			if (this.getChildren()[attr] != null) {
				currentLhs.set(attr);
				this.getChildren()[attr].maximizeNegativeRecursive(plis.get(attr), currentLhs, numAttributes, invertedPlis, this);
				currentLhs.clear(attr);
			}
		}
	}

	// Add invalid root FDs {} -/-> rhs to negative cover, because these are seeds for not yet discovered non-FDs
	this.addInvalidRootFDs(plis, numRecords); // TODO: These FDs make the search complex again :-(

	// On the way back, check all rhs-FDs that all their possible supersets are valid FDs; check with refines or, if available, with previously calculated plis
	//     which supersets to consider: add all attributes A with A notIn lhs and A notequal rhs; 
	//         for newLhs->rhs check that no FdOrSpecialization exists, because it is invalid then; this check might be slower than the FD check on high levels but faster on low levels in particular in the root! this check is faster on the negative cover, because we look for a non-FD
	for (int rhs = this.rhsFds.nextSetBit(0); rhs >= 0; rhs = this.rhsFds.nextSetBit(rhs + 1)) {
		OpenBitSet extensions = currentLhs.clone();
		extensions.flip(0, numAttributes);
		extensions.clear(rhs);
		
		// If a superset is a non-FD, mark this as not rhsFD, add the superset as a new node, filterGeneralizations() of the new node, call maximizeNegative() on the new supersets node
		//     if the superset node is in a right node of the tree, it will be checked anyways later; hence, only check supersets that are left or in the same tree path
		for (int extensionAttr = extensions.nextSetBit(0); extensionAttr >= 0; extensionAttr = extensions.nextSetBit(extensionAttr + 1)) {
			currentLhs.set(extensionAttr);
			
			if (this.containsFdOrSpecialization(currentLhs, rhs) || !plis.get(extensionAttr).refines(invertedPlis[rhs])) { // Otherwise, it must be false and a specialization is already contained; Only needed in root node, because we already filtered generalizations of other nodes and use a depth-first search that always removes generalizations when a new node comes in!
				this.rhsFds.clear(rhs);
				
				FDTreeElement newElement = this.addFunctionalDependency(currentLhs, rhs);
				//this.filterGeneralizations(currentLhs, rhs); // TODO: test effect
				newElement.maximizeNegativeRecursive(plis.get(extensionAttr), currentLhs, numAttributes, invertedPlis, this);
			}
			currentLhs.clear(extensionAttr);
		}
	}
}