sp_densityfnct.h
Go to the documentation of this file.
1 /** @file sp_densityfnct.h Discrete density function approximation */
2 
3 /*
4  Copyright (C) 2008 Thomas Moor
5  Exclusive copyright is granted to Klaus Schmidt
6 */
7 
8 
9 #ifndef FAUDES_SP_DENSITYFNCT_H
10 #define FAUDES_SP_DENSITYFNCT_H
11 
12 #include "corefaudes.h"
13 #include "tp_include.h"
14 
15 
16 namespace faudes {
17 
18 /**
19 
20 Density Function
21 
22 A DiscreteDensityFnction models a piecewise constant
23 map with non-negative support. It consists of a
24 sorted vector (aka map) of disjoint time intervals
25 with one associated value each.
26 
27 The current implementation is rather incomplete,
28 inefficient, and buggy. The ToDo list includes
29 - we assume consecutive right open intervals, so either
30  assert the restriction or implement more general
31 - we assume an integer time type, so either assert the restriction
32  or implement more general
33 - fix token io
34 - need proper access methods
35 - implement method to evaluate random variable with given density
36 - generalise to class DensityFunction to include some continuous functions
37  eg exponential, gauss
38 - have this a proper faudes type
39 
40 
41 */
43 
44  public:
45 
46  // construct destruct
48  virtual ~DiscreteDensityFunction(void) {};
49 
50  // clear all
51  virtual void Clear(void);
52 
53  // get values
54  double Value(Time::Type time) const;
55  const TimeInterval& TimeInt(Time::Type time) const;
56 
57  // data per support interval
58  typedef struct {
59  TimeInterval timeint; // support
60  double value; // value
61  } Entry;
62 
63  // convenience typedef
64  typedef std::map<Time::Type,Entry>::const_iterator CIterator;
65  typedef std::map<Time::Type,Entry>::iterator Iterator;
66 
67  // access map
68  CIterator Begin(void) const { return mValueMap.begin();} ;
69  CIterator End(void) const { return mValueMap.end();} ;
70  CIterator At(Time::Type time) const { return mValueMap.lower_bound(time);} ;
71  const TimeInterval& TimeInt(CIterator mit) const { return mit->second.timeint;};
72  const double& Value(CIterator mit) const { return mit->second.value;};
73 
74  // access map (should be protected)
75  Iterator Begin(void) { return mValueMap.begin();} ;
76  Iterator End(void) { return mValueMap.end();} ;
77  Iterator At(Time::Type time) { return mValueMap.lower_bound(time);} ;
78  const Entry& EntryAt(Time::Type time) const;
79 
80  // get/set name
81  const std::string& Name(void) const { return mName;};
82  void Name(const std::string& rName) { mName=rName;};
83 
84  // get/set count (-1 for not avail)
85  int Count(void) const { return mCount;};
86  void Count(int count) { mCount= count;};
87 
88  // get characteristics (set by compile)
89  double MaxValue(void) const { return mMaxValue; };
90  double MinValue(void) const { return mMinValue; };
91  Time::Type MaxTime(void) const { return mMaxTime; };
92  Time::Type MinTime(void) const { return mMinTime; };
93  double Sum(void) const { return mSum; };
94  double SquareSum(void) const { return mSquareSum; };
95  double Average(void) const { return mAverage; };
96  double Variance(void) const { return mVariance; };
97  double Quantile05(void) const { return mQuantile05; };
98  double Quantile95(void) const { return mQuantile95; };
99 
100  // file io
101  void Write(TokenWriter& rTw) const;
102  void Write(void) const;
103  std::string ToString(void) const;
104  void Read(TokenReader& rTr);
105 
106  // compute characteristics
107  void Compile(void) const;
108 
109  // pretty string
110  std::string Str(void) const;
111 
112  protected:
113 
114  // map of all support intervals
115  std::map<Time::Type,Entry> mValueMap;
116 
117  // user data
118  std::string mName;
119  int mCount;
120 
121  // characteristics
122  double mMaxValue;
123  double mMinValue;
126  double mSum;
127  double mSquareSum;
128  double mAverage;
129  double mVariance;
130  double mQuantile05;
131  double mQuantile95;
132 
133  // compute characteristics (non const version)
134  virtual void CompileNonConst(void);
135 
136  // pseudo static zero entry
138 };
139 
140 
141 
142 /*
143 
144 Sampled Density Function
145 
146 A SampledDensityFunction is a DiscreteDensityFunction that
147 is set up by sampling experiment outcome. This implementation
148 attempts to be smart in choosing sampling intervals and, hence,
149 requires minimal configuration.
150 
151 The current implementation is rather incomplete,
152 inefficient, and buggy. The ToDo list includes
153 - interface incomplete
154 - compilation faulty
155 - no token io
156 - need to improve automatic sampling interval selection
157 
158 */
159 
161 
162  public:
163 
164  // construct destruct
166  virtual ~SampledDensityFunction(void) {};
167 
168  // set/get dimension
169  void Dim(Idx dim) { mDim=dim; Clear();};
170  Idx Dim(void) const { return mDim;};
171 
172  // clear all
173  void Clear(void);
174 
175  // add sample
176  void Sample(Time::Type time);
177 
178  // pretty string
179  std::string SStr(void) const;
180 
181  protected:
182 
183  // data per support interval
184  typedef struct {
185  TimeInterval timeint; // support
186  Idx count; // count
187  } CountEntry;
188 
189  // convenience typedef
190  typedef std::map<Time::Type,CountEntry>::iterator CountIterator;
191  typedef std::map<Time::Type,CountEntry>::const_iterator CCountIterator;
192 
193  // map of all support intervals
194  std::map<Time::Type,CountEntry> mCountMap;
195 
196  // my target dimension;
198 
199  // overall count
200  double mCountSum;
202 
203  // compute characteristics (non const version)
204  virtual void CompileNonConst(void);
205 
206 };
207 
208 
209 
210 
211 
212 } // namespace
213 
214 #endif
#define FAUDES_API
Interface export/import symbols: windows.
Definition: cfl_platform.h:80
void Name(const std::string &rName)
std::map< Time::Type, Entry > mValueMap
CIterator End(void) const
std::map< Time::Type, Entry >::iterator Iterator
const std::string & Name(void) const
const TimeInterval & TimeInt(CIterator mit) const
const double & Value(CIterator mit) const
CIterator Begin(void) const
Time::Type MaxTime(void) const
CIterator At(Time::Type time) const
Time::Type MinTime(void) const
std::map< Time::Type, Entry >::const_iterator CIterator
Iterator At(Time::Type time)
std::map< Time::Type, CountEntry >::iterator CountIterator
std::map< Time::Type, CountEntry >::const_iterator CCountIterator
std::map< Time::Type, CountEntry > mCountMap
Model of a time interval.
Int Type
Datatype for point on time axis.
A TokenReader reads sequential tokens from a file or string.
A TokenWriter writes sequential tokens to a file, a string or stdout.
Includes all libFAUDES headers, no plugins.
libFAUDES resides within the namespace faudes.
uint32_t Idx
Type definition for index type (allways 32bit)
Include timed plugin headers.

libFAUDES 2.32f --- 2024.12.22 --- c++ api documentaion by doxygen