diff --git a/.gitignore b/.gitignore index a1a4383..16484ea 100644 --- a/.gitignore +++ b/.gitignore @@ -213,3 +213,4 @@ doc out/* src/test/java/weka/classifiers/rules/LocalTests.java *.iml +lib diff --git a/src/main/java/weka/classifiers/rules/vfdr/GaussianAttributeStats.java b/src/main/java/weka/classifiers/rules/vfdr/GaussianAttributeStats.java index 5c3fff2..cf05fb9 100644 --- a/src/main/java/weka/classifiers/rules/vfdr/GaussianAttributeStats.java +++ b/src/main/java/weka/classifiers/rules/vfdr/GaussianAttributeStats.java @@ -127,7 +127,7 @@ public CandidateAntd bestCandidate(ExpansionMetric expMetric, Map getExpansionCandidates(ExpansionMetric expMetric) { AttributeStats astat = en.getValue(); candids.add(astat.bestCandidate(expMetric, m_classDistribution)); } + + candids.removeAll(Collections.singleton(null)); return candids; } diff --git a/src/main/java/weka/classifiers/rules/vfdr/VfdrRule.java b/src/main/java/weka/classifiers/rules/vfdr/VfdrRule.java index 1a4b772..169fe4c 100644 --- a/src/main/java/weka/classifiers/rules/vfdr/VfdrRule.java +++ b/src/main/java/weka/classifiers/rules/vfdr/VfdrRule.java @@ -74,8 +74,9 @@ public SufficientStats getStats() { * Expands a rule according to its sufficient statistics. * * @param expMetric The metric used to get the best expansion possible + * * @return A new VfdrRule if the default rule was expanded, or {@code this} - * otherwise + * otherwise */ public VfdrRule expand(ExpansionMetric expMetric) { @@ -83,21 +84,19 @@ public VfdrRule expand(ExpansionMetric expMetric) { if (m_lr.classDistribution().size() > 1) { List bestCandidates = m_lr.getExpansionCandidates(expMetric); - // System.err.println(bestCandidates.toString()); Collections.sort(bestCandidates); boolean doExpand = false; - if (bestCandidates.size() > 0) { + if (bestCandidates.size() > 1) { double hoeffding = computeHoeffding(expMetric.getMetricRange(m_lr.m_classDistribution), - m_classifierCallback.getHoeffdingConfidence(), m_lr.totalWeight()); + m_classifierCallback.getHoeffdingConfidence(), m_lr.totalWeight()); CandidateAntd best = bestCandidates.get(bestCandidates.size() - 1); CandidateAntd secondBest = bestCandidates.get(bestCandidates.size() - 2); - double diff = best.expMerit() - secondBest.expMerit(); - if (diff > hoeffding || m_classifierCallback.getTieThreshold() < hoeffding) { + if (diff > hoeffding || hoeffding > m_classifierCallback.getTieThreshold()) { doExpand = true; } } @@ -132,6 +131,7 @@ public VfdrRule expand(ExpansionMetric expMetric) { * Whether the rule covers the example or not. * * @param datum The instance to test + * * @return Whether the rule covers the example or not. */ public boolean covers(Instance datum) { @@ -171,6 +171,7 @@ public double size() { * @param range Range of the split metric * @param confidence Confidence threshold * @param weight Weight of the observations made so far with this rule + * * @return Hoeffding bound */ public double computeHoeffding(double range, double confidence, double weight) { @@ -221,11 +222,11 @@ public String toString() { } Collections.sort(sortedDist, new Comparator>() { - @Override - public int compare(Entry o1, Entry o2) { - return Double.compare(o2.getValue(), o1.getValue()); - } + @Override + public int compare(Entry o1, Entry o2) { + return Double.compare(o2.getValue(), o1.getValue()); } + } ); for (Map.Entry e : sortedDist) {