Commit 3845ae54 authored by mak28ma's avatar mak28ma
Browse files

genug für heute

parent e1d41e7a
......@@ -108,6 +108,8 @@ public class Instance {
outer: for (Point p : features) {
if (p.y == 0)
return false;
for (int row = 0; row < getNrRows(); row++) {
if (featureArray[p.x][row] == p.y) {
......@@ -170,7 +172,8 @@ public class Instance {
}
}
// assert that the entries in the expanded matrices are of size x(x-1)/2+x
// assert that the entries in the expanded matrices are of size
// x(x-1)/2+x
assert (Matrices.cardinality(denseInstanceMatrix) * ((Matrices.cardinality(denseInstanceMatrix) - 1) * 0.5)
+ Matrices.cardinality(denseInstanceMatrix) == Matrices.cardinality(
expanedMatrix)) : "Amount of non null entries of kronecker matrix after instance expansion not correct "
......
......@@ -35,16 +35,16 @@ public class MatrixMcMatrixFace {
if (goldLabel == i.getLabel()) {
// add to TP matrix
addToMatrix(i.getValueAt(col,row), col, tpMatrix);
addToMatrix(i.getValueAt(col, row), col, tpMatrix);
} else {
// add to FP matrix
addToMatrix(i.getValueAt(col,row), col, fpMatrix);
addToMatrix(i.getValueAt(col, row), col, fpMatrix);
}
}
}
}
}
public void removeInstance(Instance i) {
// for each column, #columns == windowsize
// l2r t2B
......@@ -53,22 +53,25 @@ public class MatrixMcMatrixFace {
if (goldLabel == i.getLabel()) {
// add to TP matrix
removeFromMatrix(i.getValueAt(col,row), col, tpMatrix);
removeFromMatrix(i.getValueAt(col, row), col, tpMatrix);
} else {
// add to FP matrix
removeFromMatrix(i.getValueAt(col,row), col, fpMatrix);
removeFromMatrix(i.getValueAt(col, row), col, fpMatrix);
}
}
}
}
private void removeFromMatrix(int feature, int windowcolumn, FlexCompColMatrix matrix) {
matrix.add(feature, windowcolumn, -1);
}
private void addToMatrix(int feature, int windowcolumn, FlexCompColMatrix matrix) {
//do not add the default label!!
if (feature == 0)
return;
matrix.add(feature, windowcolumn, 1);
}
......@@ -112,26 +115,23 @@ public class MatrixMcMatrixFace {
double scoreCurrent = entry.get() - fpMatrix.get(entry.row(), entry.column());
if (scoreCurrent > maxScore) {
maxScore = scoreCurrent;
bestEntry = new Point(entry.column(),entry.row());
bestEntry = new Point(entry.column(), entry.row());
}
}
return bestEntry == null ? null :bestEntry;
return bestEntry == null ? null : bestEntry;
}
public String asString(List<MatrixMapping> mappings) {
StringBuilder sb = new StringBuilder();
sb.append("Matrix, Goldlabel=" + LabelAlphabet.getFeatureToId(goldLabel) + "\n");
// print the tp matrix
sb.append("TP-Matrix:\n");
sb.append(matrixToString(tpMatrix,mappings));
sb.append(matrixToString(tpMatrix, mappings));
// print the fp matrix
sb.append("FP-Matrix:\n");
sb.append(matrixToString(fpMatrix,mappings));
sb.append(matrixToString(fpMatrix, mappings));
return sb.toString();
}
public String matrixToString(FlexCompColMatrix matrix, List<MatrixMapping> mappings) {
StringBuilder sb = new StringBuilder();
......@@ -139,12 +139,16 @@ public class MatrixMcMatrixFace {
while (iterator.hasNext()) {
MatrixEntry next = iterator.next();
//recalculate the features for each entry
List<Point> determineFeaturesForIndex = MatrixUtil.determineFeaturesForIndex(new Point(next.column(),next.row()), mappings);
// recalculate the features for each entry
List<Point> determineFeaturesForIndex = MatrixUtil
.determineFeaturesForIndex(new Point(next.column(), next.row()), mappings);
String featureRepresentaion = MatrixUtil.convertPointListToFeatureString(determineFeaturesForIndex);
sb.append("Element at: " + "colnr " + next.column() + " and rownr " + next.row() +" Alphabet_ID:" +next.row() + " represents feature: " + featureRepresentaion).append("\n");
// sb.append("Col: " + next.column() + " Row: " + LabelAlphabet.getFeatureToId(next.row()) +"("+next.row()+")" + " " + " Value: "
// +next.get()).append("\n");
sb.append("Element at: " + "colnr " + next.column() + " and rownr " + next.row() + " Alphabet_ID:"
+ next.row() + " represents feature: " + featureRepresentaion).append("\n");
// sb.append("Col: " + next.column() + " Row: " +
// LabelAlphabet.getFeatureToId(next.row()) +"("+next.row()+")" + "
// " + " Value: "
// +next.get()).append("\n");
}
return sb.toString();
}
......@@ -183,8 +187,4 @@ public class MatrixMcMatrixFace {
return true;
}
}
......@@ -5,30 +5,58 @@ public class MatrixPoint {
private int x;
private int y;
private double score;
public MatrixPoint(int x, int y, double score) {
private double fp;
private double tp;
public MatrixPoint(int x, int y, double score, double tp, double fp) {
super();
this.x = x;
this.y = y;
this.score = score;
this.tp = tp;
this.fp = fp;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
public int getY() {
return y;
}
public void setY(int y) {
this.y = y;
}
public double getScore() {
return score;
}
public void setScore(double score) {
this.score = score;
}
public double getFp() {
return fp;
}
public void setFp(double fp) {
this.fp = fp;
}
public double getTp() {
return tp;
}
public void setTp(double tp) {
this.tp = tp;
}
}
......@@ -16,6 +16,7 @@ import java.util.stream.Collector;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import de.uniwue.ls6.algorithm.datastructure.RepresentationRule;
import de.uniwue.ls6.datastructure.Instance;
import de.uniwue.ls6.datastructure.LabelAlphabet;
import de.uniwue.ls6.datastructure.MatrixMapping;
......@@ -45,13 +46,15 @@ public class MatrixUtil {
matrixMapping.addEntry(new Point(entry.column(), entry.row()));
// save the score
double score = entry.get() - matrixface.getFpMatrix().get(entry.row(), entry.column());
entries.add(new MatrixPoint(entry.column(), entry.row(), score));
entries.add(new MatrixPoint(entry.column(), entry.row(), score, entry.get(),
matrixface.getFpMatrix().get(entry.row(), entry.column())));
}
}
if (matrixMapping.getDenseMatrixDimension() > Math.sqrt(beamSize)) {
logger.warn("Too many possible features! We restrict to the best " + beamSize
+ " Amounf of potentially good features " + matrixMapping.getDenseMatrixDimension()*matrixMapping.getDenseMatrixDimension());
+ " Amount of potentially good features "
+ matrixMapping.getDenseMatrixDimension() * matrixMapping.getDenseMatrixDimension());
matrixMapping = new MatrixMapping(formerMatrixSize);
// sort
......@@ -60,24 +63,38 @@ public class MatrixUtil {
@Override
public int compare(MatrixPoint arg0, MatrixPoint arg1) {
// TODO Auto-generated method stub
return (int) (arg1.getScore()-arg0.getScore());
return (int) (arg1.getScore() - arg0.getScore());
}
});
// add the top "beamsize" to the mapping
int amountEntries=0;
for (MatrixPoint entry : entries) {
if(matrixMapping.getMappingMap().size()>beamSize)break;
matrixMapping.addEntry(new Point(entry.getX(), entry.getY()));
if (matrixMapping.getMappingMap().size() > beamSize)
break;
if (entry.getScore() > 0) {
matrixMapping.addEntry(new Point(entry.getX(), entry.getY()));
}
}
System.out.println("Mappingsize: " + matrixMapping.getMappingMap().size());
}
// infer the -> righthandside
ArrayList<MatrixMapping> arrayList = new ArrayList<MatrixMapping>(mappings);
arrayList.add(matrixMapping);
matrixMapping.inferDenseMapValues(arrayList);
// System.out.println(entries.size()+"==");
// debug
// for (MatrixPoint entry : entries) {
// Point densePoints = matrixMapping.getMappingMap().get(new Point(entry.getX(), entry.getY()));
// List<Point> featuresForDenseIndex = matrixMapping.getFeaturesForDenseIndex(densePoints);
// RepresentationRule representationRule = new RepresentationRule(6, featuresForDenseIndex, 1, 10);
// System.out.println(entry.getScore() + "\t" + maximum + "\tTP " + entry.getTp() + "\tFP" + entry.getFp()
// + "\t" + representationRule.toString());
// }
return matrixMapping;
}
......@@ -152,7 +169,7 @@ public class MatrixUtil {
// assure no point is null
assert (secondBack != null && firstBack != null) : "One of the reverted points is null";
}
reversedfeatures.addAll(toAdd);
......
......@@ -33,7 +33,7 @@ public class FirstTest {
File korpusFOlder = new File("X:\\Neuer Ordner\\output+speech");
MultiClassRepresentationRuleAlgorithm algorithm = new MultiClassRepresentationRuleAlgorithm(500);
MultiClassRepresentationRuleAlgorithm algorithm = new MultiClassRepresentationRuleAlgorithm(2500);
TypeSystemDescription tsd = TypeSystemDescriptionFactory
.createTypeSystemDescriptionFromPath(typesystem.toURL().toString());
......@@ -41,7 +41,6 @@ public class FirstTest {
"de.uniwue.kalimachos.coref.type.POS", tsd, new POSTagFeatureGenerator("POSTag"),
new WordFeaturegenerator(),new IsUppercaseFeatureGenerator(), new PrefixNGenerator(3), new NGramGenerator());
System.out.println(instances.size());
algorithm.learn(instances.toArray(new Instance[0]));
......
......@@ -35,7 +35,7 @@ public class FirstTest2 {
File korpusFOlder = new File("X:\\Neuer Ordner\\output+speech");
MultiClassRepresentationRuleAlgorithm algorithm = new MultiClassRepresentationRuleAlgorithm(9);
MultiClassRepresentationRuleAlgorithm algorithm = new MultiClassRepresentationRuleAlgorithm(500);
TypeSystemDescription tsd = TypeSystemDescriptionFactory
.createTypeSystemDescriptionFromPath(typesystem.toURL().toString());
......@@ -46,8 +46,8 @@ public class FirstTest2 {
instances.addAll(InstanceCreationFactory.createWindowedInstancesFromUIMA(f, instances.size(), 2, 2,
"de.uniwue.kalimachos.coref.type.POS", tsd, new BIO_UIMA_FeatureGen("de.uniwue.kalimachos.coref.type.NamedEntity", "NE"),
new WordFeaturegenerator(), new SuffixNGenerator(4), new SuffixNGenerator(3),
new SuffixNGenerator(2), new SuffixNGenerator(1), new PrefixNGenerator(1), new PrefixNGenerator(2),
new IsUppercaseFeatureGenerator(), new PrefixNGenerator(3), new NGramGenerator(), new POSTagFeatureGenerator("POSTag")));
new SuffixNGenerator(2), new SuffixNGenerator(1), new PrefixNGenerator(1),
new IsUppercaseFeatureGenerator() ));
System.out.println("instances: " + instances.size());
// if(instances.size()>20000)break;
}
......
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