Revision 304 trunk/contrib/statslib/dnorm.cpp

dnorm.cpp (revision 304)
21 21
* where \f$\mu\f$ is the mean and \f$\sigma\f$
22 22
* is the standard deviation.
23 23
* 
24
* The concentrated likelihood is implemented as:
25
* \f[
26
*  0.5 n \ln(\sum_{i=1}^{n}\epsilon^2)
27
* \f]
28
* where \f$ \epsilon \f$ is a vector of residuals with an assumed mean 0.
24 29
* 
25
* 
26 30
*/
27 31

  
28 32
/** 
......
187 191
}
188 192

  
189 193

  
194

  
190 195
/** 
191 196
	\author Steven James Dean Martell
192 197
	\date 2011-06-21
193 198
	\param  residual a variable vector of residuals
199
	\return returns the concentrated likelihood for the normal distribution.
200
	\sa
201
**/
202
dvariable dnorm( const dvar_vector& residual )
203
{
204
	RETURN_ARRAYS_INCREMENT();
205
	int n              = size_count(residual);
206
	dvariable SS       = norm2(residual);
207
	dvariable nloglike = 0.5*n*log(SS);
208
	RETURN_ARRAYS_DECREMENT();
209
	return(nloglike);
210
}
211

  
212
/** 
213
	\author Steven James Dean Martell
214
	\date 2011-06-21
215
	\param  obs a matrix of observed values
216
	\param  pred a variable matrix of predicted values
217
	\return returns the concentrated likelihood for the normal distribution.
218
	\sa
219
**/
220
dvariable dnorm( const dmatrix& obs, const dvar_matrix& pred)
221
{
222
	RETURN_ARRAYS_INCREMENT();
223
	int n = size_count(obs);
224
	dvariable SS = sum(elem_div(square(obs-pred),0.01+pred));
225
	RETURN_ARRAYS_DECREMENT();
226
	return 0.5*n*log(SS);
227
}
228

  
229

  
230

  
231
/** 
232
	\author Steven James Dean Martell
233
	\date 2011-06-21
234
	\param  residual a variable vector of residuals
194 235
	\param  std a variable vector of standard deviations
195 236
	\return returns the sum of negative loglikelihoods of the normal distribution
196 237
	\sa

Also available in: Unified diff