Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _mapunim_h_
00036 #define _mapunim_h_
00037
00038 #include <string>
00039 #include <iostream>
00040 #include <sstream>
00041 #include "maptype.h"
00042
00043
00044 namespace unifexp {
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057 template <class numType>
00058 class mapUnimodal: public mapType<numType>
00059 {
00060 public:
00061
00062 mapUnimodal (const numType &_gamma);
00063
00064
00065 std::string name () const;
00066
00067
00068 int countCritical () const;
00069
00070
00071 numType criticalPoint (int n) const;
00072
00073
00074 numType leftBound () const;
00075
00076
00077 numType rightBound () const;
00078
00079
00080 void image (const numType &x1, const numType &x2,
00081 numType &y1, numType &y2) const;
00082
00083
00084
00085 numType minLogDerivative (const numType &x1, const numType &x2,
00086 const numType &y1, const numType &y2) const;
00087
00088 private:
00089
00090 numType gamma;
00091
00092
00093
00094 numType gammaPower (numType x) const;
00095
00096
00097
00098 numType gammaPower1 (numType x) const;
00099
00100
00101
00102 numType gammaRoot (numType x) const;
00103
00104 };
00105
00106
00107
00108 template <class numType>
00109 inline mapUnimodal<numType>::mapUnimodal (const numType &_gamma):
00110 gamma (_gamma)
00111 {
00112 return;
00113 }
00114
00115 template <class numType>
00116 inline std::string mapUnimodal<numType>::name () const
00117 {
00118 std::ostringstream nameStr;
00119 nameStr << "unimodal-" << gamma;
00120 return nameStr. str ();
00121 }
00122
00123 template <class numType>
00124 inline int mapUnimodal<numType>::countCritical () const
00125 {
00126 return 1;
00127 }
00128
00129 template <class numType>
00130 inline numType mapUnimodal<numType>::criticalPoint (int n) const
00131 {
00132 return 0.0;
00133 }
00134
00135 template <class numType>
00136 inline numType mapUnimodal<numType>::leftBound () const
00137 {
00138 return -1;
00139 }
00140
00141 template <class numType>
00142 inline numType mapUnimodal<numType>::rightBound () const
00143 {
00144 return 1;
00145 }
00146
00147 template <class numType>
00148 inline numType mapUnimodal<numType>::gammaPower (numType x) const
00149 {
00150
00151
00152
00153
00154
00155
00156 const numType zero (0);
00157 if (x == zero)
00158 return zero;
00159
00160
00161 if (x < zero)
00162 x = -x;
00163
00164
00165 return exp (log (x) * gamma);
00166
00167 }
00168
00169 template <class numType>
00170 inline numType mapUnimodal<numType>::gammaPower1 (numType x) const
00171 {
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183 const numType zero (0);
00184 if (x == zero)
00185 return zero;
00186
00187
00188 if (x < zero)
00189 x = -x;
00190
00191
00192 return exp (log (x) * (gamma - 1));
00193
00194 }
00195
00196 template <class numType>
00197 inline numType mapUnimodal<numType>::gammaRoot (numType x) const
00198 {
00199
00200
00201
00202
00203
00204
00205 const numType zero (0);
00206 if (x == zero)
00207 return zero;
00208
00209
00210 if (x < zero)
00211 x = -x;
00212
00213
00214 return exp (log (x) / gamma);
00215
00216 }
00217
00218 template <class numType>
00219 inline void mapUnimodal<numType>::image (const numType &x1,
00220 const numType &x2, numType &y1, numType &y2) const
00221 {
00222 if (x2 < x1)
00223 throw "Image computation: Wrong interval for 'x'.";
00224 if (x1 > 0)
00225 {
00226 y1 = 2 * gammaPower (x1) - this -> paramMax;
00227 y2 = 2 * gammaPower (x2) - this -> paramMin;
00228 }
00229 else if (x2 < 0)
00230 {
00231 y1 = 2 * gammaPower (-x2) - this -> paramMax;
00232 y2 = 2 * gammaPower (-x1) - this -> paramMin;
00233 }
00234 else
00235 {
00236 y2 = 2 * gammaPower ((-x1 < x2) ? x2 : -x1) -
00237 this -> paramMin;
00238 y1 = -this -> paramMax;
00239 }
00240 return;
00241 }
00242
00243 template <class numType>
00244 inline numType mapUnimodal<numType>::minLogDerivative (const numType &x1,
00245 const numType &x2, const numType &y1, const numType &y2) const
00246 {
00247
00248 if (x2 < x1)
00249 throw "MinLogDerivative: Wrong interval for 'x'.";
00250 if (y2 < y1)
00251 throw "MinLogDerivative: Wrong interval for 'y'.";
00252 if ((x1 <= 0) && (0 <= x2))
00253 throw "MinLogDerivative: The interval contains zero.";
00254
00255
00256
00257
00258
00259 if (gamma < 1)
00260 {
00261 const numType sum = ((y2 + this -> paramMax) / 2);
00262 const numType preImg = (0 < sum) ? gammaRoot (sum) : 0;
00263 const numType x = (0 < x1) ? x2 : -x1;
00264 const numType endPoint = (x < preImg) ? x : preImg;
00265 return log (2 * gamma) + (gamma - 1) * log (endPoint);
00266 }
00267 else
00268 {
00269 const numType sum = ((y1 + this -> paramMin) / 2);
00270 if ((sum < 0) || (sum == 0))
00271 throw "MinLogDerivative: Zero in the preimage.";
00272 const numType preImg = (0 < sum) ? gammaRoot (sum) : 0;
00273 const numType x = (0 < x1) ? x1 : -x2;
00274 const numType endPoint = (x < preImg) ? preImg : x;
00275 return log (2 * gamma) + (gamma - 1) * log (endPoint);
00276 }
00277 }
00278
00279
00280 }
00281
00282 #endif // _mapunim_h_
00283
00284
00285