ROOT  6.06/09
Reference Guide
Interval.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Peter Speckmayer
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : TMVA::Interval *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Peter Speckmayer <speckmay@mail.cern.ch> - CERN, Switzerland *
15  * *
16  * Copyright (c) 2005: *
17  * CERN, Switzerland *
18  * MPI-K Heidelberg, Germany *
19  * *
20  * Redistribution and use in source and binary forms, with or without *
21  * modification, are permitted according to the terms listed in LICENSE *
22  * (http://tmva.sourceforge.net/LICENSE) *
23  * *
24  * File and Version Information: *
25  **********************************************************************************/
26 
27 //////////////////////////////////////////////////////////////////////////////
28 // //
29 // Interval //
30 // //
31 // Interval definition, continuous and discrete //
32 // //
33 // Interval(min,max) : a continous interval [min,max] //
34 // Interval(min,max,n): a "discrete interval" [min,max], i.e the n numbers: //
35 // min, min+step, min+2*step,...., min+(n-1)*step, min+n*step=max //
36 // e.g.: Interval(1,5,5)=1,2,3,4,5 //
37 // Interval(.5,1.,6)= .5, .6., .7, .8, .9, 1.0 //
38 // //
39 // Note: **bin** counting starts from ZERO unlike in ROOT histograms //
40 //////////////////////////////////////////////////////////////////////////////
41 /* Begin_Html
42 <center><h2>the TMVA::Interval Class</h2></center>
43 
44 <ul>
45  <li> Interval definition, continuous and discrete
46  <ul>
47  <li> Interval(min,max) : a continous interval [min,max]
48  <li> Interval(min,max,n): a "discrete interval" [min,max], i.e the n numbers:<br>
49  min, min+step, min+2*step,...., min+(n-1)*step=max <br>
50  e.g.: Interval(1,5,5)=1,2,3,4,5 <br>
51  Interval(.5,1.,6)= .5, .6., .7, .8, .9, 1.0 <br>
52 
53  </ul>
54 </ul>
55 <pre>
56 
57  Example: Interval(.5,1.,6)
58 
59  [ min max ]
60  ------------------------------------------------------------
61  | | | | | |
62  .5 .6 .7 .8 .9 1.0
63 
64  bin 0 1 2 3 4 5
65 
66 
67 </pre>
68 End_Html */
69 
70 #include "TMath.h"
71 #include "TRandom3.h"
72 #include "ThreadLocalStorage.h"
73 
74 #include "TMVA/Interval.h"
75 #include "TMVA/MsgLogger.h"
76 
78 
79 ////////////////////////////////////////////////////////////////////////////////
80 /// defines minimum and maximum of an interval
81 /// when nbins > 0, interval describes a discrete distribution (equally distributed in the interval)
82 /// when nbins == 0, interval describes a continous interval
83 ///
84 
85 TMVA::Interval::Interval( Double_t min, Double_t max, Int_t nbins ) :
86  fMin(min),
87  fMax(max),
88  fNbins(nbins)
89 {
90  if (fMax - fMin < 0) Log() << kFATAL << "maximum lower than minimum" << Endl;
91  if (nbins < 0) {
92  Log() << kFATAL << "nbins < 0" << Endl;
93  return;
94  }
95  else if (nbins == 1) {
96  Log() << kFATAL << "interval has to have at least 2 bins if discrete" << Endl;
97  return;
98  }
99 }
100 
102  fMin ( other.fMin ),
103  fMax ( other.fMax ),
104  fNbins( other.fNbins )
105 {
106 }
107 
108 ////////////////////////////////////////////////////////////////////////////////
109 /// destructor
110 
112 {
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// calculates the value of the "number" bin in a discrete interval.
117 /// Parameters:
118 /// Double_t position
119 ///
120 
122 {
123  if (fNbins <= 0) {
124  Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
125  return 0.0;
126  }
127  else if (bin < 0 || bin >= fNbins) {
128  Log() << kFATAL << "bin " << bin << " out of range: interval *bins* count from 0 to " << fNbins-1 << Endl;
129  return 0.0;
130  }
131  return fMin + ( (Double_t(bin)/(fNbins-1)) *(fMax - fMin) );
132 }
133 
134 ////////////////////////////////////////////////////////////////////////////////
135 /// retuns the step size between the numbers of a "discrete Interval"
136 
138 {
139  if (fNbins <= 0) {
140  Log() << kFATAL << "GetElement only defined for discrete value Intervals" << Endl;
141  }
142  if (iBin<0) {
143  Log() << kFATAL << "You asked for iBin=" << iBin
144  <<" in interval .. and.. sorry, I cannot let this happen.."<<Endl;
145  }
146  return (fMax-fMin)/(Double_t)(fNbins-1);
147 }
148 
149 ////////////////////////////////////////////////////////////////////////////////
150 /// get uniformely distributed number within interval
151 
153 {
154  return rnd.Rndm()*(fMax - fMin) + fMin;
155 }
156 
158 {
159  return fMax - fMin;
160 }
162 {
163  return (fMax + fMin)/2;
164 }
165 
166 void TMVA::Interval::Print(std::ostream &os) const
167 {
168  for (Int_t i=0; i<GetNbins(); i++){
169  os << "| " << GetElement(i)<<" |" ;
170  }
171 }
172 
174  TTHREAD_TLS_DECL_ARG(MsgLogger,logger,"Interval"); // message logger
175  return logger;
176 }
Random number generator class based on M.
Definition: TRandom3.h:29
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
Definition: vector.h:433
MsgLogger & Endl(MsgLogger &ml)
Definition: MsgLogger.h:162
MsgLogger & Log() const
Definition: Interval.cxx:173
int Int_t
Definition: RtypesCore.h:41
virtual Double_t GetMean() const
Definition: Interval.cxx:161
int nbins[3]
ClassImp(TMVA::Interval) TMVA
defines minimum and maximum of an interval when nbins > 0, interval describes a discrete distribution...
Definition: Interval.cxx:77
virtual ~Interval()
destructor
Definition: Interval.cxx:111
virtual Double_t GetWidth() const
Definition: Interval.cxx:157
virtual Double_t GetElement(Int_t position) const
calculates the value of the "number" bin in a discrete interval.
Definition: Interval.cxx:121
virtual Double_t Rndm(Int_t i=0)
Machine independent random number generator.
Definition: TRandom3.cxx:93
Interval(Double_t min, Double_t max, Int_t nbins=0)
virtual Double_t GetStepSize(Int_t iBin=0) const
retuns the step size between the numbers of a "discrete Interval"
Definition: Interval.cxx:137
virtual Double_t GetRndm(TRandom3 &) const
get uniformely distributed number within interval
Definition: Interval.cxx:152
double Double_t
Definition: RtypesCore.h:55
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
Definition: vector.h:440
Abstract ClassifierFactory template that handles arbitrary types.
virtual void Print(std::ostream &os) const
Definition: Interval.cxx:166
Definition: math.cpp:60