Skip to content

Commit

Permalink
refactoring to improve the efficiency when metrics are computed
Browse files Browse the repository at this point in the history
  • Loading branch information
lfoppiano committed Nov 17, 2017
1 parent 2107af1 commit 99d3417
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 344 deletions.
34 changes: 34 additions & 0 deletions grobid-trainer/src/main/java/org/grobid/trainer/LabelStat.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,48 @@ public final class LabelStat {
private int observed = 0; // this is true positives
private int expected = 0; // total expected number of items with this label

private double accuracy = 0.0;
private int trueNegative;
private boolean hasChanged = false;

public void incrementFalseNegative() {
this.incrementFalseNegative(1);
hasChanged = true;
}

public void incrementFalsePositive() {
this.incrementFalsePositive(1);
hasChanged = true;
}

public void incrementObserved() {
this.incrementObserved(1);
hasChanged = true;
}

public void incrementExpected() {
this.incrementExpected(1);
hasChanged = true;
}

public void incrementFalseNegative(int count) {
this.falseNegative += count;
hasChanged = true;
}

public void incrementFalsePositive(int count) {
this.falsePositive += count;
hasChanged = true;
}

public void incrementObserved(int count) {
this.observed += count;
hasChanged = true;
}

public void incrementExpected(int count) {
this.expected += count;
hasChanged = true;
}

public int getExpected() {
Expand All @@ -60,24 +72,36 @@ public int getAll() {

public void setFalsePositive(int falsePositive) {
this.falsePositive = falsePositive;
hasChanged = true;
}

public void setFalseNegative(int falseNegative) {
this.falseNegative = falseNegative;
hasChanged = true;
}

public void setObserved(int observed) {
this.observed = observed;
hasChanged = true;
}

public void setExpected(int expected) {
this.expected = expected;
hasChanged = true;
}

public static LabelStat create() {
return new LabelStat();
}

public double getAccuracy() {
double accuracy = (double) (observed + trueNegative) / (observed + falsePositive + trueNegative + falseNegative);
if (accuracy < 0.0)
accuracy = 0.0;

return accuracy;
}

public double getPrecision() {
if (observed == 0.0) {
return 0.0;
Expand Down Expand Up @@ -111,4 +135,14 @@ public String toString() {
.append("; expected: ").append(expected);
return builder.toString();
}

public void setTrueNegative(int trueNegative) {
this.trueNegative = trueNegative;
}

public boolean hasChanged() {
Boolean oldValue = new Boolean(hasChanged);
hasChanged = false;
return oldValue;
}
}
238 changes: 0 additions & 238 deletions grobid-trainer/src/main/java/org/grobid/trainer/Stats.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package org.grobid.trainer.evaluation;

import org.grobid.core.engines.config.GrobidAnalysisConfig;
import org.grobid.core.engines.tagging.GenericTagger;
import org.grobid.core.exceptions.*;
import org.grobid.core.engines.Engine;
import org.grobid.core.data.BiblioItem;
import org.grobid.core.data.BibDataSet;
import org.grobid.core.factory.GrobidFactory;
import org.grobid.core.utilities.GrobidProperties;
import org.grobid.core.utilities.UnicodeUtil;
import org.grobid.trainer.Stats;
import org.grobid.trainer.sax.NLMHeaderSaxHandler;
import org.grobid.trainer.sax.FieldExtractSaxHandler;
import org.grobid.core.utilities.TextUtilities;
import org.grobid.trainer.evaluation.utilities.NamespaceContextMap;
import org.grobid.trainer.evaluation.utilities.FieldSpecification;
Expand All @@ -26,7 +20,7 @@
import javax.xml.xpath.XPathFactory;
import javax.xml.parsers.*;
import org.xml.sax.*;
import org.xml.sax.helpers.*;

import javax.xml.xpath.XPathConstants;

import com.rockymadden.stringmetric.similarity.RatcliffObershelpMetric;
Expand Down

0 comments on commit 99d3417

Please sign in to comment.