# lhobbslik.R
# 4 parameter negative log likelihood for weeds problem in 
#  log scale for all parameters
#  and we use shobb.res form using simple scaling parameters
# need source("lhobbs.R")

lhobbs.lik<-function(xaug,y=y0){ # likelihood function including sigma
  xl<-xaug[1:3]
  logSigma<-xaug[4]
  sigma2=exp(2.0*logSigma);
  res<-lhobbs.res(xl,y)
  nll<-0.5*(length(res)*log(2*pi*sigma2)+sum(res*res)/sigma2)
}

lhobbs.lg<-function(xaug,y=y0){ # gradient function including sigma
  xl<-xaug[1:3]
  logSigma<-xaug[4]
  sigma2=exp(2.0*logSigma);
  res3<-lhobbs.res(xl,y)
  n<-length(res3)
  f3<-crossprod(res3)
  g3<-0.5*lhobbs.g(xl,y)/sigma2
  gg<-c(g3,(n - f3/sigma2))
}
