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