00001 /*************************************************************************** 00002 dwellprobe.h 00003 ------------------- 00004 begin : Mon Oct 5 2000 00005 copyright : (C) 2000 by Michael Peeters 00006 email : Michael.Peeters@vub.ac.be 00007 ***************************************************************************/ 00008 00009 /*************************************************************************** 00010 * * 00011 * This program is free software; you can redistribute it and/or modify * 00012 * it under the terms of the GNU General Public License as published by * 00013 * the Free Software Foundation; either version 2 of the License, or * 00014 * (at your option) any later version. * 00015 * * 00016 ***************************************************************************/ 00017 00018 #ifndef DWELLPROBE_H 00019 #define DWELLPROBE_H 00020 00021 #include "probe.h" 00022 #include "bin.h" 00023 00024 namespace MODEL 00025 { 00026 00040 template<integer dims, typename nelem=number, class NT = NumericTraits<nelem,dims> > 00041 class DwellProbe : public Probe 00042 { 00043 public: 00044 typedef ODESystem<dims,nelem,NT> system; 00045 00046 DwellProbe(TimeFrame& T, 00047 const string& n, 00048 system& sys, 00049 integer v, 00050 number threshold, number range) : Probe (T,n), my_sys(&sys), 00051 var(v), 00052 th(threshold), ra(range) 00053 // range is the %of the threshold above or below to have a 00054 // definite switch - this is to avoid random paths thru the 00055 // middle, without a real switch taking place 00056 { 00057 // Set inital state 00058 more_or_less = (my_sys->get_current()[var] > th); 00059 last_t=T; 00060 avgn=0.; 00061 } 00062 00063 DwellProbe(TimeFrame& T, 00064 ostream& o, 00065 system& sys, 00066 integer v, 00067 number threshold, number range) : Probe (T,o), my_sys(&sys), 00068 var(v), 00069 th(threshold), ra(range) 00070 // range is the %of the threshold above or below to have a 00071 // definite switch - this is to avoid random paths thru the 00072 // middle, without a real switch taking place 00073 { 00074 // Set inital state 00075 more_or_less = (my_sys->get_current()[var] > th); 00076 last_t=T; 00077 avgn=0.; 00078 } 00079 00080 const number& switches(void) 00081 { 00082 return avgn; 00083 } 00084 00085 void probe(void) 00086 { 00087 bool now_more = (my_sys->get_current()[var] > (th*(1.+ra))); 00088 bool now_less = (my_sys->get_current()[var] < (th*(1.-ra))); 00089 00090 if(now_more!=now_less) // both false means in the middle 00091 if(now_more != more_or_less) 00092 { 00093 avgn++; 00094 number dt=get_time()-last_t; 00095 add_data(dt); 00096 add_data(now_more?1.:-1.); 00097 add_data(my_sys->get_current()[var]); 00098 00099 more_or_less=now_more; 00100 last_t=get_time(); 00101 } 00102 } 00103 00104 NO_COPY(DwellProbe); 00105 00106 private: 00107 system* my_sys; 00108 integer var; 00109 number th; 00110 number ra; 00111 00112 number avgn; 00113 00114 bool more_or_less; 00115 number last_t; 00116 00117 }; 00118 00125 template<integer dims, typename nelem=number, class NT = NumericTraits<nelem,dims> > 00126 class BinDwellProbe : public GenericProbe 00127 { 00128 public: 00129 typedef ODESystem<dims,nelem,NT> system; 00130 00131 BinDwellProbe(TimeFrame& T, 00132 const string& n, Bin& b_up, Bin& b_down, 00133 system& sys, 00134 integer v, 00135 number threshold) : GenericProbe (T,n), my_sys(&sys), 00136 var(v), th(threshold), 00137 my_b_up(&b_up), my_b_down(&b_down) 00138 { 00139 // Set inital state 00140 more_or_less = (my_sys->get_current()[var] > th); 00141 last_t=T; 00142 } 00143 00144 ~BinDwellProbe() 00145 { 00146 write_data(); 00147 } 00148 00149 virtual void print(ostream& out) 00150 { 00151 // Here, we write the data from the bin to the probe 00152 // First the up-data 00153 out << "# Dwell statistics for up state" << endl; 00154 00155 vector<number> bi=my_b_up->get_bins(); 00156 vector<counter> hi=my_b_up->get_histo(); 00157 00158 for(counter i=0;i<bi.size();i++) 00159 out << bi[i] << "\t" << hi[i] << endl; 00160 00161 // Then the down-data; extra endl fo Gnuplot 00162 out << endl << endl << "# Dwell statistics for down state" << endl; 00163 00164 bi=my_b_down->get_bins(); 00165 hi=my_b_down->get_histo(); 00166 00167 for(counter i=0;i<bi.size();i++) 00168 out << bi[i] << "\t" << hi[i] << endl; 00169 } 00170 00171 void probe(void) 00172 { 00173 bool now_more = (my_sys->get_current()[var] > th); 00174 if(now_more != more_or_less) 00175 { 00176 number dt=get_time()-last_t; 00177 avgn++; 00178 00179 if(more_or_less) //bugfix 00180 my_b_up->add_value(dt); 00181 else 00182 my_b_down->add_value(dt); 00183 00184 more_or_less=now_more; 00185 last_t=get_time(); 00186 } 00187 } 00188 00189 NO_COPY(BinDwellProbe); 00190 00191 private: 00192 system* my_sys; 00193 integer var; 00194 number th; 00195 number avgn; 00196 00197 Bin* my_b_up; 00198 Bin* my_b_down; 00199 00200 bool more_or_less; 00201 number last_t; 00202 00203 }; 00204 00208 template<integer dims, typename nelem=number, class NT = NumericTraits<nelem,dims> > 00209 class AVGDwellProbe : public Probe 00210 { 00211 public: 00212 typedef ODESystem<dims,nelem,NT> system; 00213 00215 AVGDwellProbe(TimeFrame& T, 00216 const string& n, 00217 system& sys, 00218 integer v, 00219 number threshold, 00220 number width=0.1,bool below=true) : Probe (T,n), my_sys(&sys), 00221 var(v), 00222 th(threshold), 00223 w(width*threshold), lower(below) 00224 { 00225 // Set inital state 00227 if(lower) 00228 more_or_less = (my_sys->get_current()[var] > (th+w))?1:-1; 00229 else 00230 more_or_less = (my_sys->get_current()[var] < (th-w))?-1:1; 00231 last_t=T; 00232 avg=0.;avgn=0.; 00233 } 00234 00235 const number& switches(void) 00236 { 00237 return avgn; 00238 } 00239 00240 const number& average(void) 00241 { 00242 return avg; 00243 } 00244 00245 void probe(void) 00246 { 00247 bool more = (my_sys->get_current()[var] > (th+w)); 00248 bool less = (my_sys->get_current()[var] < (th-w)); 00249 integer now_more=more?1:(less?-1:0); 00250 if(now_more != more_or_less) // if we have a change 00251 { 00252 if(lower){ 00256 if (now_more==0) // inside DMZ 00257 { 00258 // how did we enter 00259 from_top=(more_or_less==1); 00260 } 00261 if ((now_more==1) && !from_top) // and it is an up switch 00262 { 00263 number dt=get_time()-last_t; // get the time when we 00264 // swiched down 00265 avgn++; 00266 avg=((avgn-1.)*avg + dt)/avgn; // calculate average 00267 add_data(avg); // add the average 00268 } 00269 00270 if ((now_more==-1) && from_top) // down switch 00271 { 00272 last_t=get_time(); // keep this point 00273 } 00274 more_or_less=now_more; // keep the current state 00275 } 00276 else{ 00277 if (now_more==0) // inside DMZ 00278 { 00279 // how did we enter 00280 from_bottom=(more_or_less==-1); 00281 } 00282 if ((now_more==-1) && !from_bottom) // and it is a down switch 00283 { 00284 number dt=get_time()-last_t; // get the time when we 00285 // swiched up 00286 avgn++; 00287 avg=((avgn-1.)*avg + dt)/avgn; // calculate average 00288 add_data(avg); // add the average 00289 } 00290 00291 if ((now_more==1) && from_bottom) // up switch 00292 { 00293 last_t=get_time(); // keep this point 00294 } 00295 more_or_less=now_more; // keep the current state 00296 } 00297 } 00298 } 00299 NO_COPY(AVGDwellProbe); 00300 00301 private: 00302 system* my_sys; 00303 integer var; 00304 number th; 00305 number w; 00306 00307 number avg; 00308 number avgn; 00309 00315 integer more_or_less; 00316 bool from_top, from_bottom; 00317 bool lower; 00318 number last_t; 00319 00320 }; 00321 00322 } 00323 #endif 00324 00325 /********************************************************************* 00326 $Id: dwellprobe.h,v 1.1.2.3 2002/06/19 13:13:34 mpeeters Exp $ 00327 ********************************************************************** 00328 00329 $Log: dwellprobe.h,v $ 00330 Revision 1.1.2.3 2002/06/19 13:13:34 mpeeters 00331 Added threshold functionality with DMZ. 00332 00333 Revision 1.1.2.2 2001/09/03 10:22:18 mpeeters 00334 Added extra endl to allow for efficient gnuplot parsing. 00335 00336 Revision 1.1.2.1 2001/08/30 13:07:25 mpeeters 00337 Fixed bug #456813, where the binning in BinDwellProbe was inverted. 00338 00339 Revision 1.1 2001/05/22 10:54:55 mpeeters 00340 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter". 00341 00342 Revision 1.2 2001/05/21 11:53:16 mpeeters 00343 Removed Makefile.in, which is automatically generated anyway. 00344 00345 Revision 1.1 2000/10/13 11:20:22 mpeeters 00346 Added two new probes (which were in the 0.9 tarball, but which I forgot 00347 to add to the CVS). Removed history. 00348 00349 *********************************************************************/
More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be
Last update: June 2002.