source: src/main/java/agents/anac/y2013/MetaAgent/parser/cart/tree/Node.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 3.3 KB
Line 
1package agents.anac.y2013.MetaAgent.parser.cart.tree;
2import java.util.HashMap;
3import java.util.Vector;
4
5
6public abstract class Node {
7
8int _id;
9int _observations;
10int _leftId;
11int _rightId;
12int _leftobs;
13int _rightObs;
14Node _left;
15Node _right;
16double _complexityParam;
17Vector<PrimarySplit> _primary_splits;
18Vector<SurrogateSplit> _Surrogate_splits;
19
20enum treeType{
21 MEAN,ESTIMATED
22}
23
24protected Node(int _id, int _observations, int _leftId, int _rightId,
25 int _leftobs, int _rightObs, double _complexityParam,Vector<PrimarySplit> _primary_splits,
26 Vector<SurrogateSplit> _Surrogate_splits) {
27 super();
28 this._id = _id;
29 this._observations = _observations;
30 this._leftId = _leftId;
31 this._rightId = _rightId;
32 this._leftobs = _leftobs;
33 this._rightObs = _rightObs;
34 this._complexityParam = _complexityParam;
35 this._primary_splits = _primary_splits;
36 this._Surrogate_splits = _Surrogate_splits;
37}
38
39
40protected static Vector< PrimarySplit> parsePrimarySplits(String[] splitsText) {
41 Vector< PrimarySplit> splits=new Vector<PrimarySplit>();
42 for (String string : splitsText) {
43 PrimarySplit s=PrimarySplit.factory(string);
44 splits.add(s );
45 }
46 return splits;
47}
48
49protected static Vector< SurrogateSplit> parseSurrogateSplits(String[] splitsText) {
50 Vector< SurrogateSplit> splits=new Vector<SurrogateSplit>();
51 for (String string : splitsText) {
52 SurrogateSplit s=SurrogateSplit.factory(string);
53 splits.add(s );
54 }
55 return splits;
56}
57
58
59public int get_id() {
60 return _id;
61}
62public int get_leftId() {
63 return _leftId;
64}
65public int get_rightId() {
66 return _rightId;
67}
68public Node get_left() {
69 return _left;
70}
71public void set_left(Node _left) {
72 this._left = _left;
73}
74public Node get_right() {
75 return _right;
76}
77public void set_right(Node _right) {
78 this._right = _right;
79}
80protected static int parseObs(String text, String dir) {
81 text=substring(text, dir,"obs)");
82 return Integer.parseInt(text.split(" ")[2].substring(1));
83}
84public static String substring(String s,String from,String to){
85 s=s.substring(s.indexOf(from)+from.length());
86 if(s.indexOf(to)!=-1)
87 s=s.substring(0,s.indexOf(to));
88
89 return s;
90}
91public static String substring(String s,String from,int to){
92 return s.substring(s.indexOf(from)+from.length(),to);
93}
94
95public Node getBestNode(HashMap<String,Double> values){
96 if(isLeaf()){
97 return this;
98 }
99 else return navigate(values);
100}
101protected Node navigate(HashMap<String, Double> values) {
102 if(this._primary_splits!=null){
103 PrimarySplit.Direction dir=this._primary_splits.get(0).getDirection(values);
104 switch (dir) {
105 case LEFT:{
106 return this._left.getBestNode(values);
107 }
108 case RIGHT:{
109 return this._right.getBestNode(values);
110 }
111 default:
112 break;
113 }
114 }
115 if(this._Surrogate_splits!=null){
116 PrimarySplit.Direction dir=this._Surrogate_splits.get(0).getDirection(values);
117 switch (dir) {
118 case LEFT:{
119// System.out.println(this.get_id() +" choose left" );
120 return this._left.getBestNode(values);
121 }
122 case RIGHT:{
123// System.out.println(this.get_id() +" choose right");
124 return this._right.getBestNode(values);
125 }
126 default:
127 break;
128 }
129 }
130 return null;
131}
132protected boolean isLeaf(){
133 if(this._left==null&&this._right==null)
134 return true;
135 return false;
136}
137
138
139public abstract double get_mean();
140public abstract double get_estimated_rate();
141}
Note: See TracBrowser for help on using the repository browser.