Skip to content

Commit

Permalink
Fixed the problem with treeDepthOption, it should now work correctly.
Browse files Browse the repository at this point in the history
Also now you can't display more trees than exist in the forest.
  • Loading branch information
michael committed Sep 5, 2020
1 parent 9a0633b commit c826200
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions src/weka/classifiers/trees/SmoothPrivateForest.java
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
* </pre>
*
* <pre>
* -T &lt;tree depth&gt;
* -R &lt;tree depth&gt;
* Tree depth option. If &lt;= 0 will be equal to the tree depth
* calculation from the paper
* (default -1)
Expand Down Expand Up @@ -105,7 +105,7 @@
*
*
* @author Michael Furner (mfurner@csu.edu.au)
* @version $Revision: 1.0$
* @version $Revision: 1.2.1$
*/
public class SmoothPrivateForest extends AbstractClassifier
implements OptionHandler, Randomizable {
Expand Down Expand Up @@ -295,6 +295,8 @@ public Enumeration<Option> listOptions() {
+ "\t(default 10)", "N", 1, "-N"));
newVector.addElement(new Option("\tNumber of trees to display.\n"
+ "\t(default 3)", "D", 1, "-D"));
newVector.addElement(new Option("\tThe tree depth (<=0 uses calculation from paper).\n"
+ "\t(default -1)", "R", 1, "-R"));
newVector.addElement(new Option("\tPrivacy budget for differential "
+ "privacy (episilon in paper)\n"
+ "\t(default 1.0)", "E", 1, "-E"));
Expand Down Expand Up @@ -334,14 +336,17 @@ public void buildClassifier(Instances ds) throws Exception {
ds.deleteWithMissingClass();

//if this is a dataset with only the class attribute
if (ds.numAttributes() == 1 || this.m_forestSize > ds.numInstances()) {
if (ds.numAttributes() == 1 || this.m_forestSize > ds.numInstances() || this.m_numDisplayTrees > this.m_forestSize) {

if(ds.numAttributes() == 1) {
errorMessage += "This is a dataset with only the class value and cannot be used.\n";
}
if(this.m_forestSize > ds.numInstances()) {
errorMessage += "The forest size has been set higher than the number of instances in the dataset so the forest cannot be build.\n";
}
if(this.m_numDisplayTrees > this.m_forestSize) {
errorMessage += "Number of display trees can not be larger than the number of trees in the forest.\n";
}

ZeroR zr = new ZeroR();
zr.buildClassifier(ds);
Expand Down Expand Up @@ -1498,7 +1503,7 @@ protected String defaultComparisonClassifierString() {
* </pre>
*
* <pre>
* -T &lt;tree depth&gt;
* -R &lt;tree depth&gt;
* Tree depth option. If &lt;= 0 will be equal to the tree depth
* calculation from the paper
* (default -1)
Expand Down Expand Up @@ -1543,7 +1548,7 @@ public void setOptions(String[] options) throws Exception {
setForestSize(10);
}

String sTreeDepthOption = Utils.getOption('T', options);
String sTreeDepthOption = Utils.getOption('R', options);
if (sNumberTrees.length() != 0) {
setTreeDepthOption(Integer.parseInt(sTreeDepthOption));
} else {
Expand Down Expand Up @@ -1614,10 +1619,8 @@ public String[] getOptions() {
result.add("-D");
result.add("" + getNumDisplayTrees());

if(m_treeDepthOption <= 0) {
result.add("-T");
result.add("" + getTreeDepthOption());
}
result.add("-R");
result.add("" + getTreeDepthOption());

result.add("-E");
result.add("" + getPrivacyBudget());
Expand Down

0 comments on commit c826200

Please sign in to comment.