You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ctakes.apache.org by st...@apache.org on 2012/12/20 21:37:55 UTC
svn commit: r1424686 -
/incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/selection/Chi2FeatureSelection.java
Author: stevenbethard
Date: Thu Dec 20 20:37:55 2012
New Revision: 1424686
URL: http://svn.apache.org/viewvc?rev=1424686&view=rev
Log:
Orders features in Chi2FeatureSelection file by their Chi2 value.
Modified:
incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/selection/Chi2FeatureSelection.java
Modified: incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/selection/Chi2FeatureSelection.java
URL: http://svn.apache.org/viewvc/incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/selection/Chi2FeatureSelection.java?rev=1424686&r1=1424685&r2=1424686&view=diff
==============================================================================
--- incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/selection/Chi2FeatureSelection.java (original)
+++ incubator/ctakes/trunk/ctakes-temporal/src/main/java/org/apache/ctakes/temporal/ae/feature/selection/Chi2FeatureSelection.java Thu Dec 20 20:37:55 2012
@@ -12,9 +12,11 @@ import org.cleartk.classifier.Feature;
import org.cleartk.classifier.Instance;
import org.cleartk.classifier.feature.transform.TransformableFeature;
+import com.google.common.base.Function;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
+import com.google.common.collect.Ordering;
import com.google.common.collect.Sets;
import com.google.common.collect.Table;
@@ -31,7 +33,7 @@ public class Chi2FeatureSelection<OUTCOM
/**
* Helper class for aggregating and computing mutual Chi2 statistics
*/
- private static class Chi2Scorer<OUTCOME_T> {
+ private static class Chi2Scorer<OUTCOME_T> implements Function<String, Double> {
protected Multiset<OUTCOME_T> classCounts;
protected Table<String, OUTCOME_T, Integer> featValueClassCount;
@@ -49,6 +51,10 @@ public class Chi2FeatureSelection<OUTCOM
this.featValueClassCount.put(featureName, outcome, count + occurrences);
this.classCounts.add(outcome, occurrences);
}
+
+ public Double apply(String featureName) {
+ return this.score(featureName);
+ }
public double score(String featureName) {
// notation index of 0 means false, 1 mean true
@@ -163,7 +169,8 @@ public class Chi2FeatureSelection<OUTCOM
File out = new File(uri);
BufferedWriter writer = new BufferedWriter(new FileWriter(out));
- for (String feature : this.selectedFeatureNames) {
+ Ordering<String> ordering = Ordering.natural().onResultOf(this.chi2Function).reverse();
+ for (String feature : ordering.immutableSortedCopy(this.selectedFeatureNames)) {
writer.append(String.format("%s\t%f\n", feature, this.chi2Function.score(feature)));
}