[R] Help in optimization
Alberto Monteiro
albmont at centroin.com.br
Wed Oct 11 20:19:17 CEST 2006
Ricardo Bessa wrote:
>
> I have had a problem in finding the minimum of a function, the
> function in cause is:
>
The first, obvious, optimization step is that you
are reading the whole table every time you call the function.
You should read the table just once. Instead of:
> curv <- function(a,b){
> date <- read.table("bessa.csv",header=T,sep=";",dec=",")
> calP <- (22000)/(1+exp(-(a*date$v+b)))
> err <- (calP-date$P)^2
> return(sum(err))
> }
Try:
date <- read.table("bessa.csv",header=T,sep=";",dec=",")
curv <- function(a,b){
calP <- (22000)/(1+exp(-(a*date$v+b)))
err <- (calP-date$P)^2
return(sum(err))
}
Alberto Monteiro
More information about the R-help
mailing list