LogNormal.cxx

Go to the documentation of this file.
00001 
00012 #ifdef _MSC_VER
00013 #include "msdevstudio/MSconfig.h"
00014 #endif
00015 
00016 #include "LogNormal.h"
00017 
00018 #include "FunctionHelper.h"
00019 
00020 #include <cmath>
00021 #include <cassert>
00022 
00023 using std::distance;
00024 
00025 using std::exp;
00026 using std::vector;
00027 
00028 namespace {
00031   enum { norm = 0, mu = 1, sigma = 2 };
00032 }
00033 
00034 using namespace hippodraw;
00035 
00036 LogNormal::LogNormal ( )
00037 {
00038   initialize ();
00039 }
00040 
00041 LogNormal::LogNormal ( double n, double m, double s )
00042 {
00043   initialize ();
00044   
00045   m_parms[norm] = n;
00046   m_parms[mu] = m;
00047   m_parms[sigma] = s;
00048 }
00049 
00050 void LogNormal::initialize ()
00051 {
00052   m_name = "LogNormal";
00053 
00054   m_parm_names.push_back ( "Norm" );
00055   m_parm_names.push_back ( "Mu" );
00056   m_parm_names.push_back ( "Sigma" );
00057 
00058   resize ();
00059 }
00060 
00061 FunctionBase * LogNormal::clone () const
00062 {
00063   return new LogNormal ( *this );
00064 }
00065 
00066 double LogNormal::operator () ( double x ) const
00067 {
00068   double t = ( log ( x ) - m_parms[mu] ) / m_parms[sigma];
00069   double result = m_parms[norm] * exp ( -0.5 * t*t );
00070 
00071   return result;
00072 }
00073 
00076 void 
00077 LogNormal::
00078 initialParameters ( const FunctionHelper * helper )
00079 {
00080   m_parms[norm] = 1.0;
00081   m_parms[mu] =  log ( helper->meanCoord () );
00082   m_parms[sigma] = 0.5;
00083 }
00084 
00085 double
00086 LogNormal::
00087 derivByParm ( int , double ) const
00088 {
00089   assert ( false );
00090   return 0.;
00091 }
00092 
00093 bool
00094 LogNormal::
00095 hasDerivatives () const
00096 {
00097   return false;
00098 }

Generated for HippoDraw Class Library by doxygen