• Main Page
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

mapunim.h

Go to the documentation of this file.
00001 /// @addtogroup unifexp
00002 /// @{
00003 
00004 /////////////////////////////////////////////////////////////////////////////
00005 ///
00006 /// @file mapunim.h
00007 ///
00008 /// This file contains the definition of the unimodal map "2|x|^gamma - a"
00009 /// on [-1,1] without using interval arithmetic
00010 /// for non-rigorous computations.
00011 ///
00012 /// @author Pawel Pilarczyk
00013 ///
00014 /////////////////////////////////////////////////////////////////////////////
00015 
00016 // Copyright (C) 2007 by Pawel Pilarczyk.
00017 //
00018 // This file is part of my research program package.  This is free software;
00019 // you can redistribute it and/or modify it under the terms of the GNU
00020 // General Public License as published by the Free Software Foundation;
00021 // either version 2 of the License, or (at your option) any later version.
00022 //
00023 // This software is distributed in the hope that it will be useful,
00024 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00025 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00026 // GNU General Public License for more details.
00027 //
00028 // You should have received a copy of the GNU General Public License along
00029 // with this software; see the file "license.txt".  If not, write to the
00030 // Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
00031 // MA 02111-1307, USA.
00032 
00033 // Started on August 23, 2007. Last revision: August 23, 2007.
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 // ---------------- the unimodal map ----------------
00048 // --------------------------------------------------
00049 
00050 /// This class defines the unimodal map "2 |x|^gamma - a" on [-1,1]
00051 /// without using interval arithmetic.
00052 /// It is suitable for non-rigorous computations.
00053 /// See the class "mapUnimodalIntv" for a rigorous version which does use
00054 /// interval arithmetic.
00055 /// Recommended values of gamma are between 1 and 3.
00056 /// Valid values of the parameter are between 0.5+ and 1 (optimal value: 1).
00057 template <class numType>
00058 class mapUnimodal: public mapType<numType>
00059 {
00060 public:
00061         /// The constructor.
00062         mapUnimodal (const numType &_gamma);
00063 
00064         /// Returns the name of the object.
00065         std::string name () const;
00066 
00067         /// Returns the number of critical points.
00068         int countCritical () const;
00069 
00070         /// Returns the subsequent critical points.
00071         numType criticalPoint (int n) const;
00072 
00073         /// Returns the left bound of the domain of the map.
00074         numType leftBound () const;
00075 
00076         /// Returns the right bound of the domain of the map.
00077         numType rightBound () const;
00078 
00079         /// Computes an enclosure of the image of the given interval.
00080         void image (const numType &x1, const numType &x2,
00081                 numType &y1, numType &y2) const;
00082 
00083         /// Computes the minimal log of the derivative over those points
00084         /// in the interval [x1,x2] whose images may fall into [y1,y2]
00085         numType minLogDerivative (const numType &x1, const numType &x2,
00086                 const numType &y1, const numType &y2) const;
00087 
00088 private:
00089         /// The exponent of the map.
00090         numType gamma;
00091 
00092         /// An auxiliary function for the computation of the absolute value
00093         /// of a number raised to the power gamma.
00094         numType gammaPower (numType x) const;
00095 
00096         /// An auxiliary function for the computation of the absolute value
00097         /// of a number raised to the power gamma - 1.
00098         numType gammaPower1 (numType x) const;
00099 
00100         /// An auxiliary function for the computation of the root of degree
00101         /// gamma of the absolute value of a number.
00102         numType gammaRoot (numType x) const;
00103 
00104 }; /* mapUnimodal */
00105 
00106 // --------------------------------------------------
00107 
00108 template <class numType>
00109 inline mapUnimodal<numType>::mapUnimodal (const numType &_gamma):
00110         gamma (_gamma)
00111 {
00112         return;
00113 } /* mapUnimodal::mapUnimodal */
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 } /* mapUnimodal::name */
00122 
00123 template <class numType>
00124 inline int mapUnimodal<numType>::countCritical () const
00125 {
00126         return 1;
00127 } /* mapUnimodal::countCritical */
00128 
00129 template <class numType>
00130 inline numType mapUnimodal<numType>::criticalPoint (int n) const
00131 {
00132         return 0.0;
00133 } /* mapUnimodal::criticalPoint */
00134 
00135 template <class numType>
00136 inline numType mapUnimodal<numType>::leftBound () const
00137 {
00138         return -1;
00139 } /* mapUnimodal::leftBound */
00140 
00141 template <class numType>
00142 inline numType mapUnimodal<numType>::rightBound () const
00143 {
00144         return 1;
00145 } /* mapUnimodal::rightBound */
00146 
00147 template <class numType>
00148 inline numType mapUnimodal<numType>::gammaPower (numType x) const
00149 {
00150         // return x if raising to power 1
00151 //      const numType one (1);
00152 //      if (gamma == one)
00153 //              return x;
00154 
00155         // return 0 if x is zero
00156         const numType zero (0);
00157         if (x == zero)
00158                 return zero;
00159 
00160         // make x positive if it is negative
00161         if (x < zero)
00162                 x = -x;
00163 
00164         // return x to the power gamma
00165         return exp (log (x) * gamma);
00166 
00167 } /* mapUnimodal::gammaPower */
00168 
00169 template <class numType>
00170 inline numType mapUnimodal<numType>::gammaPower1 (numType x) const
00171 {
00172         // return x if raising to power 1
00173 //      const numType two (2);
00174 //      if (gamma == two)
00175 //              return x;
00176 
00177         // return 1 if raising to power 0
00178 //      const numType one (1);
00179 //      if (gamma == one)
00180 //              return 1;
00181 
00182         // return 0 if x is zero
00183         const numType zero (0);
00184         if (x == zero)
00185                 return zero;
00186 
00187         // make x positive if it is negative
00188         if (x < zero)
00189                 x = -x;
00190 
00191         // return x to the power gamma
00192         return exp (log (x) * (gamma - 1));
00193 
00194 } /* mapUnimodal::gammaPower1 */
00195 
00196 template <class numType>
00197 inline numType mapUnimodal<numType>::gammaRoot (numType x) const
00198 {
00199         // return x if computing the root of degree 1
00200 //      const numType one (1);
00201 //      if (gamma == one)
00202 //              return x;
00203 
00204         // return 0 if x is zero
00205         const numType zero (0);
00206         if (x == zero)
00207                 return zero;
00208 
00209         // make x positive if it is negative
00210         if (x < zero)
00211                 x = -x;
00212 
00213         // return the root of degree gamma of x
00214         return exp (log (x) / gamma);
00215 
00216 } /* mapUnimodal::gammaRoot */
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 } /* mapUnimodal::image */
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         // make sure the input data is correct
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         // compute the positive preimage of the interval [y1,y2],
00256         // intersect the computed preimage with the interval [x1,x2],
00257         // and return the log of the derivative at the endpoint at which
00258         // the derivative is minimal (right for gamma < 1, left otherwise)
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 } /* mapUnimodal::minLogDerivative */
00278 
00279 
00280 } // namespace unifexp
00281 
00282 #endif // _mapunim_h_
00283 
00284 /// @}
00285 

Generated on Sun Feb 3 2013 12:40:31 for The Uniform Expansion Software by  doxygen 1.7.2