Skip to content

Commit

Permalink
Fixed a few bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
oowekyala committed Oct 19, 2017
1 parent 14df20e commit 03202b4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,4 @@ doc
out/*
src/test/java/weka/classifiers/rules/LocalTests.java
*.iml
lib
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public CandidateAntd bestCandidate(ExpansionMetric expMetric, Map<String, Intege
bestAntd.setConditionHigher(isConditionHigher);
bestAntd.setSplitPoint(bestSplitPoint);

return new CandidateAntd(bestAntd, bestScoreYet);
return Double.isNaN(bestSplitPoint) ? null : new CandidateAntd(bestAntd, bestScoreYet);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -126,6 +127,8 @@ public List<CandidateAntd> getExpansionCandidates(ExpansionMetric expMetric) {
AttributeStats astat = en.getValue();
candids.add(astat.bestCandidate(expMetric, m_classDistribution));
}

candids.removeAll(Collections.<CandidateAntd>singleton(null));

return candids;
}
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/weka/classifiers/rules/vfdr/VfdrRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,29 @@ 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) {

// i.e. distribution is impure
if (m_lr.classDistribution().size() > 1) {

List<CandidateAntd> 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;
}
}
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -221,11 +222,11 @@ public String toString() {
}

Collections.sort(sortedDist, new Comparator<Entry<String, Integer>>() {
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return Double.compare(o2.getValue(), o1.getValue());
}
@Override
public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2) {
return Double.compare(o2.getValue(), o1.getValue());
}
}
);

for (Map.Entry<String, Integer> e : sortedDist) {
Expand Down

0 comments on commit 03202b4

Please sign in to comment.