hzambran / hydroPSO

Model-Independent Particle Swarm Optimisation for Environmental Models
https://cran.r-project.org/package=hydroPSO
GNU General Public License v2.0
36 stars 18 forks source link

Suggesting particle positions #15

Closed MatthiasPucher closed 4 years ago

MatthiasPucher commented 5 years ago

So far, I have not found a way to suggest the positions of particles. Would this make sense anyway? I intended to start particles at points, where I assume a good fit close by and by that shorten the calculation time. Would it then be possible, to suggest some positions and generate others similar to a default run?

hzambran commented 4 years ago

I apologise for the huge delay, but I had to temporally be offline for some time, but now I'm back.

The answer to your question is to use the par argument. From '?hydroPSO`:

"If the user provides ‘m’ parameter sets for ‘par’, they are used to overwrite the first ‘m’ parameter sets randomly defined according to the value of ‘Xini.type’"

D <- 5
lower <- rep(-5.12, D)
upper <- rep(5.12, D)

# initial parameter values:
x0 <- rep(0, D)
hydroPSO(fn=rastrigin, par=x0, lower=lower, upper=upper, control=list(write2disk=FALSE) )

You are not restricted to provide a single initial parameter set, but you might provide as many as the number of particles, where each row in par represents a different parameter set and each column in par represent a different parameter, in the same order you enter them in lower and upper

MatthiasPucher commented 4 years ago

Thanks, its highly appreciated. I will try this!