Question

I'm trying to convert the math presented on this paper:

http://www.bouncingchairs.net/pskalman-lategecco.pdf

Around page 3 forward into working code. The algorithm itself is given around page 6, but I don't speak greek or math; so for the time being I'm stuck.

If I understand the code, it should run down like this:

    vt = particle velocity, 1d array
    vbest = best particle velocity 1d array
    v_prime = 1d storage array
    v_hat = 1d storage array

    alpha = 0.45
    sigma = 0.60

    denom = float
    denom_best = float

Prep:

for(int i = 0; i < vt.length; i++)
{
     denom += vt[i] ^ 2
     denom_best += vbest[i] ^ 2
}
denom = denom ^ (1/2)
denom_best = denom_best ^ (1/2)

Equation 7:

for(int i = 0; i < vt.length; i++)
{
v_prime[i] = alpha * (vt[i]/denom) + (1 - alpha) * (vbest[i]/denom_best)
}

Equation 8:

for(int i = 0; i < vt.length; i++)
{ 
 v_hat[i] = Rand_Gauss(v_prime[i], sigma) //gaussian random number with 
                                          //v_prime[i] average, and sigma StDev
}

Equation 9:

for(int i = 0; i < vt.length; i++)
{
vt[i] = (alpha * denom + (1 - alpha) * denom_best) * v_hat[i]
}

Is this even close to what the math is saying?

Thanks in advance, -JW

Was it helpful?

Solution

I think you might be missing the calls to "norm(...)". Normalizing a vector is just dividing each component of the vector by the length. In Equation 9, they calculate the weighted sum of the lengths of vt and vbest and multiply that average length by norm(vbar). You're just multiplying it by vbar directly.

The intent behind that equation seems to be to create a new vector v_{t+1} whose length is the average length of vt and vbest. However, vhat could be any length at all, so the multiplication in Equation 9 most of the time won't give you the correct answer unless you force the length of the vhat vector to be exactly one. That's what the vector norm does.

The norm is just the components of the vector divided by the length. So replace your code for equation 9 with something like this:

vtlen=0
for(int i=0; i<vt.length; i++)
{
    vtlen+=vt[i]*vt[i];
}
vtlen=sqrt(vtlen);
for(int i=0; i<vt.length; i++)
{
    vt[i] = (alpha * denom + (1 - alpha) * denom_best) * (v_hat[i] / vtlen);
}

You've also ignored the norm operation in Equation 7. I haven't read the paper, but it may not be strictly necessary here as the weights sum to one and the vectors are already normalized. I'd have to spend a bit more time to convince myself one way or the other, but it certainly wouldn't hurt to go ahead and normalize that calculated v' vector too.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top