Commit fd59e265 authored by Markus Krug's avatar Markus Krug
Browse files

removed a filter that was way too greedy

parent 29395dd3
......@@ -85,7 +85,7 @@ public class MatrixMcMatrixFace {
*/
public int getMaximumScore() {
double maxScore = 0;
double maxScore = Double.MIN_VALUE;
for (MatrixEntry entry : tpMatrix) {
double scoreCurrent = entry.get() - fpMatrix.get(entry.row(), entry.column());
......@@ -112,7 +112,7 @@ public class MatrixMcMatrixFace {
// TODO this needs a speedup because it calculates all features backwards
// which is unnecessary since it is stored in the mapping
public MatrixPoint getLocationOfMaximum(List<MatrixMapping> mappings) {
double maxScore = 0;
double maxScore = Double.MIN_VALUE;
MatrixPoint bestEntry = null;
Set<Point> mostSimpleRule = null;
for (MatrixEntry entry : tpMatrix) {
......@@ -125,7 +125,7 @@ public class MatrixMcMatrixFace {
mostSimpleRule = MatrixUtil.determineFeaturesForIndex(bestEntry.getLocation(), mappings,
mappings.size() > 0 ? true : false);
} else if (scoreCurrent == maxScore && scoreCurrent > 0) {
// keep the simpler rule
// keep the simpler rule TODO
MatrixPoint loc = new MatrixPoint(entry.column(), entry.row(), scoreCurrent, entry.get(), fps);
Set<Point> featuresForIndex = MatrixUtil.determineFeaturesForIndex(loc.getLocation(), mappings,
mappings.size() > 0 ? true : false);
......
......@@ -72,27 +72,25 @@ public class MatrixUtil {
}
// // get the features of this point
// Set<Point> featuresOfPoints = determineFeaturesForIndex(new
// Point(entry.column(), entry.row()),
// mappings, mappings.size() > 0 ? true : false);
//
// // only keep each feature combination exactly once!
// if (uniqueFeatureCombinations.contains(featuresOfPoints)) {
// continue;
// }
// uniqueFeatureCombinations.add(featuresOfPoints);
//
// // furthermore we can filter all those featurecombinations
Set<Point> featuresOfPoints = determineFeaturesForIndex(new Point(entry.column(), entry.row()),
mappings, mappings.size() > 0 ? true : false);
// only keep each feature combination exactly once!
if (uniqueFeatureCombinations.contains(featuresOfPoints)) {
continue;
}
uniqueFeatureCombinations.add(featuresOfPoints);
// furthermore we can filter all those featurecombinations
// that
// // resemble exactly the same instance set
// // because the algrotihm can not differ between those
// Set<Instance> instancesForFeatureSet =
// determineInstancesForFeatures(featuresOfPoints, indexMap);
//
// if (uniqueInstance.contains(instancesForFeatureSet)) {
// continue;
// }
// uniqueInstance.add(instancesForFeatureSet);
// resemble exactly the same instance set
// because the algrotihm can not differ between those
Set<Instance> instancesForFeatureSet = determineInstancesForFeatures(featuresOfPoints, indexMap);
if (uniqueInstance.contains(instancesForFeatureSet)) {
continue;
}
uniqueInstance.add(instancesForFeatureSet);
// finally we can decide to keep our feature for the next
// iteration
......@@ -118,9 +116,11 @@ public class MatrixUtil {
for (MatrixPoint entry : entries) {
if (matrixMapping.getMappingMap().size() > beamSize)
break;
if (entry.getScore() > 0) {
matrixMapping.addEntry(new Point(entry.getX(), entry.getY()));
}
// TODO this is extremely greedy!! most features have a negative
// score
// if (entry.getScore() > 0) {
matrixMapping.addEntry(new Point(entry.getX(), entry.getY()));
// }
}
// infer the -> righthandside
......@@ -147,18 +147,28 @@ public class MatrixUtil {
public static Set<Instance> determineInstancesForFeatures(Set<Point> featuresOfPoints,
Map<Point, Set<Instance>> indexMap) {
// inverted list intersection!
List<Set<Instance>> instanceSetList = new ArrayList<>();
Set<Instance> intersectionSet = new HashSet<>();
Set<Instance> smallestSet = null;
for (Point feature : featuresOfPoints) {
Set<Instance> set = indexMap.get(feature);
if (intersectionSet.isEmpty()) {
intersectionSet.addAll(set);
} else {
// keep only the elements that are in both sets
intersectionSet.retainAll(set);
instanceSetList.add(set);
if (smallestSet == null)
smallestSet = set;
else if (set.size() < smallestSet.size())
smallestSet = set;
}
outer: for (Instance i : smallestSet) {
for (Set<Instance> set : instanceSetList) {
if (!set.contains(i)) {
continue outer;
}
}
intersectionSet.add(i);
}
return intersectionSet;
}
public static MatrixMcMatrixFace performKroneckerExpansionByIndex(List<MatrixMapping> mappings,
......
......@@ -266,8 +266,8 @@ public class BinaryRepresentationRuleLearningAlgorithm implements IRepresentatio
.getY() < iterationMatrix.getTpMatrix().numRows()) : "Position of maximum out of bounds";
// expand in kronecker fashion
long time = System.currentTimeMillis();
iterationMatrix = MatrixUtil.performKroneckerExpansionByIndex(mappings, instances, indexMap, goldLabel);
//long time = System.currentTimeMillis();
iterationMatrix = MatrixUtil.performKroneckerExpansion(mappings, instances, goldLabel);
// System.out.println(System.currentTimeMillis() - time);
// assert that the maximum is growing
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment