Changeset 104 for trunk/CrossPare/src/de/ugoe
- Timestamp:
- 05/19/16 14:33:05 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/CrossPare/src/de/ugoe/cs/cpdp/training/GPTraining.java
r103 r104 1 1 package de.ugoe.cs.cpdp.training; 2 2 3 import java.util.LinkedList; 3 4 import java.util.List; 4 5 … … 47 48 public class GPTraining implements ISetWiseTrainingStrategy, IWekaCompatibleTrainer { 48 49 49 private GPV Classifier classifier = new GPVClassifier();50 private GPVVClassifier classifier = new GPVVClassifier(); 50 51 51 52 private int populationSize = 1000; … … 342 343 /** 343 344 * GP Multiple Data Sets Validation-Voting Classifier 344 * 345 * 346 * As the GP Multiple Data Sets Validation Classifier 347 * But here we do keep a model candidate for each training set which may later vote 345 348 * 346 349 */ … … 360 363 // then is evaluated on the rest 361 364 for(int i=0; i < traindataSet.size(); i++) { 362 Classifier classifier = new GPRun(); 363 364 // one project is training data 365 classifier.buildClassifier(traindataSet.get(i)); 366 365 366 // candidates we get out of evaluation 367 LinkedList<Classifier> candidates = new LinkedList<>(); 368 369 // 200 runs 370 371 for(int k=0; k < 200; k++) { 372 Classifier classifier = new GPRun(); 373 374 // one project is training data 375 classifier.buildClassifier(traindataSet.get(i)); 376 377 double[] errors; 378 // rest of the set is evaluation data, we evaluate now 379 for(int j=0; j < traindataSet.size(); j++) { 380 if(j != i) { 381 // if type1 and type2 errors are < 0.5 we allow the model in the final voting 382 errors = this.evaluate((GPRun)classifier, traindataSet.get(j)); 383 if((errors[0] / traindataSet.get(j).numInstances()) < 0.5 && (errors[0] / traindataSet.get(j).numInstances()) < 0.5) { 384 candidates.add(classifier); 385 } 386 } 387 } 388 } 389 390 // now after the evaluation we do a model selection where only one model remains for the given training data 391 double smallest_error_count = Double.MAX_VALUE; 367 392 double[] errors; 368 369 // rest of the set is evaluation data, we evaluate now 370 for(int j=0; j < traindataSet.size(); j++) { 371 if(j != i) { 372 // if type1 and type2 errors are < 0.5 we allow the model in the final voting 373 errors = this.evaluate((GPRun)classifier, traindataSet.get(j)); 374 if((errors[0] / traindataSet.get(j).numInstances()) < 0.5 && (errors[0] / traindataSet.get(j).numInstances()) < 0.5) { 375 classifiers.add(classifier); 393 Classifier best = null; 394 for(int ii=0; ii < candidates.size(); ii++) { 395 for(int j=0; j < traindataSet.size(); j++) { 396 if(j != i) { 397 errors = this.evaluate((GPRun)candidates.get(ii), traindataSet.get(j)); 398 399 if(errors[0]+errors[1] < smallest_error_count) { 400 best = candidates.get(ii); 401 } 376 402 } 377 403 } 378 404 } 405 406 // now we have the best classifier for this training data 407 classifiers.add(best); 408 379 409 } 380 410 } … … 407 437 } 408 438 409 if(vote_positive >= 3) {439 if(vote_positive >= (classifiers.size()/2)) { 410 440 return 1.0; 411 441 }else { … … 430 460 public class GPVClassifier extends AbstractClassifier { 431 461 462 private List<Classifier> classifiers = null; 432 463 private Classifier best = null; 433 464 434 465 private static final long serialVersionUID = 3708714057579101522L; 435 466 … … 449 480 // then is evaluated on the rest 450 481 for(int i=0; i < traindataSet.size(); i++) { 451 Classifier classifier = new GPRun(); 452 453 // one project is training data 454 classifier.buildClassifier(traindataSet.get(i)); 455 456 // rest of the set is evaluation data, we evaluate now 482 483 // candidates we get out of evaluation 484 LinkedList<Classifier> candidates = new LinkedList<>(); 485 486 // 200 runs 487 for(int k=0; k < 200; k++) { 488 Classifier classifier = new GPRun(); 489 490 // one project is training data 491 classifier.buildClassifier(traindataSet.get(i)); 492 493 double[] errors; 494 495 // rest of the set is evaluation data, we evaluate now 496 for(int j=0; j < traindataSet.size(); j++) { 497 if(j != i) { 498 // if type1 and type2 errors are < 0.5 we allow the model in the final voting 499 errors = this.evaluate((GPRun)classifier, traindataSet.get(j)); 500 if((errors[0] / traindataSet.get(j).numInstances()) < 0.5 && (errors[0] / traindataSet.get(j).numInstances()) < 0.5) { 501 candidates.add(classifier); 502 } 503 } 504 } 505 } 506 507 // now after the evaluation we do a model selection where only one model remains per training data set 508 // from that we chose the best model 509 510 // now after the evaluation we do a model selection where only one model remains for the given training data 457 511 double smallest_error_count = Double.MAX_VALUE; 458 512 double[] errors; 459 for(int j=0; j < traindataSet.size(); j++) { 460 if(j != i) { 461 errors = this.evaluate((GPRun)classifier, traindataSet.get(j)); 462 if(errors[0]+errors[1] < smallest_error_count) { 463 this.best = classifier; 513 Classifier best = null; 514 for(int ii=0; ii < candidates.size(); ii++) { 515 for(int j=0; j < traindataSet.size(); j++) { 516 if(j != i) { 517 errors = this.evaluate((GPRun)candidates.get(ii), traindataSet.get(j)); 518 519 if(errors[0]+errors[1] < smallest_error_count) { 520 best = candidates.get(ii); 521 } 464 522 } 465 523 } 524 } 525 526 // now we have the best classifier for this training data 527 classifiers.add(best); 528 } 529 530 // now determine the best classifier for all training data 531 double smallest_error_count = Double.MAX_VALUE; 532 double error_count; 533 double errors[]; 534 for(int j=0; j < classifiers.size(); j++) { 535 error_count = 0; 536 Classifier current = classifiers.get(j); 537 for(int i=0; i < traindataSet.size(); i++) { 538 errors = this.evaluate((GPRun)current, traindataSet.get(i)); 539 error_count = errors[0] + errors[1]; 540 } 541 542 if(error_count < smallest_error_count) { 543 best = current; 466 544 } 467 545 } … … 472 550 final Classifier classifier = new GPRun(); 473 551 classifier.buildClassifier(traindata); 474 best = classifier;552 classifiers.add(classifier); 475 553 } 476 554
Note: See TracChangeset
for help on using the changeset viewer.