Changeset 7700
- Timestamp:
- 05/05/06 14:01:54 (19 years ago)
- Location:
- trunk/MagicSoft/Mars
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/MagicSoft/Mars/Changelog
r7699 r7700 73 73 fPostTasks lists 74 74 75 * mjtrain/MJTrainEnergy.cc: 76 - implemented usage of weights 77 75 78 76 79 -
trunk/MagicSoft/Mars/mjtrain/MJTrainEnergy.cc
r7552 r7700 107 107 MHMatrix train("Train"); 108 108 train.AddColumns(fRules); 109 if (fEnableWeights) 110 train.AddColumn("MWeight.fVal"); 109 111 train.AddColumn("MMcEvt.fImpact/100"); 110 112 train.AddColumn("MMcEvt.fTelescopeTheta*kRad2Deg"); … … 120 122 fill.AddPreCuts(fPreCuts); 121 123 fill.AddPreCuts(fTrainCuts); 124 fill.AddPreTasks(fPreTasks); 125 fill.AddPostTasks(fPostTasks); 122 126 if (!fill.Process()) 123 127 return kFALSE; … … 129 133 rf.SetNumTry(fNumTry); 130 134 rf.SetNumObsoleteVariables(3); 135 rf.SetLastDataColumnHasWeights(fEnableWeights); 131 136 rf.SetDisplay(fDisplay); 132 137 rf.SetLogStream(fLog); … … 168 173 MHEnergyEst hist; 169 174 MFillH fillh(&hist); 175 if (fEnableWeights) 176 fillh.SetWeight(); 170 177 171 178 tlist.AddToList(&readtst); 179 tlist.AddToList(fPreTasks); 172 180 tlist.AddToList(&cont); 173 181 tlist.AddToList(&rf); 182 tlist.AddToList(fPostTasks); 174 183 tlist.AddToList(&fillh); 175 184 -
trunk/MagicSoft/Mars/mjtrain/MJTrainSeparation.cc
r7678 r7700 47 47 #include "MDataSet.h" 48 48 #include "MTFillMatrix.h" 49 #include "MChisqEval.h"50 49 #include "MStatusDisplay.h" 51 50 … … 59 58 #include "MContinue.h" 60 59 #include "MFillH.h" 60 #include "MSrcPosRndm.h" 61 #include "MHillasCalc.h" 61 62 #include "MRanForestCalc.h" 62 63 #include "MParameterCalc.h" … … 201 202 gPad->SetGridx(); 202 203 gPad->SetGridy(); 204 gr4.SetMinimum(0); 203 205 gr4.SetMarkerStyle(kFullDotMedium); 204 206 gr4.DrawClone("ALP")->SetBit(kCanDelete); … … 400 402 // Target spectrum 401 403 TF1 flx("Flux", "[0]/1000*(x/1000)^(-2.6)", min, max); 402 flx.SetParameter(0, 2e-7);404 flx.SetParameter(0, fFlux); 403 405 404 406 // Number n0 of events this spectrum would produce per s and m^2 … … 430 432 *fLog << "Total effective on time: " << data/r << "s" << endl; 431 433 434 const Double_t ratio = T*r/data; 435 *fLog << "Ratio of Monte Carlo to data observation time: " << ratio << endl; 436 437 // 3570.5/43440.2 = 0.082 438 439 432 440 // this yields a number of n events to be read for training 433 441 const Double_t n = r*T; //[#] … … 443 451 *fLog << "Events available in MC sample: " << nummc << endl; 444 452 445 *fLog << "MC read probability: " << data/n << endl;453 // *fLog << "MC read probability: " << data/n << endl; 446 454 447 455 // more data requested than available => Scale down num MC events … … 503 511 { 504 512 *fLog << err << "ERROR - DataSet for testing invalid!" << endl; 513 return kFALSE; 514 } 515 516 if (fDataSetTrain.IsWobbleMode()!=fDataSetTest.IsWobbleMode()) 517 { 518 *fLog << err << "ERROR - Train- and Test-DataSet have different observation modes!" << endl; 505 519 return kFALSE; 506 520 } … … 528 542 read4.DisableAutoScheme(); 529 543 544 // Setup four reading tasks with the on- and off-data of the two datasets 530 545 fDataSetTrain.AddFilesOn(read1); 531 546 fDataSetTrain.AddFilesOff(read3); … … 534 549 fDataSetTest.AddFilesOn(read4); 535 550 536 // ----------------------- Setup RF ----------------------551 // ----------------------- Setup RF Matrix ---------------------- 537 552 MHMatrix train("Train"); 538 553 train.AddColumns(fRules); 554 if (fEnableWeightsOn || fEnableWeightsOff) 555 train.AddColumn("MWeight.fVal"); 539 556 train.AddColumn("MHadronness.fVal"); 540 557 541 558 // ----------------------- Fill Matrix RF ---------------------- 542 559 560 // Setup the hadronness container identifying gammas and off-data 561 // and setup a container for the weights 543 562 MParameterD had("MHadronness"); 544 563 MParameterD wgt("MWeight"); 564 565 // Add them to the parameter list 545 566 MParList plistx; 546 567 plistx.AddToList(&had); 568 plistx.AddToList(&wgt); 547 569 plistx.AddToList(this); 548 570 571 // Setup the tool class to fill the matrix 549 572 MTFillMatrix fill; 550 573 fill.SetLogStream(fLog); … … 555 578 // Set classifier for gammas 556 579 had.SetVal(0); 580 wgt.SetVal(1); 581 582 // Setup the tool class to read the gammas and read them 557 583 fill.SetName("FillGammas"); 558 584 fill.SetDestMatrix1(&train, fNumTrainOn); 559 585 fill.SetReader(&read1); 586 fill.AddPreTasks(fPreTasksOn); 587 fill.AddPreTasks(fPreTasks); 588 fill.AddPostTasks(fPostTasksOn); 589 fill.AddPostTasks(fPostTasks); 560 590 if (!fill.Process(plistx)) 561 591 return kFALSE; 562 592 593 // Check the number or read events 563 594 const Int_t numgammastrn = train.GetNumRows(); 564 595 if (numgammastrn==0) … … 568 599 } 569 600 570 // Set classifier for hadrons 601 // Remove possible post tasks 602 fill.ClearPreTasks(); 603 fill.ClearPostTasks(); 604 605 // Set classifier for background 571 606 had.SetVal(1); 607 wgt.SetVal(1); 608 609 // In case of wobble mode we have to do something special 610 MSrcPosRndm srcrndm; 611 srcrndm.SetDistOfSource(0.4); 612 613 MHillasCalc hcalc; 614 hcalc.SetFlags(MHillasCalc::kCalcHillasSrc); 615 616 if (fDataSetTrain.IsWobbleMode()) 617 { 618 fPreTasksOff.AddFirst(&hcalc); 619 fPreTasksOff.AddFirst(&srcrndm); 620 } 621 622 // Setup the tool class to read the background and read them 572 623 fill.SetName("FillBackground"); 573 624 fill.SetDestMatrix1(&train, fNumTrainOff); 574 625 fill.SetReader(&read3); 626 fill.AddPreTasks(fPreTasksOff); 627 fill.AddPreTasks(fPreTasks); 628 fill.AddPostTasks(fPostTasksOff); 629 fill.AddPostTasks(fPostTasks); 575 630 if (!fill.Process(plistx)) 576 631 return kFALSE; 577 632 633 // Check the number or read events 578 634 const Int_t numbackgrndtrn = train.GetNumRows()-numgammastrn; 579 635 if (numbackgrndtrn==0) … … 590 646 rf.SetNumTry(fNumTry); 591 647 rf.SetNumObsoleteVariables(1); 648 rf.SetLastDataColumnHasWeights(fEnableWeightsOn || fEnableWeightsOff); 592 649 rf.SetDebug(fDebug); 593 650 rf.SetDisplay(fDisplay); … … 596 653 rf.SetNameOutput("MHadronness"); 597 654 655 // Train the random forest either by classification or regression 598 656 if (fUseRegression) 599 657 { 600 if (!rf.Train SingleRF(train))// regression658 if (!rf.TrainRegression(train)) // regression 601 659 return kFALSE; 602 660 } 603 661 else 604 662 { 605 MBinning b(2, -0.5, 1.5, "BinningHadronness", "lin"); 606 if (!rf.TrainSingleRF(train, b.GetEdgesD())) // classification 663 if (!rf.TrainSingleRF(train)) // classification 607 664 return kFALSE; 608 665 } 609 666 610 //if (!rf.TrainMultiRF(train, b.GetEdgesD())) // classification 611 // return; 612 613 //fDisplay = rf.GetDisplay(); 614 615 667 // Output information about what was going on so far. 616 668 *fLog << all; 617 fLog->Separator("The forest was t ested with...");669 fLog->Separator("The forest was trained with..."); 618 670 619 671 *fLog << "Training method:" << endl; 620 672 *fLog << " * " << (fUseRegression?"regression":"classification") << endl; 673 if (fEnableWeightsOn) 674 *fLog << " * weights for on-data" << endl; 675 if (fEnableWeightsOff) 676 *fLog << " * weights for off-data" << endl; 677 if (fDataSetTrain.IsWobbleMode()) 678 *fLog << " * random source position in a distance of 0.4°" << endl; 621 679 *fLog << endl; 622 680 *fLog << "Events used for training:" << endl; … … 628 686 *fLog << " * Result: " << (float)numgammastrn/numbackgrndtrn << endl; 629 687 688 // Chekc if testing is requested 630 689 if (!fDataSetTest.IsValid()) 631 690 return kTRUE; … … 634 693 fLog->Separator("Test"); 635 694 695 // Setup parlist and tasklist for testing 636 696 MParList plist; 637 697 MTaskList tlist; … … 642 702 plist.AddToList(&mcevt); 643 703 704 plist.AddToList(&wgt); 705 644 706 // ----- Setup histograms ----- 645 707 MBinning binsy(50, 0 , 1, "BinningMH3Y", "lin"); … … 652 714 MH3 h32("MHillas.fSize", "MHadronness.fVal"); 653 715 MH3 h40("MMcEvt.fEnergy", "MHadronness.fVal"); 654 h31.SetTitle("Background probability vs. Size:Size [phe]:Hadronness ");655 h32.SetTitle("Background probability vs. Size:Size [phe]:Hadronness ");656 h40.SetTitle("Background probability vs. Energy:Energy [GeV]:Hadronness ");716 h31.SetTitle("Background probability vs. Size:Size [phe]:Hadronness h"); 717 h32.SetTitle("Background probability vs. Size:Size [phe]:Hadronness h"); 718 h40.SetTitle("Background probability vs. Energy:Energy [GeV]:Hadronness h"); 657 719 658 720 MHHadronness hist; … … 663 725 MFillH fillh2(&h32); 664 726 MFillH fillh4(&h40); 727 fillh0.SetWeight("MWeight"); 728 fillh1.SetWeight("MWeight"); 729 fillh2.SetWeight("MWeight"); 730 fillh4.SetWeight("MWeight"); 731 fillh1.SetDrawOption("colz profy"); 732 fillh2.SetDrawOption("colz profy"); 733 fillh4.SetDrawOption("colz profy"); 665 734 fillh1.SetNameTab("Background"); 666 735 fillh2.SetNameTab("GammasH"); … … 677 746 c0.SetInverted(); 678 747 679 MFEventSelector sel; 748 MFEventSelector sel; // FIXME: USING IT (WITH PROB?) in READ will by much faster!!! 680 749 sel.SetNumSelectEvts(fNumTestOff); 681 750 … … 685 754 // ----- Setup tasklist ----- 686 755 tlist.AddToList(&read2); 756 tlist.AddToList(&c1); 757 tlist.AddToList(fPreTasksOff); 758 tlist.AddToList(fPreTasks); 687 759 tlist.AddToList(&c0); 688 tlist.AddToList(&c1);689 760 tlist.AddToList(&rf); 761 tlist.AddToList(fPostTasksOff); 762 tlist.AddToList(fPostTasks); 690 763 tlist.AddToList(&fillh0); 691 764 tlist.AddToList(&fillh1); 692 765 693 // ----- Run eventloop on gammas ----- 766 // Enable Acceleration 767 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime); 768 769 // ----- Run eventloop on background ----- 694 770 MEvtLoop loop; 695 771 loop.SetDisplay(fDisplay); … … 697 773 loop.SetParList(&plist); 698 774 775 wgt.SetVal(1); 699 776 if (!loop.Eventloop()) 700 777 return kFALSE; 701 778 702 // ----- Setup and run eventloop on background-----779 // ----- Setup and run eventloop on gammas ----- 703 780 sel.SetNumSelectEvts(fNumTestOn); 704 781 fillh0.ResetBit(MFillH::kDoNotDisplay); 705 782 783 // Remove PreTasksOff and PostTasksOff from the list 784 tlist.RemoveFromList(fPreTasksOff); 785 tlist.RemoveFromList(fPostTasksOff); 786 787 // replace the reading task by a new one 706 788 tlist.Replace(&read4); 789 790 // Add the PreTasksOn directly after the reading task 791 tlist.AddToListAfter(fPreTasksOn, &c1); 792 793 // Add the PostTasksOn after rf 794 tlist.AddToListAfter(fPostTasksOn, &rf); 795 796 // Replace fillh1 by fillh2 707 797 tlist.Replace(&fillh2); 798 799 // Add fillh4 after the new fillh2 708 800 tlist.AddToListAfter(&fillh4, &fillh2); 709 801 802 // Enable Acceleration 803 tlist.SetAccelerator(MTask::kAccDontReset|MTask::kAccDontTime); 804 805 wgt.SetVal(1); 710 806 if (!loop.Eventloop()) 711 807 return kFALSE; 712 808 809 // Display the result plots 713 810 DisplayResult(h31, h32); 714 811 812 // Write the display 715 813 if (!WriteDisplay(out)) 716 814 return kFALSE; 815 816 // Show what was going on in the testing 817 const Double_t numgammastst = h32.GetHist().GetEntries(); 818 const Double_t numbackgrndtst = h31.GetHist().GetEntries(); 717 819 718 820 *fLog << all; 719 821 fLog->Separator("The forest was tested with..."); 720 721 const Double_t numgammastst = h32.GetHist().GetEntries(); 722 const Double_t numbackgrndtst = h31.GetHist().GetEntries(); 723 822 *fLog << "Test method:" << endl; 823 *fLog << " * Random Forest: " << out << endl; 824 if (fEnableWeightsOn) 825 *fLog << " * weights for on-data" << endl; 826 if (fEnableWeightsOff) 827 *fLog << " * weights for off-data" << endl; 828 if (fDataSetTrain.IsWobbleMode()) 829 *fLog << " * random source position in a distance of 0.4°" << endl; 724 830 *fLog << "Events used for test:" << endl; 725 831 *fLog << " * Gammas: " << numgammastst << endl;
Note:
See TracChangeset
for help on using the changeset viewer.