search for: fnscale

Displaying 20 results from an estimated 85 matches for "fnscale".

2008 May 16
0
How to determine sensible values for 'fnscale' and 'parscale' in optim
Dear R-help, I'm using the 'optim' functions to minimise functions, and have read the documentation, but I'm still not sure how to determine sensible values to use for the 'fnscale' and 'parscale' options. If I have understood everything correctly, 'fnscale' should be used to scale the objective function, so that for example if the default is 'sensible' (or even 'optimal') for minimising 'f', one should use 'fnscale=1e-6' f...
2008 Mar 23
2
scaling problems in "optim"
Dear R users, I am trying to figure out the control parameter in "optim," especially, "fnscale" and "parscale." In the R docu., ------------------------------------------------------ fnscale An overall scaling to be applied to the value of fn and gr during optimization. If negative, turns the problem into a maximization problem. Optimization is performed on fn(par)/fnsc...
2001 Nov 08
3
Problem with optim (method L-BFGS-B)
...x[3]-400)/100)* ((x[4]-250)/50) + 0.62105*((x[3]-400)/100)* ((x[5]-550)/150) - 0.22426*((x[4]-250)/50)*((x[5]-550)/150))/219741978624 )} Then I run the following command, and I get a pretty good result (I know approximatively the theoritical maximum) optim(c(200,60,500,300,700),test,control=list(fnscale=-1))$par [1] 398.17520 31.34863 372.17182 217.30874 533.49458 Fortunately, all the optimal values fall in their range of possible value. But to be rigourous, I should perform a box-constrained optimization. Then, I do so with the following command (in fixing the lower and upper args and not):...
2010 Oct 01
3
maximum likelihood problem
...vectors of data. I want to R to change the value of k to maximize the value of equation. My attempts at optim and optimize have been unsuccessful. Are these the recommended functions that I should use to maximize my equation? With optim I wanted the function to be maximized so I had to make the fnscale negative. Here is what I put: L<-optim(k,equation,control=(fnscale=-1)) My result: Error: could not find function "fn" Here is what I put for optimize: L<-optimise(equation,k,maximum=TRUE) My result: Error: 'xmin' not less than 'xmax' Any advise would be...
2012 Apr 05
4
Appropriate method for sharing data across functions
...sable from source() i.e., cannot be interpreted but must be built first. JN Example using <<- rm(list=ls()) optstart<-function(npar){ # create structure for optimization computations # npar is number of parameters ?? test?? OPCON<<-list(MAXIMIZE=TRUE, PARSCALE=rep(1,npar), FNSCALE=1, KFN=0, KGR=0, KHESS=0) # may be other stuff ls(OPCON) } add1<-function(){ OPCON$KFN<<-1+OPCON$KFN test<-OPCON$KFN } OPCON<<-list(MAXIMIZE=TRUE, PARSCALE=rep(1,4), FNSCALE=1, KFN=0, KGR=0, KHESS=0) ls(OPCON) print(add1()) print(add1()) print(ls....
2009 Nov 02
2
a prolem with constrOptim
...rep(0,nrow(RR)) theta.0 = numeric(3*K) for(i in 1:K) {theta.0[(1+3*(i-1)):(3*i)] = rep(1/10,3)+i/100} # data1 gives an error but data2 does not! constrOptim(theta=theta.0, f=likelihood, grad=score, ui=RR,ci=zeros, data = data1, method="BFGS", control=list(fnscale=-1,abstol=1e-16,reltol=1e-16))$par constrOptim(theta=theta.0, f=likelihood, grad=score, ui=RR,ci=zeros, data = data2, method="BFGS", control=list(fnscale=-1,abstol=1e-16,reltol=1e-16))$par # If you want to further check run the simulation below. K = 3 N...
2005 Apr 26
2
"wild" function example in optim
Dear all, Firstly, I do apologize if my question is simple and posted in the wrong place but I had no reply from the R-help mailing list (maybe it is too simple!). I was wondering why parscale is set to 20 in the "wild" function example used in ?optim. This function has only one parameter and if we set parscale equal to 1 then the solution near the global minimum is not found. I
2011 Sep 27
2
Error in optim function.
...optim(0.01, ## starting value binomial.ll, ## log likelihood method="BFGS", ## optimization method hessian=TRUE, ## numerial Hessian control=list(fnscale=-1), ## max, not min y=y, n=n) binomial.mle.par <- c(binomial.mle$par, -1/binomial.mle$hessian[1,1]) binomial.mle.par <- as.matrix(binomial.mle.par) rownames(binomial.mle.par) <- c("lambda", "s.e.") colnames(binomial.mle.par) <- c("MLE&quot...
2010 Sep 02
1
Help on glm and optim
...]*E^2 loglik <- sum(dgamma(data$lot1,shape=1/theta[3],rate=1/(E*theta[3]),log=T)) return(loglik) } # use the glm result as initial values theta <- c(as.vector(coef(fit1)),0.002446059) fit2 <- optim(theta, loglik, clotting, gr = NULL, hessian = TRUE, control = list(fnscale = -1)) # Then I got the following error message: Error in optim(theta, loglik, clotting, gr = NULL, hessian = TRUE, control = list(fnscale = -1)) : non-finite finite-difference value [3] Wayne (Yanwei) Zhang Statistical Research CNA Phone: 312-822-6296 Email: Yanwei.Zhang@cna.com<mailto:Yan...
2011 Jun 14
1
Using MLE Method to Estimate Regression Coefficients
...Y <- as.vector(y) xbeta <- X%*%par[1:K] Sig <- par[K1:K1] sum(-(1/2)*log(2*pi)-(1/2)*log(Sig^2)-(1/(2*Sig^2))*(Y-xbeta)^2) } llik.regress # Now let's use the above function to estimate the model. model <- optim(c(1,1,1,1), llik.regress, method="BFGS", control=list(fnscale=-1), hessian=TRUE) Error in optim(c(1, 1, 1, 1), llik.regress, method = "BFGS", control = list(fnscale = -1), : initial value in 'vmmin' is not finite -------------- next part -------------- # upload printing press data # 27 design points with 3 obs each for 81 tota...
2008 Feb 08
0
scaling and optim
?optim says, in describing the control parameter, 'fnscale' An overall scaling to be applied to the value of 'fn' and 'gr' during optimization. If negative, turns the problem into a maximization problem. Optimization is performed on 'fn(par)/fnscale'. 'parscale' A vector of scaling val...
2010 Oct 02
1
[Fwd: RE: maximum likelihood problem]
...vectors of data. I want to R to change the value of k to maximize the value of equation. My attempts at optim and optimize have been unsuccessful. Are these the recommended functions that I should use to maximize my equation? With optim I wanted the function to be maximized so I had to make the fnscale negative. Here is what I put: L<-optim(k,equation,control=(fnscale=-1)) My result: Error: could not find function "fn" Here is what I put for optimize: L<-optimise(equation,k,maximum=TRUE) My result: Error: 'xmin' not less than 'xmax' Any advise would be...
2017 Aug 24
1
Problem in optimization of Gaussian Mixture model
...optima and optimx to find the maxima, but it gives me value near by the highest mean as an output, for example 830 in the above parameters. The code for my optim function is val1=*optim*(par=c(X=1000, *seg=1*),fn=xnorm, opt=c(NA,seg=1), method="BFGS",lower=-Inf,upper=+Inf, control=list(fnscale=-1)) *I am running the optim function in a loop and for different initial value and taking the val1$par[1] as the best value.* *I am taking this parameter since I want to run it on n number of segments latter* and xnorm is simply calculating the dnorm *xnorm*=function(param, opt = rep(NA, 2)){...
2008 Mar 31
2
L-BFGS-B needs finite values of 'fn'
...^(0:(n-1)))*log(x)) - 2000000*(sum(x)-k)^2 return(r) } gr <- function(x) { n <- length(x) r <- (b^(0:(n-1)))*(1/x) - 4000000*(sum(x)-k) return(r) } nvar <- 10 (sols <- optim(rep(20,nvar),f,gr,method="L-BFGS-B",lower=rep(0,nvar),upper=rep(k,nvar),control=list(fnscale=-1,parscale=rep(2000,nvar),factr=1e-300,pgtol=1e-300)))
2007 May 07
3
Bad optimization solution
...wrong? I am using R 2.5.0 on Fedora Core 6 (Linux). Thanks in advance, Paul ------------------------------------------------------ myfunc <- function(x) { x1 <- x[1] x2 <- x[2] abs(x1-x2) } optim(c(0.5,0.5),myfunc,lower=c(0,0),upper=c(1,1),method="L-BFGS-B",control=list(fnscale=-1))
2001 Nov 22
2
optim ???
...t <- (-1)*n*log(det(sigma)) logdet-sum(diag(A)) } optim(par=c(mu=mean(santes),delta=mean(sdespues-santes),s2ksi=422,s2eps=1,s2eta=75), fn=function(mu,delta,s2ksi,s2eps,s2eta) logvero(mu,delta,s2ksi,s2eps,0,s2eta,santes,sdespues-santes), control=list(trace=1, fnscale=-1), method="BFGS") gives the result: Error in as.vector(data) : Argument "s2ksi" is missing, with no default What is happening? Kjetil Halvorsen -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://...
2009 Feb 24
2
Tracing gradient during optimization
...ctor during each iteration. The documentation of optim() describes that the trace parameter should allow one to trace the progress of the optimization. I use the following command: optim(par = vPar, fn = calcLogLik, method = "BFGS", control = list(trace = TRUE, fnscale = -1, maxit = 2000)); which gives very little information: initial value 3.056998 final value 2.978351 converged Specifying trace >1, for instance trace = 20, does not result in more information. Is there a way to view more details of the progress perhaps by using another optimizer? Thanks...
2007 May 19
2
What's wrong with my code ?
...:q)] gr <- 2*Psi*((L^2)%*%e) gr } p <- ncol(cmat) if(is.null(start)) start <- (1 - 0.5*factors/p)/diag(solve(cmat)) res <- optim(start, FAfn, FAgr, method="L-BFGS-B", lower = lower, upper = 1, control = c(list(fnscale=1, parscale = rep(0.01, length(start))), control), q = factors, S = cmat) res } covmat <- structure(c(1, 0.0920030858518061, 0.053952442382614, -0.0380048634941013, 0.237986469993129, 0.243144461077282, 0.0920030858518061, 1, 0.328163804480881, 0.142002180914605, -0.13936961...
2003 Dec 18
1
NUMERIC DERIVATE
UseRs, I used the optim function valor.optim <- optim(c(1,1,1),logexp1,method ="BFGS",control=list(fnscale=-1),hessian=T); and I want to calculate the derivates, psi1<-valor.optim$par[1] psi2<-valor.optim$par[2] psi3<-valor.optim$par[3] a0=exp(psi1); a1=exp(psi2)/(20+exp(psi2)+exp(psi3)); a2=exp(psi3)/(20+exp(psi2)+exp(psi3)) deriv.psi1<-numericDeri...
2004 Oct 02
1
constraints in optim?
> optim(c(1,1),LL,method="SANN",control=list(fnscale=-1),trans=trans,times=times) $par [1] 17.422635 -1.606859 How could i constraint that the parameters should be both positive in my maximizing problem? I check constrOptim but here i could only constraint the variables trans and times and not my parameters? many thanks, regards Christian