Skip to content

setting up a genoud run

2 messages · Dimitri Liakhovitski

#
Hello - and sorry for a possibly stupid question, I'm just starting to
learn rgenoud.

I am defining a function with 5 parameters (p1, p2, p3, p4a, and p4b)
and then want to optimize it using genoud. But I am doing something
wrong.
Before genoud is even able to run it says: "Error in p2 + 1.2 : 'p2'
is missing".
I assume I did not specify it right. My code is below.
The task is: I want to find those values of p1, p2, p3, p4a and p4b at
which the function f1 is at its maximum. At the same time, I want the
value of each of those 5 parameters to be between 0 and 1000.
Thanks a lot for your advice!

library(rgenoud)
f1 = function(p1,p2,p3,p4b,p4a) {
	y = 2 + 1.5*p1 + 0.3*(p2+1.2+0.6*p4a)-1.2*p3 + 0.9*p4b
	return(y)
}

f1(p1=1,p2=2,p3=4,p4b=4,p4a=6)  # seems to be working


npredictors=5
genoud(f1,nvars=npredictors,max=TRUE,pop.size=1000,max.generations=100,wait.generations=10,
hard.generation.limit=TRUE,starting.values=rep(500,npredictors),
Domains=matrix(rep(c(0,1000),npredictors),ncol=2,byrow=T),boundary.enforcement=2)
#
As a follow up to my original question, I got it to run by
re-specifying my function a bit like this - I made the vector of 5
predictors the argument of my function:

f1 = function(predictors) {  # predictors: p1,p2,p3,p4b,p4a
	y = 2 + 1.5*predictors[1] +
0.3*(predictors[2]+1.2+0.6*predictors[5])-1.2*predictors[3] +
0.9*predictors[4]
	return(y)
}
f1(c(1,2,4,5,6)) # checking it works

npredictors=5
genoud(f1,nvars=npredictors,max=TRUE,pop.size=1000,max.generations=100,wait.generations=10,
hard.generation.limit=TRUE,starting.values=rep(0,npredictors),
Domains=matrix(rep(c(0,1000),npredictors),ncol=2,byrow=T),boundary.enforcement=2)

It has run, but starting in Generation 13, it said:  "at least one
gradient is too large." G[3]: -inf
Also, it gives me the following parameters as the answer:  1000 1000
 0 1000 1000 (which makes sense).

I am wondering what does it mean that "one gradient is too large"?
Thanks a lot for explaining!

Dimitri



On Thu, Jan 13, 2011 at 11:10 AM, Dimitri Liakhovitski
<dimitri.liakhovitski at gmail.com> wrote: