From: Julien H. <jh...@no...> - 2010-04-26 22:17:25
|
Hi Aaron, Thanks for your answer. Instead of this line code throw new RuntimeException("Type of split not allowed"); I write this following code to know which kind of summary type causes this issue : if (summary.type == Summary.CONTAINS_ABSTAIN){ throw new RuntimeException("Contains abstain not allowed"); } else if (summary.type == Summary.CONTAINS_NOABSTAIN) { throw new RuntimeException("Contains noabstain not allowed"); } else { throw new RuntimeException("Type of split not allowed"); } This is the stracktrace : Message:java.lang.RuntimeException: Contains noabstain not allowed So you are right. This is a issue of not handled splitters for python generation code. Do you know if this kind of splitters comes from finite attribute type? Because the problem appears when I put in my attribute some finite and text types. I will look the code of MakeCode method to know how to handle this splitter for python. Thanks. Regards, Julien Henot. 2010/4/26 Aaron Arvey <aa...@cb...> > Great to hear that your able to edit and compile the code! > > Can you send me the *output.tree file from the run? I'm interested to see > what kind of splitters the algorithm is using for your data. > > The types of splitter are given in src/jboost/learners/Summary.java > > public static final char EQUALITY = 1; > public static final char LESS_THAN = 2; > public static final char CONTAINS_ABSTAIN = 3; > public static final char CONTAINS_NOABSTAIN = 4; > > makePythonCode currently only works with EQUALITY and LESS_THAN. I'm not > actually familiar with the other two splitters. > > Another easy way to check what splitters are being used is to output the > following prior to the case statement: > > System.out.println("Splitter summary: " + summary.type) > > We should be able to get an exact diagnosis this way. > > Assuming this is the problem, it looks like there is some example code for > how to handle CONTAINS_ABSTAIN and CONTAINS_NOABSTAIN at lines 859-885 in > String makeCode(SplitterNode sn, String tab). > > Aaron > > > > On Mon, 26 Apr 2010, Julien Hénot wrote: > > > Hi aaron, > > > > Thanks for your answer ! > > > > I have changed the code of makePythonCode as you recommend, but I still > have > > an error: > > See the error message : > > > > Exception occured while attempting to write Python code > > Message:java.lang.RuntimeException: Type of split not allowed > > java.lang.RuntimeException: Type of split not allowed > > at > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:716) > > at > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:691) > > at > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:705) > > at > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:691) > > at > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:713) > > at > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:691) > > at > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:705) > > at > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:691) > > at jboost.atree.AlternatingTree.toPython(AlternatingTree.java:654) > > at jboost.controller.Controller.generateCode(Controller.java:694) > > at > > jboost.controller.Controller.outputLearningResults(Controller.java:273) > > at jboost.controller.Controller.main(Controller.java:91) > > > > > > For this line : 1064 ((Integer)summary.val) + ":\n"; > > I tried different casting, but I have still an error. > > > > Thanks in advance. > > > > Regards, > > Julien. > > > > > > 2010/4/23 Aaron Arvey <aa...@cb...> > > > > > Hi Julien, > > > > > > First, thanks for the detailed error message. > > > > > > While I'm no longer a main developer (and so I won't edit the public > > > repository), it looks like the problem is a simple typo. > > > > > > In AlternatingTree.java, there should be code that looks like this > (line > > > numbers may not match up): > > > > > > 1051 private String makePythonCode(SplitterNode sn, String tab) { > > > 1052 String code = ""; > > > 1053 > > > 1054 Summary summary=sn.splitter.getSummary(); > > > 1055 > > > 1056 code += tab + (allDefined > > > 1057 ? " " > > > 1058 : "if def(" + (summary.index+1) + "):") > > > 1059 + " # " + sn.id + "\n"; > > > 1060 String stab = (allDefined ? tab : tab); > > > 1061 switch(summary.type) { > > > 1062 case Summary.EQUALITY: > > > 1063 code += stab + "if self.get_data_value(x,'" + > > > ad[(summary.index)].getAttributeName() + "') == " + > > > 1064 ((Integer)summary.val) + ":\n"; > > > 1065 code += makeMatlabCode(sn.predictorNodes[0], stab + "\t"); > > > 1066 code += stab + "else:\n"; > > > 1067 code += makeMatlabCode(sn.predictorNodes[1], stab + "\t"); > > > 1068 break; > > > 1069 case Summary.LESS_THAN: > > > 1070 code += stab + "if self.get_data_value(x,'" + > > > ad[(summary.index)].getAttributeName() + "') <= " + > > > 1071 ((Double) summary.val) + ":\n"; > > > 1072 code += makePythonCode(sn.predictorNodes[0], stab + "\t"); > > > 1073 code += stab + "else:\n"; > > > 1074 code += makePythonCode(sn.predictorNodes[1], stab + "\t"); > > > 1075 break; > > > 1076 default: > > > 1077 throw new RuntimeException("Type of split not allowed"); > > > 1078 } > > > 1079 > > > 1080 return code; > > > 1081 } > > > > > > > > > Notice the three lines: > > > > > > 1065 code += makeMatlabCode(sn.predictorNodes[0], stab + "\t"); > > > 1066 code += stab + "else:\n"; > > > 1067 code += makeMatlabCode(sn.predictorNodes[1], stab + "\t"); > > > > > > These calls should be changed to recursively call the Python method > > > whereas they are currently calling the matlab method: > > > > > > 1065 code += makePythonCode(sn.predictorNodes[0], stab + "\t"); > > > 1066 code += stab + "else:\n"; > > > 1067 code += makePythonCode(sn.predictorNodes[1], stab + "\t"); > > > > > > You may also have to change the line > > > > > > 1064 ((Integer)summary.val) + ":\n"; > > > > > > So that it can handle strings (though the strings may be converted to > > > integers, and this may be easier to edit once the python code has been > > > outputted using a dictionary, etc). I don't remember the exact > internal > > > string representation, but you can email again if you have further > > > problems. > > > > > > Running 'ant jar' or 'ant dist' in the top directory will compile the > code > > > (make sure the file 'JBOOST_DIR/dist/jboost.jar' has been updated). > > > > > > Aaron > > > > > > > > > > > > On Fri, 23 Apr 2010, Julien Hénot wrote: > > > > > > > Hi all, > > > > > > > > I am a new user of JBoost and I'm very enthusiastic and happy to use > it. > > > > It's really simple to start and I succeed easily in having some good > > > > results. > > > > > > > > I would ask you a little question. > > > > > > > > When I run my Jboost command with generation of python code, I have > this > > > > exception : > > > > > > > > Exception occured while attempting to write Python code > > > > Message:java.lang.RuntimeException: Type of split not allowed > > > > java.lang.RuntimeException: Type of split not allowed > > > > at > > > jboost.atree.AlternatingTree.makeMatlabCode(AlternatingTree.java:780) > > > > at > > > jboost.atree.AlternatingTree.makeMatlabCode(AlternatingTree.java:751) > > > > at > > > jboost.atree.AlternatingTree.makeMatlabCode(AlternatingTree.java:765) > > > > at > > > jboost.atree.AlternatingTree.makeMatlabCode(AlternatingTree.java:751) > > > > at > > > jboost.atree.AlternatingTree.makeMatlabCode(AlternatingTree.java:775) > > > > at > > > jboost.atree.AlternatingTree.makeMatlabCode(AlternatingTree.java:751) > > > > at > > > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:705) > > > > at > > > jboost.atree.AlternatingTree.makePythonCode(AlternatingTree.java:691) > > > > at > jboost.atree.AlternatingTree.toPython(AlternatingTree.java:654) > > > > at jboost.controller.Controller.generateCode(Controller.java:694) > > > > at > > > > > jboost.controller.Controller.outputLearningResults(Controller.java:273) > > > > at jboost.controller.Controller.main(Controller.java:91) > > > > > > > > > > > > Have you an idea ? I look the code but I did not succeed to fix the > > > problem. > > > > > > > > I have different types of value in my spec file : number, text, and > > > finite > > > > (none,same,not) > > > > > > > > Thanks in advance, > > > > > > > > Regards, > > > > Julien Henot > > > > > > > > > > |