Hi
r-help-boun...@r-project.org napsal dne 19.01.2010 02:32:45:
>
> Hello Petr.
>
> For the random values, I wanted to generate a different random number
for
> each element of my velocity matrix.
>
> So will this do it?
>
> rmat <- matrix(runif(1000), 500,2)
> rmat2 <- matrix(runif(1000), 50
Hello Petr.
For the random values, I wanted to generate a different random number for
each element of my velocity matrix.
So will this do it?
rmat <- matrix(runif(1000), 500,2)
rmat2 <- matrix(runif(1000), 500,2)
rindex <- sample(1:500, replace=TRUE) #with repetition
velocity<-0.4 * velocity +
Hi
slightly better. However it would be nice if you provided some code which
works but not the way you want. Loops are not as problematic but often you
achieve far better results by avoiding them and using vectorised code.
Still there are some oddities.
random values in formula below shall be
Hello
Sorry for the confusion
Here are additional details.
velocity, popVar, archiveVar,pbestsVar are matrices with dimension of 500
row, 2 col matrix.
I want to assign new values for each velocity[i,j] using the formula below:
*0.4 * velocity[i,j] + 1 * randomvalue * (pbestsVar[i,j] - popVar[
Hi
Definitely not
from first I get
> gBest<-floor(runif(popsize,min=1,max=top))
Error in runif(popsize, min = 1, max = top) : object 'popsize' not found
>
and from second
> for (i in 1:popsize) {
+ for (j in 1:maxvar) {
+gBest<-sample(top,size=1)
+velocity[i,j]<<-.4* velocity[i,j]
5 matches
Mail list logo