GeneticRange.cxx

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: GeneticRange.cxx 29122 2009-06-22 06:51:30Z brun $    
00002 // Author: Peter Speckmayer
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : TMVA::GeneticRange                                                    *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Implementation (see header for description)                               *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Peter Speckmayer <speckmay@mail.cern.ch>  - CERN, Switzerland             *
00015  *                                                                                *
00016  * Copyright (c) 2005:                                                            *
00017  *      CERN, Switzerland                                                         *
00018  *      MPI-K Heidelberg, Germany                                                 *
00019  *                                                                                *
00020  * Redistribution and use in source and binary forms, with or without             *
00021  * modification, are permitted according to the terms listed in LICENSE           *
00022  * (http://tmva.sourceforge.net/LICENSE)                                          *
00023  *                                                                                *
00024  * File and Version Information:                                                  *
00025  **********************************************************************************/
00026 
00027 //_______________________________________________________________________
00028 //                                                                      
00029 // Range definition for genetic algorithm                               
00030 //_______________________________________________________________________
00031 
00032 #include "TRandom3.h"
00033 
00034 #include "TMVA/GeneticRange.h"
00035 
00036 ClassImp(TMVA::GeneticRange)
00037 
00038 //_______________________________________________________________________
00039 TMVA::GeneticRange::GeneticRange( TRandom3*rnd, Interval *interval )
00040 {
00041    // defines the "f" (from) and "t" (to) of the coefficient
00042    // and takes a randomgenerator
00043    //
00044    fInterval = interval;
00045    
00046    fFrom = fInterval->GetMin();
00047    fTo   = fInterval->GetMax();
00048    fNbins= fInterval->GetNbins();
00049    fTotalLength = fTo-fFrom;
00050 
00051    fRandomGenerator = rnd;
00052 }
00053 
00054 //_______________________________________________________________________
00055 Double_t TMVA::GeneticRange::RandomDiscrete()
00056 {
00057    // creates a new random value for the coefficient; returns a discrete value
00058    //
00059    Double_t value = fRandomGenerator->Uniform(0, 1);
00060    return fInterval->GetElement( Int_t(value*fNbins) );
00061 }
00062 
00063 //_______________________________________________________________________
00064 Double_t TMVA::GeneticRange::Random( Bool_t near, Double_t value, Double_t spread, Bool_t mirror )
00065 {
00066    // creates a new random value for the coefficient
00067    // Parameters:
00068    //        Bool_t near     : takes a random value near the current value
00069    //        double value  : this is the current value
00070    //        double spread : the sigma of the gaussian which is taken to calculate the new value
00071    //        Bool_t mirror   : if the new value would be outside of the range, mirror = false
00072    //                        maps the value between the constraints by periodic boundary conditions.
00073    //                        With mirror = true, the value gets "reflected" on the boundaries.
00074    //
00075    if (fInterval->GetNbins() > 0) {   // discrete interval
00076        return RandomDiscrete();
00077    }
00078    else if (fFrom == fTo) {
00079       return fFrom;
00080    }
00081    else if (near) {
00082       Double_t ret;
00083       ret = fRandomGenerator->Gaus( value, fTotalLength*spread );
00084       if (mirror ) return ReMapMirror( ret );
00085       else return ReMap( ret );
00086    }
00087    return fRandomGenerator->Uniform(fFrom, fTo);
00088 }
00089 
00090 //_______________________________________________________________________
00091 Double_t TMVA::GeneticRange::ReMap( Double_t val )
00092 {
00093    // remapping the value to the allowed space
00094    //
00095    if (fFrom >= fTo ) return val;
00096    if (val < fFrom ) return ReMap( (val-fFrom) + fTo );
00097    if (val >= fTo )    return ReMap( (val-fTo) + fFrom );
00098    return val;
00099 }
00100 
00101 //_______________________________________________________________________
00102 Double_t TMVA::GeneticRange::ReMapMirror( Double_t val )
00103 {
00104    // remapping the value to the allowed space by reflecting on the 
00105    // boundaries
00106    if (fFrom >= fTo ) return val;
00107    if (val < fFrom  ) return ReMap( fFrom - (val-fFrom) );
00108    if (val >= fTo   ) return ReMap( fTo - (val-fTo)  );
00109    return val;
00110 }
00111 
00112 //_______________________________________________________________________
00113 TMVA::GeneticRange::~GeneticRange()
00114 {
00115    // destructor
00116 }
00117 

Generated on Tue Jul 5 15:25:00 2011 for ROOT_528-00b_version by  doxygen 1.5.1