ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dlnorm.cpp
Go to the documentation of this file.
1 #include "statsLib.h"
2 
36 dvariable dlnorm( const prevariable& x, const double& mu, const double& std )
37 {
38 
39  if( std<=0 || x<=0 )
40  {
41  cerr<<"Standard deviation or the mean is less than or equal to zero in "
42  "dlnorm( const dvariable& x, const double& mu, const double& std )\n";
43  return 0;
44  }
45 
46  return 0.5*log(2.*M_PI)+log(std)+log(x)+square(log(x)-mu)/(2.*std*std);
47 }
48 
58 dvariable dlnorm( const prevariable& x, const prevariable& mu, const double& std )
59 {
60 
61  if( std<=0 || x<=0 )
62  {
63  cerr<<"Standard deviation or the mean is less than or equal to zero in "
64  "dlnorm( const dvariable& x, const dvariable& mu, const double& std )\n";
65  return 0;
66  }
67 
68  return 0.5*log(2.*M_PI)+log(std)+log(x)+square(log(x)-mu)/(2.*std*std);
69 }
70 
80 dvariable dlnorm( const prevariable& x, const prevariable& mu, const prevariable& std )
81 {
82 
83  if( std<=0 || x<=0 )
84  {
85  cerr<<"Standard deviation or the mean is less than or equal to zero in "
86  "dlnorm( const dvariable& x, const dvariable& mu, const dvariable& std )\n";
87  return 0;
88  }
89 
90  return 0.5*log(2.*M_PI)+log(std)+log(x)+square(log(x)-mu)/(2.*std*std);
91 }
92 
102 dvariable dlnorm( const dvar_vector& x, const double& mu, const double& std )
103 {
104 
105  if( std<=0 || min(x)<=0 )
106  {
107  cerr<<"Standard deviation or the mix(x) is less than or equal to zero in "
108  "dlnorm( const dvar_vector& x, const double& mu, const double& std )\n";
109  return 0;
110  }
111 
113  long n=size_count(x);
114  dvariable ss = norm2( log(x)-mu );
115  dvariable t1 = n*(0.5*log(2*M_PI)+log(std));
116  dvariable nloglike = t1 + sum(log(x)) + ss/(2.*std*std);
118  return nloglike;
119 }
120 
130 dvariable dlnorm( const dvar_vector& x, const prevariable& mu, const double& std )
131 {
132 
133  if( std<=0 || min(x)<=0 )
134  {
135  cerr<<"Standard deviation or the mix(x) is less than or equal to zero in "
136  "dlnorm( const dvar_vector& x, const dvariable& mu, const double& std )\n";
137  return 0;
138  }
139 
141  long n=size_count(x);
142  dvariable ss = norm2( log(x)-mu );
143  dvariable t1 = n*(0.5*log(2*M_PI)+log(std));
144  dvariable nloglike = t1 + sum(log(x)) + ss/(2.*std*std);
146  return nloglike;
147 }
148 
158 dvariable dlnorm( const dvar_vector& x, const prevariable& mu, const prevariable& std )
159 {
160 
161  if( std<=0 || min(x)<=0 )
162  {
163  cerr<<"Standard deviation or the mix(x) is less than or equal to zero in "
164  "dlnorm( const dvar_vector& x, const dvariable& mu, const dvariable& std )\n";
165  return 0;
166  }
167 
169  long n=size_count(x);
170  dvariable ss = norm2( log(x)-mu );
171  dvariable t1 = n*(0.5*log(2*M_PI)+log(std));
172  dvariable nloglike = t1 + sum(log(x)) + ss/(2.*std*std);
174  return nloglike;
175 }
176 
Base class for dvariable.
Definition: fvar.hpp:1315
void RETURN_ARRAYS_DECREMENT(void)
Decrements gradient_structure::RETURN_ARRAYS_PTR.
Definition: gradstrc.cpp:507
dvariable dlnorm(const prevariable &x, const double &mu, const double &std)
Definition: dlnorm.cpp:36
#define x
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
ADMB variable vector.
Definition: fvar.hpp:2172
#define min(a, b)
Definition: cbivnorm.cpp:188
double norm2(const d3_array &a)
Return sum of squared elements in a.
Definition: d3arr2a.cpp:167
Library of statistic functions.
unsigned int size_count(const dvector &x)
Returns total size of elements in vector x.
Definition: dsize.cpp:17
void RETURN_ARRAYS_INCREMENT(void)
Increments gradient_structure::RETURN_ARRAYS_PTR.
Definition: gradstrc.cpp:474
#define M_PI
Definition: fvar.hpp:92
double square(const double value)
Return square of value; constant object.
Definition: d3arr4.cpp:16
Fundamental data type for reverse mode automatic differentiation.
Definition: fvar.hpp:1518
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13