Displaying 2 results from an estimated 2 matches for "objgrad".
2012 Mar 20
2
Constraint Linear regression
...# The objective function : least squares.
e<-expression((y-(c1+c2*x1+c3*x2))^2)
foo<-deriv(e, name=c("c1","c2","c3"))
# Objective
objfun<-function(coefs, data) {
return(sum(eval(foo,env=c(as.list(coefs), as.list(data)))))
}
# Objective's gradient
objgrad<-function(coefs, data) {
return(apply(attr(eval(foo,env=c(as.list(coefs), as.list(data))),
"gradient"),2,sum))
}
D1.unbound<-optim(par=c(c1=0.5, c2=0.5, c3=0.5),
fn=objfun,
gr=objgrad,
data=Data1,
method="L-BFGS-B",
lower=rep(0, 3),
upper=rep(1, 3))
D1.un...
2009 Jun 01
1
installing sn package
...a
constructed
> # environment
>
> foo<-deriv(e, nam=c("c1","c2","c3"))
>
> # Objective
>
> objfun<-function(coefs, data) {
+ return(sum(eval(foo,env=c(as.list(coefs), as.list(data)))))
+ }
>
> # Objective's gradient
>
> objgrad<-function(coefs, data) {
+ return(apply(attr(eval(foo,env=c(as.list(coefs), as.list(data))),
+ "gradient"),2,sum))
+ }
>
> # raincheck : unbounded optimization, but using a form palatable to
> # bounded optimization
>
> system.time(D1.unbound<...