- 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/GPTraining.java
r125 r135 1 1 2 package de.ugoe.cs.cpdp.training; 2 3 … … 45 46 * Genetic Programming Trainer 46 47 * 47 * Implementation (mostly) according to Liu et al. Evolutionary Optimization of Software Quality Modeling with Multiple Repositories. 48 * Implementation (mostly) according to Liu et al. Evolutionary Optimization of Software Quality 49 * Modeling with Multiple Repositories. 48 50 * 49 * - GPRun is a Run of a complete Genetic Programm Evolution, we want several complete runs. 50 * - GPVClassifier is the Validation Classifier 51 * - GPVVClassifier is the Validation-Voting Classifier 51 * - GPRun is a Run of a complete Genetic Programm Evolution, we want several complete runs. - 52 * GPVClassifier is the Validation Classifier - GPVVClassifier is the Validation-Voting Classifier 52 53 * 53 * config: <setwisetrainer name="GPTraining" param="populationSize:1000,numberRuns:10" /> 54 * config: <setwisetrainer name="GPTraining" param="populationSize:1000,numberRuns:10" /> 55 * 56 * @author Alexander Trautsch 54 57 */ 55 public class GPTraining implements ISetWiseTrainingStrategy, IWekaCompatibleTrainer { 56 58 public class GPTraining implements ISetWiseTrainingStrategy, IWekaCompatibleTrainer { 59 60 /** 61 * the interal validation-and-voting classifier 62 */ 57 63 private GPVVClassifier classifier = null; 58 59 // default values from the paper 64 65 /** 66 * size of the population of the genetic program; default from the paper is 1000 67 */ 60 68 private int populationSize = 1000; 69 70 /** 71 * minimal depth of the S-expression tree at the start of the training; default from the paper 72 * is 2 73 */ 61 74 private int initMinDepth = 2; 75 76 /** 77 * maximal depth of the S-expression tree at the start of the training; default from the paper 78 * is 6 79 */ 62 80 private int initMaxDepth = 6; 81 82 /** 83 * size of the tournaments used for selection; default from the paper is 7 84 */ 63 85 private int tournamentSize = 7; 86 87 /** 88 * number of genetic generations considered (i.e., number of iterations; default from the paper 89 * is 50 90 */ 64 91 private int maxGenerations = 50; 92 93 /** 94 * weight factor for the prediction errors for cost estimation; default from the paper is 15 95 */ 65 96 private double errorType2Weight = 15; 66 private int numberRuns = 20; // im paper 20 per errorType2Weight then additional 20 67 private int maxDepth = 20; // max depth within one program 68 private int maxNodes = 100; // max nodes within one program 69 97 98 /** 99 * number of internal replications from which the best result is picked; default from the paper 100 * is 20 101 */ 102 private int numberRuns = 20; 103 104 /** 105 * maximal depth of the S-expression tree; default from the paper is 20 106 */ 107 private int maxDepth = 20; 108 109 /** 110 * maximal number of nodes of the S-expression tree; default from the paper is 100 111 */ 112 private int maxNodes = 100; 113 114 /* 115 * (non-Javadoc) 116 * 117 * @see de.ugoe.cs.cpdp.IParameterizable#setParameter(java.lang.String) 118 */ 70 119 @Override 71 120 public void setParameter(String parameters) { 72 121 73 122 String[] params = parameters.split(","); 74 123 String[] keyvalue = new String[2]; 75 124 76 for (int i=0; i < params.length; i++) {125 for (int i = 0; i < params.length; i++) { 77 126 keyvalue = params[i].split(":"); 78 79 switch(keyvalue[0]) { 127 128 switch (keyvalue[0]) 129 { 80 130 case "populationSize": 81 131 this.populationSize = Integer.parseInt(keyvalue[1]); 82 break;83 132 break; 133 84 134 case "initMinDepth": 85 135 this.initMinDepth = Integer.parseInt(keyvalue[1]); 86 break;87 136 break; 137 88 138 case "tournamentSize": 89 139 this.tournamentSize = Integer.parseInt(keyvalue[1]); 90 break;91 140 break; 141 92 142 case "maxGenerations": 93 143 this.maxGenerations = Integer.parseInt(keyvalue[1]); 94 break;95 144 break; 145 96 146 case "errorType2Weight": 97 147 this.errorType2Weight = Double.parseDouble(keyvalue[1]); 98 break;99 148 break; 149 100 150 case "numberRuns": 101 151 this.numberRuns = Integer.parseInt(keyvalue[1]); 102 break;103 152 break; 153 104 154 case "maxDepth": 105 155 this.maxDepth = Integer.parseInt(keyvalue[1]); 106 break;107 156 break; 157 108 158 case "maxNodes": 109 159 this.maxNodes = Integer.parseInt(keyvalue[1]); 110 break;111 } 112 } 113 160 break; 161 } 162 } 163 114 164 this.classifier = new GPVVClassifier(); 115 ((GPVClassifier)this.classifier).configure(populationSize, initMinDepth, initMaxDepth, tournamentSize, maxGenerations, errorType2Weight, numberRuns, maxDepth, maxNodes); 165 ((GPVClassifier) this.classifier) 166 .configure(populationSize, initMinDepth, initMaxDepth, tournamentSize, maxGenerations, 167 errorType2Weight, numberRuns, maxDepth, maxNodes); 116 168 } 117 169 170 /* 171 * (non-Javadoc) 172 * 173 * @see 174 * de.ugoe.cs.cpdp.training.ISetWiseTrainingStrategy#apply(org.apache.commons.collections4.list. 175 * SetUniqueList) 176 */ 118 177 @Override 119 178 public void apply(SetUniqueList<Instances> traindataSet) { 120 179 try { 121 180 classifier.buildClassifier(traindataSet); 122 }catch(Exception e) { 181 } 182 catch (Exception e) { 123 183 throw new RuntimeException(e); 124 184 } 125 185 } 126 186 187 /* 188 * (non-Javadoc) 189 * 190 * @see de.ugoe.cs.cpdp.training.ISetWiseTrainingStrategy#getName() 191 */ 127 192 @Override 128 193 public String getName() { … … 130 195 } 131 196 197 /* 198 * (non-Javadoc) 199 * 200 * @see de.ugoe.cs.cpdp.training.IWekaCompatibleTrainer#getClassifier() 201 */ 132 202 @Override 133 203 public Classifier getClassifier() { 134 204 return this.classifier; 135 205 } 136 206 207 /** 208 * <p> 209 * Internal helper class that stores the data in a format that can be used by the genetic 210 * program. 211 * </p> 212 * 213 * @author Alexander Trautsch 214 */ 137 215 public class InstanceData { 216 217 /** 218 * instances values 219 */ 138 220 private double[][] instances_x; 221 222 /** 223 * class labels 224 */ 139 225 private boolean[] instances_y; 140 226 227 /** 228 * <p> 229 * Constructor. Creates the internal data representation. 230 * </p> 231 * 232 * @param instances 233 */ 141 234 public InstanceData(Instances instances) { 142 this.instances_x = new double[instances.numInstances()][instances.numAttributes() -1];235 this.instances_x = new double[instances.numInstances()][instances.numAttributes() - 1]; 143 236 this.instances_y = new boolean[instances.numInstances()]; 144 237 145 238 Instance current; 146 for (int i=0; i < this.instances_x.length; i++) {239 for (int i = 0; i < this.instances_x.length; i++) { 147 240 current = instances.get(i); 148 241 this.instances_x[i] = WekaUtils.instanceValues(current); … … 150 243 } 151 244 } 152 245 246 /** 247 * <p> 248 * returns the instance values 249 * </p> 250 * 251 * @return 252 */ 153 253 public double[][] getX() { 154 254 return instances_x; 155 255 } 256 257 /** 258 * <p> 259 * returns the instance labels 260 * </p> 261 * 262 * @return 263 */ 156 264 public boolean[] getY() { 157 265 return instances_y; 158 266 } 159 267 } 160 268 161 269 /** 162 270 * One Run executed by a GP Classifier 163 271 */ 164 272 public class GPRun extends AbstractClassifier { 273 274 /** 275 * generated serialization ID 276 */ 165 277 private static final long serialVersionUID = -4250422550107888789L; 166 278 279 /** 280 * size of the population of the genetic program 281 */ 167 282 private int populationSize; 283 284 /** 285 * minimal depth of the S-expression tree at the start of the training 286 */ 168 287 private int initMinDepth; 288 289 /** 290 * maximal depth of the S-expression tree at the start of the training 291 */ 169 292 private int initMaxDepth; 293 294 /** 295 * size of the tournaments used for selection 296 */ 170 297 private int tournamentSize; 298 299 /** 300 * number of genetic generations considered (i.e., number of iterations 301 */ 171 302 private int maxGenerations; 303 304 /** 305 * weight factor for the prediction errors for cost estimation 306 */ 172 307 private double errorType2Weight; 308 309 /** 310 * maximal depth of the S-expression tree 311 */ 173 312 private int maxDepth; 313 314 /** 315 * maximal number of nodes of the S-expression tree 316 */ 174 317 private int maxNodes; 175 318 319 /** 320 * genetic program 321 */ 176 322 private GPGenotype gp; 323 324 /** 325 * description of the problem to be solved by the genetic program 326 */ 177 327 private GPProblem problem; 178 179 public void configure(int populationSize, int initMinDepth, int initMaxDepth, int tournamentSize, int maxGenerations, double errorType2Weight, int maxDepth, int maxNodes) { 328 329 /** 330 * <p> 331 * Configures the runner 332 * </p> 333 * 334 * @param populationSize 335 * the population size 336 * @param initMinDepth 337 * the initial minimal depth of the S-expression tree 338 * @param initMaxDepth 339 * the initial maximal depth of the S-expression tree 340 * @param tournamentSize 341 * the tournament size for selection 342 * @param maxGenerations 343 * the number of generations created 344 * @param errorType2Weight 345 * weigth factor for the prediction errors 346 * @param maxDepth 347 * maximal depth of the S-expression tree 348 * @param maxNodes 349 * maximal number of nodes of the S-expression tree 350 */ 351 public void configure(int populationSize, 352 int initMinDepth, 353 int initMaxDepth, 354 int tournamentSize, 355 int maxGenerations, 356 double errorType2Weight, 357 int maxDepth, 358 int maxNodes) 359 { 180 360 this.populationSize = populationSize; 181 361 this.initMinDepth = initMinDepth; … … 187 367 this.maxNodes = maxNodes; 188 368 } 189 369 370 /** 371 * <p> 372 * returns the genetic program 373 * </p> 374 * 375 * @return the genetic program 376 */ 190 377 public GPGenotype getGp() { 191 378 return this.gp; 192 379 } 193 380 381 /** 382 * <p> 383 * returns the variables of the genetic program 384 * </p> 385 * 386 * @return the variables 387 */ 194 388 public Variable[] getVariables() { 195 return ((CrossPareGP)this.problem).getVariables(); 196 } 197 389 return ((CrossPareGP) this.problem).getVariables(); 390 } 391 392 /* 393 * (non-Javadoc) 394 * 395 * @see weka.classifiers.Classifier#buildClassifier(weka.core.Instances) 396 */ 198 397 @Override 199 398 public void buildClassifier(Instances traindata) throws Exception { 200 InstanceData train = new InstanceData(traindata); 201 this.problem = new CrossPareGP(train.getX(), train.getY(), this.populationSize, this.initMinDepth, this.initMaxDepth, this.tournamentSize, this.errorType2Weight, this.maxDepth, this.maxNodes); 399 InstanceData train = new InstanceData(traindata); 400 this.problem = 401 new CrossPareGP(train.getX(), train.getY(), this.populationSize, this.initMinDepth, 402 this.initMaxDepth, this.tournamentSize, this.errorType2Weight, 403 this.maxDepth, this.maxNodes); 202 404 this.gp = problem.create(); 203 405 this.gp.evolve(this.maxGenerations); 204 406 } 205 407 206 408 /** 207 409 * GPProblem implementation 410 * 411 * @author Alexander Trautsch 208 412 */ 209 413 class CrossPareGP extends GPProblem { 414 415 /** 416 * Instance values of the training data 417 */ 210 418 private double[][] instances; 419 420 /** 421 * Classifications of the training data 422 */ 211 423 private boolean[] output; 212 424 425 /** 426 * maximal depth of the S-expression tree 427 */ 213 428 private int maxDepth; 429 430 /** 431 * maximal number of nodes of the S-expression tree 432 */ 214 433 private int maxNodes; 215 434 435 /** 436 * variables of the genetic program 437 */ 216 438 private Variable[] x; 217 439 218 public CrossPareGP(double[][] instances, boolean[] output, int populationSize, int minInitDept, int maxInitDepth, int tournamentSize, double errorType2Weight, int maxDepth, int maxNodes) throws InvalidConfigurationException { 440 /** 441 * 442 * <p> 443 * Constructor. Creates a new genetic program. 444 * </p> 445 * 446 * @param instances 447 * instance values of the training data 448 * @param output 449 * classifications of the training data 450 * @param populationSize 451 * the population size 452 * @param initMinDepth 453 * the initial minimal depth of the S-expression tree 454 * @param initMaxDepth 455 * the initial maximal depth of the S-expression tree 456 * @param tournamentSize 457 * the tournament size for selection 458 * @param maxGenerations 459 * the number of generations created 460 * @param errorType2Weight 461 * weigth factor for the prediction errors 462 * @param maxDepth 463 * maximal depth of the S-expression tree 464 * @param maxNodes 465 * maximal number of nodes of the S-expression tree 466 * @throws InvalidConfigurationException 467 * thrown in case the problem cannot be created 468 */ 469 public CrossPareGP(double[][] instances, 470 boolean[] output, 471 int populationSize, 472 int minInitDept, 473 int maxInitDepth, 474 int tournamentSize, 475 double errorType2Weight, 476 int maxDepth, 477 int maxNodes) 478 throws InvalidConfigurationException 479 { 219 480 super(new GPConfiguration()); 220 481 221 482 this.instances = instances; 222 483 this.output = output; … … 226 487 Configuration.reset(); 227 488 GPConfiguration config = this.getGPConfiguration(); 228 489 229 490 this.x = new Variable[this.instances[0].length]; 230 231 for(int j=0; j < this.x.length; j++) { 232 this.x[j] = Variable.create(config, "X"+j, CommandGene.DoubleClass); 233 } 234 235 config.setGPFitnessEvaluator(new DeltaGPFitnessEvaluator()); // smaller fitness is better 236 //config.setGPFitnessEvaluator(new DefaultGPFitnessEvaluator()); // bigger fitness is better 491 492 for (int j = 0; j < this.x.length; j++) { 493 this.x[j] = Variable.create(config, "X" + j, CommandGene.DoubleClass); 494 } 495 496 config.setGPFitnessEvaluator(new DeltaGPFitnessEvaluator()); // smaller fitness is 497 // better 498 // config.setGPFitnessEvaluator(new DefaultGPFitnessEvaluator()); // bigger fitness 499 // is better 237 500 238 501 config.setMinInitDepth(minInitDept); 239 502 config.setMaxInitDepth(maxInitDepth); 240 241 config.setCrossoverProb((float) 0.60);242 config.setReproductionProb((float) 0.10);243 config.setMutationProb((float) 0.30);503 504 config.setCrossoverProb((float) 0.60); 505 config.setReproductionProb((float) 0.10); 506 config.setMutationProb((float) 0.30); 244 507 245 508 config.setSelectionMethod(new TournamentSelector(tournamentSize)); … … 248 511 249 512 config.setMaxCrossoverDepth(4); 250 config.setFitnessFunction(new CrossPareFitness(this.x, this.instances, this.output, errorType2Weight)); 513 config.setFitnessFunction(new CrossPareFitness(this.x, this.instances, this.output, 514 errorType2Weight)); 251 515 config.setStrictProgramCreation(true); 252 516 } 253 517 254 // used for running the fitness function again for testing 518 /** 519 * <p> 520 * Returns the variables of the problem. Used for running the fitness function again for 521 * testing. 522 * </p> 523 * 524 * @return the variables 525 */ 255 526 public Variable[] getVariables() { 256 527 return this.x; 257 528 } 258 529 259 530 /** 531 * creates the genetic program 532 */ 533 @SuppressWarnings("rawtypes") 260 534 public GPGenotype create() throws InvalidConfigurationException { 261 535 GPConfiguration config = this.getGPConfiguration(); 262 536 263 537 // return type 264 Class[] types = {CommandGene.DoubleClass}; 538 Class[] types = 539 { CommandGene.DoubleClass }; 265 540 266 541 // Arguments of result-producing chromosome: none 267 Class[][] argTypes = { {} }; 542 Class[][] argTypes = 543 { { } }; 268 544 269 545 // variables + functions, we set the variables with the values of the instances here 270 546 CommandGene[] vars = new CommandGene[this.instances[0].length]; 271 for (int j=0; j < this.instances[0].length; j++) {547 for (int j = 0; j < this.instances[0].length; j++) { 272 548 vars[j] = this.x[j]; 273 549 } 274 CommandGene[] funcs = { 275 new Add(config, CommandGene.DoubleClass), 276 new Subtract(config, CommandGene.DoubleClass), 277 new Multiply(config, CommandGene.DoubleClass), 278 new Divide(config, CommandGene.DoubleClass), 279 new Sine(config, CommandGene.DoubleClass), 280 new Cosine(config, CommandGene.DoubleClass), 281 new Exp(config, CommandGene.DoubleClass), 282 new Log(config, CommandGene.DoubleClass), 283 new GT(config, CommandGene.DoubleClass), 284 new Max(config, CommandGene.DoubleClass), 285 new Terminal(config, CommandGene.DoubleClass, -100.0, 100.0, true), // min, max, whole numbers 286 }; 287 288 CommandGene[] comb = (CommandGene[])ArrayUtils.addAll(vars, funcs); 289 CommandGene[][] nodeSets = { 290 comb, 291 }; 292 550 CommandGene[] funcs = 551 { new Add(config, CommandGene.DoubleClass), 552 new Subtract(config, CommandGene.DoubleClass), 553 new Multiply(config, CommandGene.DoubleClass), 554 new Divide(config, CommandGene.DoubleClass), 555 new Sine(config, CommandGene.DoubleClass), 556 new Cosine(config, CommandGene.DoubleClass), 557 new Exp(config, CommandGene.DoubleClass), 558 new Log(config, CommandGene.DoubleClass), 559 new GT(config, CommandGene.DoubleClass), 560 new Max(config, CommandGene.DoubleClass), 561 new Terminal(config, CommandGene.DoubleClass, -100.0, 100.0, true), // min, 562 // max, 563 // whole 564 // numbers 565 }; 566 567 CommandGene[] comb = (CommandGene[]) ArrayUtils.addAll(vars, funcs); 568 CommandGene[][] nodeSets = 569 { comb, }; 570 293 571 // we only have one chromosome so this suffices 294 int minDepths[] = {config.getMinInitDepth()}; 295 int maxDepths[] = {this.maxDepth}; 296 GPGenotype result = GPGenotype.randomInitialGenotype(config, types, argTypes, nodeSets, minDepths, maxDepths, this.maxNodes, false); // 40 = maxNodes, true = verbose output 572 int minDepths[] = 573 { config.getMinInitDepth() }; 574 int maxDepths[] = 575 { this.maxDepth }; 576 GPGenotype result = 577 GPGenotype.randomInitialGenotype(config, types, argTypes, nodeSets, minDepths, 578 maxDepths, this.maxNodes, false); // 40 = 579 // maxNodes, 580 // true = 581 // verbose 582 // output 297 583 298 584 return result; … … 300 586 } 301 587 302 303 /** 304 * Fitness function 588 /** 589 * Internal helper class for the fitness function. 590 * 591 * @author Alexander Trautsch 305 592 */ 306 593 class CrossPareFitness extends GPFitnessFunction { 307 594 595 /** 596 * generated serialization ID 597 */ 308 598 private static final long serialVersionUID = 75234832484387L; 309 599 600 /** 601 * variables of the genetic program 602 */ 310 603 private Variable[] x; 311 604 605 /** 606 * instance values of the training data 607 */ 312 608 private double[][] instances; 609 610 /** 611 * classifications of the training data 612 */ 313 613 private boolean[] output; 314 614 615 /** 616 * weight of the error costs 617 */ 315 618 private double errorType2Weight = 1.0; 316 619 317 620 // needed in evaluate 318 //private Object[] NO_ARGS = new Object[0]; 319 621 // private Object[] NO_ARGS = new Object[0]; 622 623 /** 624 * fitness value 625 */ 320 626 private double sfitness = 0.0f; 627 628 /** 629 * type I error 630 */ 321 631 private int errorType1 = 0; 632 633 /** 634 * type II error 635 */ 322 636 private int errorType2 = 0; 323 637 324 public CrossPareFitness(Variable[] x, double[][] instances, boolean[] output, double errorType2Weight) { 638 /** 639 * <p> 640 * Constructor. Creates a new fitness function. 641 * </p> 642 * 643 * @param x 644 * variables of the genetic program 645 * @param instances 646 * instance values of the training data 647 * @param output 648 * classification of the training data 649 * @param errorType2Weight 650 * weight of the error costs 651 */ 652 public CrossPareFitness(Variable[] x, 653 double[][] instances, 654 boolean[] output, 655 double errorType2Weight) 656 { 325 657 this.x = x; 326 658 this.instances = instances; … … 329 661 } 330 662 663 /** 664 * <p> 665 * returns the type I error 666 * </p> 667 * 668 * @return type I error 669 */ 331 670 public int getErrorType1() { 332 671 return this.errorType1; 333 672 } 334 673 674 /** 675 * <p> 676 * returns the type II error 677 * </p> 678 * 679 * @return type II error 680 */ 335 681 public int getErrorType2() { 336 682 return this.errorType2; 337 683 } 338 684 685 /** 686 * <p> 687 * returns the value of the secondary fitness function 688 * </p> 689 * 690 * @return secondary fitness 691 */ 339 692 public double getSecondFitness() { 340 693 return this.sfitness; 341 694 } 342 695 696 /** 697 * <p> 698 * returns the number of training instances 699 * </p> 700 * 701 * @return number of instances 702 */ 343 703 public int getNumInstances() { 344 704 return this.instances.length; … … 346 706 347 707 /** 348 * This is the fitness function 708 * <p> 709 * The fitness function. Our fitness is best if we have the less wrong classifications, 710 * this includes a weight for type2 errors. 711 * </p> 349 712 * 350 * Our fitness is best if we have the less wrong classifications, this includes a weight for type2 errors 713 * @param program 714 * the genetic program whose fitness is evaluated. 715 * 716 * @see org.jgap.gp.GPFitnessFunction#evaluate(org.jgap.gp.IGPProgram) 351 717 */ 352 718 @Override … … 360 726 this.errorType2 = 0; 361 727 362 for(int i=0; i < this.instances.length; i++) { 363 364 // requires that we have a variable for each column of our dataset (attribute of instance) 365 for(int j=0; j < this.x.length; j++) { 728 for (int i = 0; i < this.instances.length; i++) { 729 730 // requires that we have a variable for each column of our dataset (attribute of 731 // instance) 732 for (int j = 0; j < this.x.length; j++) { 366 733 this.x[j].set(this.instances[i][j]); 367 734 } … … 370 737 value = program.execute_double(0, this.x); 371 738 372 if (value < 0.5) {373 if (this.output[i] != true) {739 if (value < 0.5) { 740 if (this.output[i] != true) { 374 741 this.errorType1 += 1; 375 742 } 376 }else { 377 if(this.output[i] == true) { 743 } 744 else { 745 if (this.output[i] == true) { 378 746 this.errorType2 += 1; 379 747 } … … 382 750 383 751 // now calc pfitness 384 pfitness = (this.errorType1 + this.errorType2Weight * this.errorType2) / this.instances.length; 752 pfitness = (this.errorType1 + this.errorType2Weight * this.errorType2) / 753 this.instances.length; 385 754 386 755 // number of nodes in the programm, if lower then 10 we assign sFitness of 10 387 756 // we can set metadata with setProgramData to save this 388 if (program.getChromosome(0).getSize(0) < 10) {757 if (program.getChromosome(0).getSize(0) < 10) { 389 758 program.setApplicationData(10.0f); 390 759 } … … 393 762 } 394 763 } 395 764 396 765 /** 397 766 * Custom GT implementation used in the GP Algorithm. 398 */ 399 public class GT extends MathCommand implements ICloneable { 400 401 private static final long serialVersionUID = 113454184817L; 402 403 public GT(final GPConfiguration a_conf, java.lang.Class a_returnType) throws InvalidConfigurationException { 404 super(a_conf, 2, a_returnType); 405 } 406 407 public String toString() { 408 return "GT(&1, &2)"; 409 } 410 411 public String getName() { 412 return "GT"; 413 } 414 415 public float execute_float(ProgramChromosome c, int n, Object[] args) { 416 float f1 = c.execute_float(n, 0, args); 417 float f2 = c.execute_float(n, 1, args); 418 419 float ret = 1.0f; 420 if(f1 > f2) { 421 ret = 0.0f; 422 } 423 424 return ret; 425 } 426 427 public double execute_double(ProgramChromosome c, int n, Object[] args) { 428 double f1 = c.execute_double(n, 0, args); 429 double f2 = c.execute_double(n, 1, args); 430 431 double ret = 1; 432 if(f1 > f2) { 433 ret = 0; 434 } 435 return ret; 436 } 437 438 public Object clone() { 439 try { 440 GT result = new GT(getGPConfiguration(), getReturnType()); 441 return result; 442 }catch(Exception ex) { 443 throw new CloneException(ex); 444 } 445 } 446 } 767 * 768 * @author Alexander Trautsch 769 */ 770 public class GT extends MathCommand implements ICloneable { 771 772 /** 773 * generated serialization ID. 774 */ 775 private static final long serialVersionUID = 113454184817L; 776 777 /** 778 * <p> 779 * Constructor. Creates a new GT. 780 * </p> 781 * 782 * @param a_conf 783 * the configuration of the genetic program 784 * @param a_returnType 785 * the return type 786 * @throws InvalidConfigurationException 787 * thrown is there is a problem during the initialization of the super class 788 * 789 * @see MathCommand 790 */ 791 public GT(final GPConfiguration a_conf, @SuppressWarnings("rawtypes") java.lang.Class a_returnType) 792 throws InvalidConfigurationException 793 { 794 super(a_conf, 2, a_returnType); 795 } 796 797 /* 798 * (non-Javadoc) 799 * 800 * @see org.jgap.gp.CommandGene#toString() 801 */ 802 @Override 803 public String toString() { 804 return "GT(&1, &2)"; 805 } 806 807 /* 808 * (non-Javadoc) 809 * 810 * @see org.jgap.gp.CommandGene#getName() 811 */ 812 @Override 813 public String getName() { 814 return "GT"; 815 } 816 817 /* 818 * (non-Javadoc) 819 * 820 * @see org.jgap.gp.CommandGene#execute_float(org.jgap.gp.impl.ProgramChromosome, int, 821 * java.lang.Object[]) 822 */ 823 @Override 824 public float execute_float(ProgramChromosome c, int n, Object[] args) { 825 float f1 = c.execute_float(n, 0, args); 826 float f2 = c.execute_float(n, 1, args); 827 828 float ret = 1.0f; 829 if (f1 > f2) { 830 ret = 0.0f; 831 } 832 833 return ret; 834 } 835 836 /* 837 * (non-Javadoc) 838 * 839 * @see org.jgap.gp.CommandGene#execute_double(org.jgap.gp.impl.ProgramChromosome, int, 840 * java.lang.Object[]) 841 */ 842 @Override 843 public double execute_double(ProgramChromosome c, int n, Object[] args) { 844 double f1 = c.execute_double(n, 0, args); 845 double f2 = c.execute_double(n, 1, args); 846 847 double ret = 1; 848 if (f1 > f2) { 849 ret = 0; 850 } 851 return ret; 852 } 853 854 /* 855 * (non-Javadoc) 856 * 857 * @see java.lang.Object#clone() 858 */ 859 @Override 860 public Object clone() { 861 try { 862 GT result = new GT(getGPConfiguration(), getReturnType()); 863 return result; 864 } 865 catch (Exception ex) { 866 throw new CloneException(ex); 867 } 868 } 869 } 447 870 } 448 871 449 872 /** 450 873 * GP Multiple Data Sets Validation-Voting Classifier 451 874 * 452 * Basically the same as the GP Multiple Data Sets Validation Classifier. 453 * But here we do keep amodel candidate for each training set which may later vote875 * Basically the same as the GP Multiple Data Sets Validation Classifier. But here we do keep a 876 * model candidate for each training set which may later vote 454 877 * 455 878 */ 456 879 public class GPVVClassifier extends GPVClassifier { 457 880 881 /** 882 * generated serialization ID 883 */ 458 884 private static final long serialVersionUID = -654710583852839901L; 885 886 /** 887 * classifiers for each validation set 888 */ 459 889 private List<Classifier> classifiers = null; 460 890 891 /* 892 * (non-Javadoc) 893 * 894 * @see 895 * de.ugoe.cs.cpdp.training.GPTraining.GPVClassifier#buildClassifier(weka.core.Instances) 896 */ 461 897 @Override 462 898 public void buildClassifier(Instances arg0) throws Exception { 463 899 // TODO Auto-generated method stub 464 465 } 466 467 /** Build the GP Multiple Data Sets Validation-Voting Classifier468 * 469 * This is according to Section 6 of the Paper by Liu et al. 470 * It is basically the MultipleData Sets Validation Classifier but here we keep the best models an let them vote.900 } 901 902 /** 903 * Build the GP Multiple Data Sets Validation-Voting Classifier 904 * 905 * This is according to Section 6 of the Paper by Liu et al. It is basically the Multiple 906 * Data Sets Validation Classifier but here we keep the best models an let them vote. 471 907 * 472 908 * @param traindataSet 909 * the training data 473 910 * @throws Exception 911 * thrown in case of a problem with the training 474 912 */ 475 913 public void buildClassifier(SetUniqueList<Instances> traindataSet) throws Exception { … … 478 916 // then is evaluated on the rest 479 917 classifiers = new LinkedList<>(); 480 for (int i=0; i < traindataSet.size(); i++) {918 for (int i = 0; i < traindataSet.size(); i++) { 481 919 482 920 // candidates we get out of evaluation 483 921 LinkedList<Classifier> candidates = new LinkedList<>(); 484 922 485 923 // number of runs, yields the best of these 486 double smallest_error_count_train = Double.MAX_VALUE; 924 double smallest_error_count_train = Double.MAX_VALUE; 487 925 Classifier bestTrain = null; 488 for(int k=0; k < this.numberRuns; k++) { 489 double[] errors_eval = {0.0, 0.0}; 926 for (int k = 0; k < this.numberRuns; k++) { 927 double[] errors_eval = 928 { 0.0, 0.0 }; 490 929 Classifier classifier = new GPRun(); 491 ((GPRun)classifier).configure(this.populationSize, this.initMinDepth, this.initMaxDepth, this.tournamentSize, this.maxGenerations, this.errorType2Weight, this.maxDepth, this.maxNodes); 492 930 ((GPRun) classifier).configure(this.populationSize, this.initMinDepth, 931 this.initMaxDepth, this.tournamentSize, 932 this.maxGenerations, this.errorType2Weight, 933 this.maxDepth, this.maxNodes); 934 493 935 // one project is training data 494 936 classifier.buildClassifier(traindataSet.get(i)); 495 937 496 938 double[] errors; 497 939 // rest of the set is evaluation data, we evaluate now 498 for(int j=0; j < traindataSet.size(); j++) { 499 if(j != i) { 500 // if type1 and type2 errors are < 0.5 we allow the model in the candidates 501 errors = this.evaluate((GPRun)classifier, traindataSet.get(j)); 940 for (int j = 0; j < traindataSet.size(); j++) { 941 if (j != i) { 942 // if type1 and type2 errors are < 0.5 we allow the model in the 943 // candidates 944 errors = this.evaluate((GPRun) classifier, traindataSet.get(j)); 502 945 errors_eval[0] += errors[0]; 503 946 errors_eval[1] += errors[1]; 504 if ((errors[0] < 0.5) && (errors[1] < 0.5)) {947 if ((errors[0] < 0.5) && (errors[1] < 0.5)) { 505 948 candidates.add(classifier); 506 949 } 507 950 } 508 951 } 509 952 510 953 // if the candidate made fewer errors it is now the best 511 if (errors_eval[0] + errors_eval[1] < smallest_error_count_train) {954 if (errors_eval[0] + errors_eval[1] < smallest_error_count_train) { 512 955 bestTrain = classifier; 513 956 smallest_error_count_train = errors_eval[0] + errors_eval[1]; … … 515 958 } 516 959 517 // now after the evaluation we do a model selection where only one model remains for the given training data 960 // now after the evaluation we do a model selection where only one model remains for 961 // the given training data 518 962 // we select the model which is best on all evaluation data 519 963 double smallest_error_count = Double.MAX_VALUE; 520 964 double[] errors; 521 965 Classifier best = null; 522 for(int ii=0; ii < candidates.size(); ii++) { 523 double[] errors_eval = {0.0, 0.0}; 524 966 for (int ii = 0; ii < candidates.size(); ii++) { 967 double[] errors_eval = 968 { 0.0, 0.0 }; 969 525 970 // we add the errors the candidate makes over the evaldata 526 for (int j=0; j < traindataSet.size(); j++) {527 if (j != i) {528 errors = this.evaluate((GPRun) candidates.get(ii), traindataSet.get(j));971 for (int j = 0; j < traindataSet.size(); j++) { 972 if (j != i) { 973 errors = this.evaluate((GPRun) candidates.get(ii), traindataSet.get(j)); 529 974 errors_eval[0] += errors[0]; 530 975 errors_eval[1] += errors[1]; 531 976 } 532 977 } 533 978 534 979 // if the candidate made fewer errors it is now the best 535 if (errors_eval[0] + errors_eval[1] < smallest_error_count) {980 if (errors_eval[0] + errors_eval[1] < smallest_error_count) { 536 981 best = candidates.get(ii); 537 982 smallest_error_count = errors_eval[0] + errors_eval[1]; 538 983 } 539 984 } 540 541 if ( best==null) {985 986 if (best == null) { 542 987 best = bestTrain; 543 988 } … … 546 991 } 547 992 } 548 993 549 994 /** 550 995 * Use the best classifiers for each training data in a majority voting 996 * 997 * @param instance 998 * instance that is classified 999 * 1000 * @see de.ugoe.cs.cpdp.training.GPTraining.GPVClassifier#classifyInstance(weka.core.Instance) 551 1001 */ 552 1002 @Override 553 1003 public double classifyInstance(Instance instance) { 554 1004 555 1005 int vote_positive = 0; 556 1006 557 1007 for (int i = 0; i < classifiers.size(); i++) { 558 1008 Classifier classifier = classifiers.get(i); 559 560 GPGenotype gp = ((GPRun) classifier).getGp();561 Variable[] vars = ((GPRun) classifier).getVariables();562 563 IGPProgram fitest = gp.getAllTimeBest(); 564 for (int j = 0; j < instance.numAttributes()-1; j++) {565 vars[j].set(instance.value(j));566 } 567 568 if (fitest.execute_double(0, vars) < 0.5) {1009 1010 GPGenotype gp = ((GPRun) classifier).getGp(); 1011 Variable[] vars = ((GPRun) classifier).getVariables(); 1012 1013 IGPProgram fitest = gp.getAllTimeBest(); // all time fitest 1014 for (int j = 0; j < instance.numAttributes() - 1; j++) { 1015 vars[j].set(instance.value(j)); 1016 } 1017 1018 if (fitest.execute_double(0, vars) < 0.5) { 569 1019 vote_positive += 1; 570 1020 } 571 1021 } 572 573 if (vote_positive >= (classifiers.size()/2)) {1022 1023 if (vote_positive >= (classifiers.size() / 2)) { 574 1024 return 1.0; 575 }else { 1025 } 1026 else { 576 1027 return 0.0; 577 1028 } 578 1029 } 579 1030 } 580 1031 581 1032 /** 582 1033 * GP Multiple Data Sets Validation Classifier 583 1034 * 584 * We train a Classifier with one training project $numberRun times. 585 * Then we evaluate the classifier on the rest of the training projects and keep the best classifier. 586 * After that we have for each training project the best classifier as per the evaluation on the rest of the data set. 587 * Then we determine the best classifier from these candidates and keep it to be used later. 1035 * We train a Classifier with one training project $numberRun times. Then we evaluate the 1036 * classifier on the rest of the training projects and keep the best classifier. After that we 1037 * have for each training project the best classifier as per the evaluation on the rest of the 1038 * data set. Then we determine the best classifier from these candidates and keep it to be used 1039 * later. 1040 * 1041 * @author sherbold Alexander Trautsch 588 1042 */ 589 1043 public class GPVClassifier extends AbstractClassifier { 590 1044 591 1045 private List<Classifier> classifiers = null; 592 1046 private Classifier best = null; … … 594 1048 private static final long serialVersionUID = 3708714057579101522L; 595 1049 1050 /** 1051 * size of the population of the genetic program 1052 */ 596 1053 protected int populationSize; 1054 1055 /** 1056 * minimal depth of the S-expression tree at the start of the training 1057 */ 597 1058 protected int initMinDepth; 1059 1060 /** 1061 * maximal depth of the S-expression tree at the start of the training 1062 */ 598 1063 protected int initMaxDepth; 1064 1065 /** 1066 * size of the tournaments used for selection 1067 */ 599 1068 protected int tournamentSize; 1069 1070 /** 1071 * number of genetic generations considered (i.e., number of iterations 1072 */ 600 1073 protected int maxGenerations; 1074 1075 /** 1076 * weight factor for the prediction errors for cost estimation 1077 */ 601 1078 protected double errorType2Weight; 602 protected int numberRuns; 1079 1080 /** 1081 * number of internal replications from which the best result is picked 1082 */ 1083 protected int numberRuns = 20; 1084 1085 /** 1086 * maximal depth of the S-expression tree 1087 */ 603 1088 protected int maxDepth; 1089 1090 /** 1091 * maximal number of nodes of the S-expression tree 1092 */ 604 1093 protected int maxNodes; 605 1094 606 1095 /** 1096 * 1097 * <p> 607 1098 * Configure the GP Params and number of Runs 1099 * </p> 608 1100 * 609 1101 * @param populationSize 1102 * the population size 610 1103 * @param initMinDepth 1104 * the initial minimal depth of the S-expression tree 611 1105 * @param initMaxDepth 1106 * the initial maximal depth of the S-expression tree 612 1107 * @param tournamentSize 1108 * the tournament size for selection 613 1109 * @param maxGenerations 1110 * the number of generations created 614 1111 * @param errorType2Weight 615 */ 616 public void configure(int populationSize, int initMinDepth, int initMaxDepth, int tournamentSize, int maxGenerations, double errorType2Weight, int numberRuns, int maxDepth, int maxNodes) { 1112 * weigth factor for the prediction errors 1113 * @param numberRuns 1114 * number of internal replications from which the best result is picked 1115 * @param maxDepth 1116 * maximal depth of the S-expression tree 1117 * @param maxNodes 1118 * maximal number of nodes of the S-expression tree 1119 */ 1120 public void configure(int populationSize, 1121 int initMinDepth, 1122 int initMaxDepth, 1123 int tournamentSize, 1124 int maxGenerations, 1125 double errorType2Weight, 1126 int numberRuns, 1127 int maxDepth, 1128 int maxNodes) 1129 { 617 1130 this.populationSize = populationSize; 618 1131 this.initMinDepth = initMinDepth; … … 625 1138 this.maxNodes = maxNodes; 626 1139 } 627 628 /** Build the GP Multiple Data Sets Validation Classifier 629 * 630 * This is according to Section 6 of the Paper by Liu et al. except for the selection of the best model. 631 * Section 4 describes a slightly different approach. 1140 1141 /** 1142 * Build the GP Multiple Data Sets Validation Classifier 1143 * 1144 * This is according to Section 6 of the Paper by Liu et al. except for the selection of the 1145 * best model. Section 4 describes a slightly different approach. 632 1146 * 633 1147 * @param traindataSet 1148 * the training data 634 1149 * @throws Exception 1150 * thrown in case of a problem with the training 635 1151 */ 636 1152 public void buildClassifier(SetUniqueList<Instances> traindataSet) throws Exception { … … 638 1154 // each classifier is trained with one project from the set 639 1155 // then is evaluated on the rest 640 for (int i=0; i < traindataSet.size(); i++) {641 1156 for (int i = 0; i < traindataSet.size(); i++) { 1157 642 1158 // candidates we get out of evaluation 643 1159 LinkedList<Classifier> candidates = new LinkedList<>(); 644 1160 645 1161 // numberRuns full GPRuns, we generate numberRuns models for each traindata 646 for (int k=0; k < this.numberRuns; k++) {1162 for (int k = 0; k < this.numberRuns; k++) { 647 1163 Classifier classifier = new GPRun(); 648 ((GPRun)classifier).configure(this.populationSize, this.initMinDepth, this.initMaxDepth, this.tournamentSize, this.maxGenerations, this.errorType2Weight, this.maxDepth, this.maxNodes); 649 1164 ((GPRun) classifier).configure(this.populationSize, this.initMinDepth, 1165 this.initMaxDepth, this.tournamentSize, 1166 this.maxGenerations, this.errorType2Weight, 1167 this.maxDepth, this.maxNodes); 1168 650 1169 classifier.buildClassifier(traindataSet.get(i)); 651 1170 652 1171 double[] errors; 653 1172 654 1173 // rest of the set is evaluation data, we evaluate now 655 for(int j=0; j < traindataSet.size(); j++) { 656 if(j != i) { 657 // if type1 and type2 errors are < 0.5 we allow the model in the candidate list 658 errors = this.evaluate((GPRun)classifier, traindataSet.get(j)); 659 if((errors[0] < 0.5) && (errors[1] < 0.5)) { 1174 for (int j = 0; j < traindataSet.size(); j++) { 1175 if (j != i) { 1176 // if type1 and type2 errors are < 0.5 we allow the model in the 1177 // candidate list 1178 errors = this.evaluate((GPRun) classifier, traindataSet.get(j)); 1179 if ((errors[0] < 0.5) && (errors[1] < 0.5)) { 660 1180 candidates.add(classifier); 661 1181 } … … 663 1183 } 664 1184 } 665 666 // now after the evaluation we do a model selection where only one model remains for the given training data 1185 1186 // now after the evaluation we do a model selection where only one model remains for 1187 // the given training data 667 1188 // we select the model which is best on all evaluation data 668 1189 double smallest_error_count = Double.MAX_VALUE; 669 1190 double[] errors; 670 1191 Classifier best = null; 671 for(int ii=0; ii < candidates.size(); ii++) { 672 double[] errors_eval = {0.0, 0.0}; 673 1192 for (int ii = 0; ii < candidates.size(); ii++) { 1193 double[] errors_eval = 1194 { 0.0, 0.0 }; 1195 674 1196 // we add the errors the candidate makes over the evaldata 675 for (int j=0; j < traindataSet.size(); j++) {676 if (j != i) {677 errors = this.evaluate((GPRun) candidates.get(ii), traindataSet.get(j));1197 for (int j = 0; j < traindataSet.size(); j++) { 1198 if (j != i) { 1199 errors = this.evaluate((GPRun) candidates.get(ii), traindataSet.get(j)); 678 1200 errors_eval[0] += errors[0]; 679 1201 errors_eval[1] += errors[1]; 680 1202 } 681 1203 } 682 1204 683 1205 // if the candidate made fewer errors it is now the best 684 if (errors_eval[0] + errors_eval[1] < smallest_error_count) {1206 if (errors_eval[0] + errors_eval[1] < smallest_error_count) { 685 1207 best = candidates.get(ii); 686 1208 smallest_error_count = errors_eval[0] + errors_eval[1]; 687 1209 } 688 1210 } 689 690 1211 691 1212 // now we have the best classifier for this training data 692 1213 classifiers.add(best); 693 1214 694 1215 } /* endfor trainData */ 695 696 // now we have one best classifier for each trainData 1216 1217 // now we have one best classifier for each trainData 697 1218 // we evaluate again to find the best classifier of all time 698 // this selection is now according to section 4 of the paper and not 6 where an average of the 6 models is build 1219 // this selection is now according to section 4 of the paper and not 6 where an average 1220 // of the 6 models is build 699 1221 double smallest_error_count = Double.MAX_VALUE; 700 1222 double error_count; 701 1223 double errors[]; 702 for (int j=0; j < classifiers.size(); j++) {1224 for (int j = 0; j < classifiers.size(); j++) { 703 1225 error_count = 0; 704 1226 Classifier current = classifiers.get(j); 705 for (int i=0; i < traindataSet.size(); i++) {706 errors = this.evaluate((GPRun) current, traindataSet.get(i));1227 for (int i = 0; i < traindataSet.size(); i++) { 1228 errors = this.evaluate((GPRun) current, traindataSet.get(i)); 707 1229 error_count = errors[0] + errors[1]; 708 1230 } 709 710 if (error_count < smallest_error_count) {1231 1232 if (error_count < smallest_error_count) { 711 1233 best = current; 712 1234 } 713 1235 } 714 1236 } 715 1237 1238 /* 1239 * (non-Javadoc) 1240 * 1241 * @see weka.classifiers.Classifier#buildClassifier(weka.core.Instances) 1242 */ 716 1243 @Override 717 1244 public void buildClassifier(Instances traindata) throws Exception { 718 1245 final Classifier classifier = new GPRun(); 719 ((GPRun)classifier).configure(populationSize, initMinDepth, initMaxDepth, tournamentSize, maxGenerations, errorType2Weight, this.maxDepth, this.maxNodes); 1246 ((GPRun) classifier).configure(populationSize, initMinDepth, initMaxDepth, 1247 tournamentSize, maxGenerations, errorType2Weight, 1248 this.maxDepth, this.maxNodes); 720 1249 classifier.buildClassifier(traindata); 721 1250 classifiers.add(classifier); 722 1251 } 723 724 /** 725 * Evaluation of the Classifier 726 * 727 * We evaluate the classifier with the Instances of the evalData. 728 * It basically assigns the instance attribute values to the variables of the s-expression-tree and 729 * then counts the missclassifications. 1252 1253 /** 1254 * <p> 1255 * Evaluation of the Classifier. 1256 * </p> 1257 * <p> 1258 * We evaluate the classifier with the Instances of the evalData. It basically assigns the 1259 * instance attribute values to the variables of the s-expression-tree and then counts the 1260 * missclassifications. 1261 * </p> 730 1262 * 731 1263 * @param classifier 1264 * the classifier that is evaluated 732 1265 * @param evalData 1266 * the validation data 733 1267 * @return 734 1268 */ … … 736 1270 GPGenotype gp = classifier.getGp(); 737 1271 Variable[] vars = classifier.getVariables(); 738 739 IGPProgram fitest = gp.getAllTimeBest(); // selects the fitest of all not just the last generation 740 1272 1273 IGPProgram fitest = gp.getAllTimeBest(); // selects the fitest of all not just the last 1274 // generation 1275 741 1276 double classification; 742 1277 int error_type1 = 0; … … 744 1279 int positive = 0; 745 1280 int negative = 0; 746 747 for (Instance instance: evalData) {748 1281 1282 for (Instance instance : evalData) { 1283 749 1284 // assign instance attribute values to the variables of the s-expression-tree 750 1285 double[] tmp = WekaUtils.instanceValues(instance); 751 for (int i = 0; i < tmp.length; i++) {1286 for (int i = 0; i < tmp.length; i++) { 752 1287 vars[i].set(tmp[i]); 753 1288 } 754 1289 755 1290 classification = fitest.execute_double(0, vars); 756 1291 757 1292 // we need to count the absolutes of positives for percentage 758 if(instance.classValue() == 1.0) { 759 positive +=1; 760 }else { 761 negative +=1; 762 } 763 1293 if (instance.classValue() == 1.0) { 1294 positive += 1; 1295 } 1296 else { 1297 negative += 1; 1298 } 1299 764 1300 // classification < 0.5 we say defective 765 if (classification < 0.5) {766 if (instance.classValue() != 1.0) {1301 if (classification < 0.5) { 1302 if (instance.classValue() != 1.0) { 767 1303 error_type1 += 1; 768 1304 } 769 }else { 770 if(instance.classValue() == 1.0) { 1305 } 1306 else { 1307 if (instance.classValue() == 1.0) { 771 1308 error_type2 += 1; 772 1309 } 773 1310 } 774 1311 } 775 776 // return error types percentages for the types 1312 1313 // return error types percentages for the types 777 1314 double et1_per = error_type1 / negative; 778 double et2_per = error_type2 / positive; 779 return new double[]{et1_per, et2_per}; 780 } 781 1315 double et2_per = error_type2 / positive; 1316 return new double[] 1317 { et1_per, et2_per }; 1318 } 1319 782 1320 /** 783 1321 * Use only the best classifier from our evaluation phase 1322 * 1323 * @param instance 1324 * instance that is classified 1325 * 1326 * @see weka.classifiers.AbstractClassifier#classifyInstance(weka.core.Instance) 784 1327 */ 785 1328 @Override 786 1329 public double classifyInstance(Instance instance) { 787 GPGenotype gp = ((GPRun) best).getGp();788 Variable[] vars = ((GPRun) best).getVariables();789 790 IGPProgram fitest = gp.getAllTimeBest(); 791 for (int i = 0; i < instance.numAttributes()-1; i++) {792 vars[i].set(instance.value(i));793 } 794 1330 GPGenotype gp = ((GPRun) best).getGp(); 1331 Variable[] vars = ((GPRun) best).getVariables(); 1332 1333 IGPProgram fitest = gp.getAllTimeBest(); // all time fitest 1334 for (int i = 0; i < instance.numAttributes() - 1; i++) { 1335 vars[i].set(instance.value(i)); 1336 } 1337 795 1338 double classification = fitest.execute_double(0, vars); 796 797 if (classification < 0.5) {1339 1340 if (classification < 0.5) { 798 1341 return 1.0; 799 }else { 1342 } 1343 else { 800 1344 return 0.0; 801 1345 }
Note: See TracChangeset
for help on using the changeset viewer.