<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>HippoDraw Class Library</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> <link rel="shortcut icon" href="hippoApp.ico"> </head><body> <!-- Generated by Doxygen 1.6.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_0274a9be98ae47925200be6537e3d505.html">functions</a> </div> </div> <div class="contents"> <h1>PowerLaw.cxx</h1><a href="PowerLaw_8cxx.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <a name="l00012"></a>00012 <span class="preprocessor">#ifdef _MSC_VER</span> <a name="l00013"></a>00013 <span class="preprocessor"></span><span class="preprocessor">#include "msdevstudio/MSconfig.h"</span> <a name="l00014"></a>00014 <span class="preprocessor">#endif</span> <a name="l00015"></a>00015 <span class="preprocessor"></span> <a name="l00016"></a>00016 <span class="preprocessor">#include "<a class="code" href="PowerLaw_8h.html" title="PowerLaw class interface.">PowerLaw.h</a>"</span> <a name="l00017"></a>00017 <a name="l00018"></a>00018 <span class="preprocessor">#include "<a class="code" href="FunctionHelper_8h.html" title="FunctionHelper class interface.">FunctionHelper.h</a>"</span> <a name="l00019"></a>00019 <a name="l00020"></a>00020 <span class="preprocessor">#include <cmath></span> <a name="l00021"></a>00021 <span class="preprocessor">#include <cassert></span> <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="preprocessor">#ifdef ITERATOR_MEMBER_DEFECT</span> <a name="l00024"></a>00024 <span class="preprocessor"></span><span class="keyword">using namespace </span>std; <a name="l00025"></a>00025 <span class="preprocessor">#else</span> <a name="l00026"></a>00026 <span class="preprocessor"></span><span class="keyword">using</span> std::max; <a name="l00027"></a>00027 <span class="keyword">using</span> std::vector; <a name="l00028"></a>00028 <span class="preprocessor">#endif</span> <a name="l00029"></a>00029 <span class="preprocessor"></span> <a name="l00030"></a>00030 <span class="keyword">namespace </span>hippodraw { <a name="l00031"></a>00031 <a name="l00032"></a><a class="code" href="classhippodraw_1_1PowerLaw.html#a3ee68e9f8e0262624dcb4eb7fd2204e9">00032</a> <a class="code" href="classhippodraw_1_1PowerLaw.html#a3ee68e9f8e0262624dcb4eb7fd2204e9" title="The default constructor.">PowerLaw::PowerLaw</a> ( ) <a name="l00033"></a>00033 { <a name="l00034"></a>00034 <a class="code" href="classhippodraw_1_1PowerLaw.html#a25a40b6614565f755233080a384c35f1" title="Initializes the function and parameters names.">initialize</a> (); <a name="l00035"></a>00035 } <a name="l00036"></a>00036 <a name="l00037"></a><a class="code" href="classhippodraw_1_1PowerLaw.html#ac52952f20e8c35975220a0ff8f91c1a3">00037</a> <a class="code" href="classhippodraw_1_1PowerLaw.html#a3ee68e9f8e0262624dcb4eb7fd2204e9" title="The default constructor.">PowerLaw::PowerLaw</a> ( <span class="keywordtype">double</span> prefactor, <span class="keywordtype">double</span> index ) <a name="l00038"></a>00038 { <a name="l00039"></a>00039 <a class="code" href="classhippodraw_1_1PowerLaw.html#a25a40b6614565f755233080a384c35f1" title="Initializes the function and parameters names.">initialize</a> (); <a name="l00040"></a>00040 <a name="l00041"></a>00041 <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[0] = prefactor; <a name="l00042"></a>00042 <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[1] = index; <a name="l00043"></a>00043 } <a name="l00044"></a>00044 <a name="l00045"></a><a class="code" href="classhippodraw_1_1PowerLaw.html#a25a40b6614565f755233080a384c35f1">00045</a> <span class="keywordtype">void</span> <a class="code" href="classhippodraw_1_1PowerLaw.html#a25a40b6614565f755233080a384c35f1" title="Initializes the function and parameters names.">PowerLaw::initialize</a> () <a name="l00046"></a>00046 { <a name="l00047"></a>00047 <a class="code" href="classhippodraw_1_1FunctionBase.html#adb41893ba19e889e56c559f25fc1a68a" title="The name of the function.">m_name</a> = <span class="stringliteral">"PowerLaw"</span>; <a name="l00048"></a>00048 <a class="code" href="classhippodraw_1_1FunctionBase.html#a96bf64e362e48f2ad4ecd76c32e4bc54" title="The names of the function parameters.">m_parm_names</a>.push_back ( <span class="stringliteral">"Prefactor"</span> ); <a name="l00049"></a>00049 <a class="code" href="classhippodraw_1_1FunctionBase.html#a96bf64e362e48f2ad4ecd76c32e4bc54" title="The names of the function parameters.">m_parm_names</a>.push_back ( <span class="stringliteral">"Index"</span> ); <a name="l00050"></a>00050 <a name="l00051"></a>00051 <a class="code" href="classhippodraw_1_1FunctionBase.html#a0fc3d585aa53859602ac79c9c421f2a9" title="Re-sizes the appropriate vectors maintained in this base class.">resize</a> (); <a name="l00052"></a>00052 } <a name="l00053"></a>00053 <a name="l00054"></a><a class="code" href="classhippodraw_1_1PowerLaw.html#a5e4b003c4faa8b7729e762445c7578d8">00054</a> <a class="code" href="classhippodraw_1_1FunctionBase.html" title="A function that can be added to a DataRep and used in a fitter.">FunctionBase</a> * <a class="code" href="classhippodraw_1_1PowerLaw.html#a5e4b003c4faa8b7729e762445c7578d8" title="Creates a new function object by copying an existing one.">PowerLaw::clone</a> ()<span class="keyword"> const</span> <a name="l00055"></a>00055 <span class="keyword"></span>{ <a name="l00056"></a>00056 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1PowerLaw.html#a3ee68e9f8e0262624dcb4eb7fd2204e9" title="The default constructor.">PowerLaw</a> ( *<span class="keyword">this</span> ); <a name="l00057"></a>00057 } <a name="l00058"></a>00058 <a name="l00059"></a><a class="code" href="classhippodraw_1_1PowerLaw.html#a3a71b677f013fdbc07bdf5dd65ee5f27">00059</a> <span class="keywordtype">double</span> <a class="code" href="classhippodraw_1_1PowerLaw.html#a3a71b677f013fdbc07bdf5dd65ee5f27" title="The function call operator.">PowerLaw::operator () </a>( <span class="keywordtype">double</span> x )<span class="keyword"> const</span> <a name="l00060"></a>00060 <span class="keyword"></span>{ <a name="l00061"></a>00061 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[0]*pow(x, <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[1]); <a name="l00062"></a>00062 } <a name="l00063"></a>00063 <a name="l00064"></a>00064 <span class="comment">/* virtual */</span> <a name="l00065"></a>00065 <span class="keywordtype">void</span> <a name="l00066"></a>00066 <a class="code" href="classhippodraw_1_1PowerLaw.html#ac89ece7f0010b352e8d897f0a352f811" title="Sets the FunctionHelper so that the function can calculate a reasonable set of initial...">PowerLaw::</a> <a name="l00067"></a><a class="code" href="classhippodraw_1_1PowerLaw.html#ac89ece7f0010b352e8d897f0a352f811">00067</a> <a class="code" href="classhippodraw_1_1PowerLaw.html#ac89ece7f0010b352e8d897f0a352f811" title="Sets the FunctionHelper so that the function can calculate a reasonable set of initial...">initialParameters</a> ( <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1FunctionHelper.html" title="An abstract base class to help FunctionBase objects perform some operations.">FunctionHelper</a> * helper ) <a name="l00068"></a>00068 { <a name="l00069"></a>00069 <span class="keywordtype">double</span> min_x = helper-><a class="code" href="classhippodraw_1_1FunctionHelper.html#aae8e27d24b633cfe806a30a6533e8581" title="Returns the smallest coordinate value along the X axis in the data set.">minCoord</a> (); <a name="l00070"></a>00070 <span class="keywordtype">double</span> max_x = helper-><a class="code" href="classhippodraw_1_1FunctionHelper.html#a719f9e98d819c68e7588583cf65a0ad5" title="Returns the largest coordinate value along the X axis in the data set.">maxCoord</a> (); <a name="l00071"></a>00071 max_x = (min_x + max_x)/2.; <a name="l00072"></a>00072 <a name="l00073"></a>00073 <span class="keywordtype">double</span> min_y, max_y; <a name="l00074"></a>00074 <span class="keywordflow">try</span> { <a name="l00075"></a>00075 min_y = helper-><a class="code" href="classhippodraw_1_1FunctionHelper.html#acc335283b093f009806131472a62fecf" title="Returns the value at a given coordinate.">valueAt</a>(min_x); <a name="l00076"></a>00076 max_y = helper-><a class="code" href="classhippodraw_1_1FunctionHelper.html#acc335283b093f009806131472a62fecf" title="Returns the value at a given coordinate.">valueAt</a>(max_x); <a name="l00077"></a>00077 <span class="keywordflow">if</span> (min_y != 0 && max_y != 0) { <a name="l00078"></a>00078 <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[1] = log( max_y/min_y ) / log( max_x/min_x ); <a name="l00079"></a>00079 <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[0] = max_y/pow(max_x, <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[1]); <a name="l00080"></a>00080 <span class="keywordflow">return</span>; <a name="l00081"></a>00081 } <a name="l00082"></a>00082 } <span class="keywordflow">catch</span> (...) { <a name="l00083"></a>00083 <span class="comment">// do nothing</span> <a name="l00084"></a>00084 } <a name="l00085"></a>00085 <a name="l00086"></a>00086 <span class="comment">// default behavior</span> <a name="l00087"></a>00087 min_y = max(helper-><a class="code" href="classhippodraw_1_1FunctionHelper.html#abad9bd56009500b7eab09eb640e3e52d" title="Returns the smallest value in the data set.">minValue</a>(), 1.); <a name="l00088"></a>00088 max_y = helper-><a class="code" href="classhippodraw_1_1FunctionHelper.html#a2be3e090b19415ac06d8388b5fc91fe2" title="Returns the largest value in the data set.">maxValue</a>(); <a name="l00089"></a>00089 <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[1] = log( max_y/min_y ) / log( max_x/min_x ); <a name="l00090"></a>00090 <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[0] = max_y/pow(max_x, <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[1]); <a name="l00091"></a>00091 } <a name="l00092"></a>00092 <a name="l00093"></a><a class="code" href="classhippodraw_1_1PowerLaw.html#a8617a1aa7536e4cb61f2a4ec29a39f36">00093</a> <span class="keywordtype">double</span> <a class="code" href="classhippodraw_1_1PowerLaw.html#a8617a1aa7536e4cb61f2a4ec29a39f36" title="Returns the function&#39;s derivative at the coordinate value x with respect to the...">PowerLaw::derivByParm</a> ( <span class="keywordtype">int</span> i, <span class="keywordtype">double</span> x )<span class="keyword"> const</span> <a name="l00094"></a>00094 <span class="keyword"></span>{ <a name="l00095"></a>00095 <span class="keywordflow">switch</span> ( i ) { <a name="l00096"></a>00096 <span class="keywordflow">case</span> 0 : <a name="l00097"></a>00097 <span class="keywordflow">return</span> pow(x, <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[1]); <a name="l00098"></a>00098 <span class="keywordflow">break</span>; <a name="l00099"></a>00099 <a name="l00100"></a>00100 <span class="keywordflow">case</span> 1 : <a name="l00101"></a>00101 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[0]*pow(x, <a class="code" href="classhippodraw_1_1FunctionBase.html#aa892dcf9755ccd651b666f353b723c34" title="The parameter values.">m_parms</a>[1])*log(x); <a name="l00102"></a>00102 <span class="keywordflow">break</span>; <a name="l00103"></a>00103 <a name="l00104"></a>00104 <span class="keywordflow">default</span>: <a name="l00105"></a>00105 assert ( <span class="keyword">false</span> ); <a name="l00106"></a>00106 <span class="keywordflow">break</span>; <a name="l00107"></a>00107 } <a name="l00108"></a>00108 <span class="keywordflow">return</span> 0.0; <a name="l00109"></a>00109 } <a name="l00110"></a>00110 <a name="l00111"></a>00111 } <span class="comment">// namespace hippodraw</span> <a name="l00112"></a>00112 </pre></div></div> <hr size="1"><address style="align: right;"><small> Generated for HippoDraw Class Library by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0> </a> </small></address> </body> </html>