ADMB Documentation  11.5.3197
 All Classes Files Functions Variables Typedefs Friends Defines
dlnorm.cpp
Go to the documentation of this file.
00001 #include "statsLib.h"
00002 
00036 dvariable dlnorm( const prevariable& x, const double& mu, const double& std )
00037 { 
00038   
00039   if( std<=0 || x<=0 ) 
00040   {
00041     cerr<<"Standard deviation or the mean is less than or equal to zero in "
00042     "dlnorm( const dvariable& x, const double& mu, const double& std )\n";
00043     return 0;
00044   }
00045   
00046   return 0.5*log(2.*M_PI)+log(std)+log(x)+square(log(x)-mu)/(2.*std*std);
00047 }
00048 
00058 dvariable dlnorm( const prevariable& x, const prevariable& mu, const double& std )
00059 { 
00060   
00061   if( std<=0 || x<=0 ) 
00062   {
00063     cerr<<"Standard deviation or the mean is less than or equal to zero in "
00064     "dlnorm( const dvariable& x, const dvariable& mu, const double& std )\n";
00065     return 0;
00066   }
00067   
00068   return 0.5*log(2.*M_PI)+log(std)+log(x)+square(log(x)-mu)/(2.*std*std);
00069 }
00070 
00080 dvariable dlnorm( const prevariable& x, const prevariable& mu, const prevariable& std )
00081 { 
00082   
00083   if( std<=0 || x<=0 ) 
00084   {
00085     cerr<<"Standard deviation or the mean is less than or equal to zero in "
00086     "dlnorm( const dvariable& x, const dvariable& mu, const dvariable& std )\n";
00087     return 0;
00088   }
00089   
00090   return 0.5*log(2.*M_PI)+log(std)+log(x)+square(log(x)-mu)/(2.*std*std);
00091 }
00092 
00102 dvariable dlnorm( const dvar_vector& x, const double& mu, const double& std )
00103 {
00104   
00105   if( std<=0 || min(x)<=0 )
00106   {
00107     cerr<<"Standard deviation or the mix(x) is less than or equal to zero in "
00108     "dlnorm( const dvar_vector& x, const double& mu, const double& std )\n";
00109     return 0;
00110   }
00111   
00112   RETURN_ARRAYS_INCREMENT();
00113   long n=size_count(x);
00114   dvariable ss = norm2( log(x)-mu );
00115   dvariable t1 = n*(0.5*log(2*M_PI)+log(std));
00116   dvariable nloglike = t1 + sum(log(x)) + ss/(2.*std*std);
00117   RETURN_ARRAYS_DECREMENT();
00118   return nloglike;  
00119 }
00120 
00130 dvariable dlnorm( const dvar_vector& x, const prevariable& mu, const double& std )
00131 {
00132   
00133   if( std<=0 || min(x)<=0 )
00134   {
00135     cerr<<"Standard deviation or the mix(x) is less than or equal to zero in "
00136     "dlnorm( const dvar_vector& x, const dvariable& mu, const double& std )\n";
00137     return 0;
00138   }
00139   
00140   RETURN_ARRAYS_INCREMENT();
00141   long n=size_count(x);
00142   dvariable ss = norm2( log(x)-mu );
00143   dvariable t1 = n*(0.5*log(2*M_PI)+log(std));
00144   dvariable nloglike = t1 + sum(log(x)) + ss/(2.*std*std);
00145   RETURN_ARRAYS_DECREMENT();
00146   return nloglike;  
00147 }
00148 
00158 dvariable dlnorm( const dvar_vector& x, const prevariable& mu, const prevariable& std )
00159 {
00160   
00161   if( std<=0 || min(x)<=0 )
00162   {
00163     cerr<<"Standard deviation or the mix(x) is less than or equal to zero in "
00164     "dlnorm( const dvar_vector& x, const dvariable& mu, const dvariable& std )\n";
00165     return 0;
00166   }
00167   
00168   RETURN_ARRAYS_INCREMENT();
00169   long n=size_count(x);
00170   dvariable ss = norm2( log(x)-mu );
00171   dvariable t1 = n*(0.5*log(2*M_PI)+log(std));
00172   dvariable nloglike = t1 + sum(log(x)) + ss/(2.*std*std);
00173   RETURN_ARRAYS_DECREMENT();
00174   return nloglike;  
00175 }
00176