- Timestamp:
- 07/18/16 12:26:03 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/training/QuadTree.java
r86 r135 24 24 25 25 /** 26 * QuadTree implementation 26 * <p> 27 * QuadTree implementation. 28 * </p> 29 * <p> 30 * QuadTree gets a list of instances and then recursively split them into 4 children For this it 31 * uses the median of the 2 values x,y. 32 * </p> 27 33 * 28 * QuadTree gets a list of instances and then recursively split them into 4 childs For this it uses 29 * the median of the 2 values x,y 34 * @author Alexander Trautsch 30 35 */ 31 36 public class QuadTree { 32 37 33 /* 1 parent or null */ 38 /** 39 * 1 parent or null 40 */ 34 41 private QuadTree parent = null; 35 42 36 /* 4 childs, 1 per quadrant */ 43 /** 44 * north-west quadrant 45 */ 37 46 private QuadTree child_nw; 47 48 /** 49 * north-east quadrant 50 */ 38 51 private QuadTree child_ne; 52 53 /** 54 * south-east quadrant 55 */ 39 56 private QuadTree child_se; 57 58 /** 59 * south-west quadrant 60 */ 40 61 private QuadTree child_sw; 41 62 42 /* list (only helps with generation of list of childs!) */ 63 /** 64 * helper list for child quadrant generation 65 */ 43 66 private ArrayList<QuadTree> l = new ArrayList<QuadTree>(); 44 67 45 /* level only used for debugging */ 68 /** 69 * debugging attribute 70 */ 46 71 public int level = 0; 47 72 48 /* size of the quadrant */ 73 /** 74 * size of the quadrant in x-dimension 75 */ 49 76 private double[] x; 77 78 /** 79 * size of the quadrant in y-dimension 80 */ 50 81 private double[] y; 51 82 83 /** 84 * debugging parameter 85 */ 52 86 public static boolean verbose = false; 87 88 /** 89 * global size of the QuadTree. 90 */ 53 91 public static int size = 0; 92 93 /** 94 * recursion parameter alpha 95 */ 54 96 public static double alpha = 0; 55 97 56 /* cluster payloads */ 98 /** 99 * data for each cluster 100 */ 57 101 public static ArrayList<ArrayList<QuadTreePayload<Instance>>> ccluster = 58 102 new ArrayList<ArrayList<QuadTreePayload<Instance>>>(); 59 103 60 /* cluster sizes (index is cluster number, arraylist is list of boxes (x0,y0,x1,y1) */ 104 /** 105 * cluster sizes (index is cluster number, {@link ArrayList} is list of boxes (x0,y0,x1,y1 106 */ 61 107 public static HashMap<Integer, ArrayList<Double[][]>> csize = 62 108 new HashMap<Integer, ArrayList<Double[][]>>(); 63 109 64 /* payload of this instance */ 110 /** 111 * data within this quadrant 112 */ 65 113 private ArrayList<QuadTreePayload<Instance>> payload; 66 114 115 /** 116 * <p> 117 * Constructor. Creates a new QuadTree. 118 * </p> 119 * 120 * @param parent 121 * parent of this tree 122 * @param payload 123 * data within the quadrant 124 */ 67 125 public QuadTree(QuadTree parent, ArrayList<QuadTreePayload<Instance>> payload) { 68 126 this.parent = parent; … … 70 128 } 71 129 130 /* 131 * (non-Javadoc) 132 * 133 * @see java.lang.Object#toString() 134 */ 135 @Override 72 136 public String toString() { 73 137 String n = ""; … … 81 145 82 146 /** 147 * <p> 83 148 * Returns the payload, used for clustering in the clustering list we only have children with 84 * paylod 85 * 86 * @return payload 149 * payload 150 * </p> 151 * 152 * @return payload the payload 87 153 */ 88 154 public ArrayList<QuadTreePayload<Instance>> getPayload() { … … 91 157 92 158 /** 93 * Calculate the density of this quadrant 94 * 95 * density = number of instances / global size (all instances) 96 * 97 * @return density 159 * <p> 160 * Calculate the density of this quadrant as 161 * <ul> 162 * <li>density = number of instances / global size (all instances)</li> 163 * </ul> 164 * 165 * @return density the density 98 166 */ 99 167 public double getDensity() { … … 103 171 } 104 172 173 /** 174 * <p> 175 * sets the size coordinates of the quadrant 176 * </p> 177 * 178 * @param x 179 * x-dimension 180 * @param y 181 * y-dimension 182 */ 105 183 public void setSize(double[] x, double[] y) { 106 184 this.x = x; … … 108 186 } 109 187 188 /** 189 * <p> 190 * returns the size of the quadrant 191 * </p> 192 * 193 * @return size of the current quadrant 194 */ 110 195 public double[][] getSize() { 111 196 return new double[][] … … 113 198 } 114 199 200 /** 201 * <p> 202 * returns the size of the quadrant 203 * </p> 204 * 205 * @return size of the current quadrant 206 */ 115 207 public Double[][] getSizeDouble() { 116 208 Double[] tmpX = new Double[2]; … … 128 220 129 221 /** 130 * TODO: DRY, median ist immer dasselbe 222 * <p> 223 * calculates the median for the x axis 224 * </p> 131 225 * 132 226 * @return median for x … … 161 255 } 162 256 257 /** 258 * <p> 259 * calculates the median for the y axis 260 * </p> 261 * 262 * @return median for y 263 */ 163 264 private double getMedianForY() { 164 265 double med_y = 0; … … 191 292 192 293 /** 193 * Reurns the number of instances in the payload 194 * 195 * @return int number of instances 294 * <p> 295 * Returns the number of instances in the payload 296 * </p> 297 * 298 * @return number of instances 196 299 */ 197 300 public int getNumbers() { … … 204 307 205 308 /** 309 * <p> 206 310 * Calculate median values of payload for x, y and split into 4 sectors 311 * </p> 207 312 * 208 313 * @return Array of QuadTree nodes (4 childs) … … 295 400 296 401 /** 297 * TODO: static method 298 * 402 * <p> 403 * creates the children of a QuadTree and recursively splits them as well 404 * </p> 405 * 299 406 * @param q 300 */ 301 public void recursiveSplit(QuadTree q) { 407 * tree that is split 408 */ 409 public static void recursiveSplit(QuadTree q) { 302 410 if (QuadTree.verbose) { 303 411 System.out.println("splitting: " + q); … … 310 418 try { 311 419 QuadTree[] childs = q.split(); 312 this.recursiveSplit(childs[0]);313 this.recursiveSplit(childs[1]);314 this.recursiveSplit(childs[2]);315 this.recursiveSplit(childs[3]);420 recursiveSplit(childs[0]); 421 recursiveSplit(childs[1]); 422 recursiveSplit(childs[2]); 423 recursiveSplit(childs[3]); 316 424 } 317 425 catch (Exception e) { … … 322 430 323 431 /** 324 * returns an list of childs sorted by density 432 * <p> 433 * returns an list of children sorted by density 434 * </p> 325 435 * 326 436 * @param q 327 437 * QuadTree 328 * @return list of QuadTrees329 438 */ 330 439 private void generateList(QuadTree q) { … … 350 459 351 460 /** 461 * <p> 352 462 * Checks if passed QuadTree is neighboring to us 463 * </p> 353 464 * 354 465 * @param q … … 396 507 397 508 /** 509 * <p> 398 510 * Perform pruning and clustering of the quadtree 399 * 511 * </p> 512 * <p> 400 513 * Pruning according to: Tim Menzies, Andrew Butcher, David Cok, Andrian Marcus, Lucas Layman, 401 514 * Forrest Shull, Burak Turhan, Thomas Zimmermann, 402 515 * "Local versus Global Lessons for Defect Prediction and Effort Estimation," IEEE Transactions 403 516 * on Software Engineering, vol. 39, no. 6, pp. 822-834, June, 2013 404 * 405 * 1) get list of leaf quadrants 2) sort by their density 3) set stop_rule to 0.5 * highest 406 * Density in the list 4) merge all nodes with a density > stop_rule to the new cluster and 407 * remove all from list 5) repeat 517 * </p> 518 * <ol> 519 * <li>get list of leaf quadrants</li> 520 * <li>sort by their density</li> 521 * <li>set stop_rule to 0.5*highest Density in the list</li> 522 * <li>merge all nodes with a density > stop_rule to the new cluster and remove all from list 523 * </li> 524 * <li>repeat</li> 525 * </ol> 408 526 * 409 527 * @param q … … 479 597 } 480 598 599 /** 600 * <p> 601 * debugging function that prints information about the QuadTree 602 * </p> 603 * 604 */ 481 605 public void printInfo() { 482 606 System.out.println("we have " + ccluster.size() + " clusters"); … … 488 612 489 613 /** 614 * <p> 490 615 * Helper Method to get a sorted list (by density) for all children 616 * </p> 491 617 * 492 618 * @param q
Note: See TracChangeset
for help on using the changeset viewer.