Jon’s PhD Journal

April 12, 2007

Thursday: more SAS action, calculating distances between flock members…

Filed under: Notes — JDE @ 5:54 pm

After yesterday’s introduction to SAS,today has been spent trying to work out how to calculate the distances between flock members.  Fundamentally flocks are supposed to, well, flock together.  As such, those flocks which have a small distance between their members should indicate that the flock is actually quite cohesive and is well joined from one another.

So far today I’ve worked out how to calculate the distance between a flock member and each other flock member, per timestep.  The following code below is the SAS syntax required to produce the correct output:

proc sql;
    /*input BOID RADIUS TIMESTEP X_POS Y_POS Z_POS VEL_X VEL_Y VEL_Z;*/
    create table Result as
    select     a.BOID         as FirstAgent,
            b.BOID        as SecondAgent,
            a.TIMESTEP    as FirstTimeStep,
            b.TIMESTEP    as SecondTimeStep,
            a.X_POS – b.X_POS    as X_Diff,
            a.Y_POS – b.Y_POS    as Y_Diff,
            a.Z_POS – b.Z_POS    as Z_Diff
    from     boids a, boids b
    /*where    a.BOID lt b.BOID and a.TIMESTEP lt b.TIMESTEP*/
    where    a.BOID lt b.BOID
    and     b.TIMESTEP = a.TIMESTEP + 1
    /*order by a.BOID, b.BOID, a.TIMESTEP, b.TIMESTEP*/
    /*order by a.BOID, a.TIMESTEP*/
    order by a.BOID, a.TIMESTEP
    ;
    quit;

proc print data=Result;
run;

To calculate the hypotenuse between each of the agents, now to be fairly basic to complete, working on the progress made yesterday. From looking at the results I generated on Tuesday from the simulation, I’ve got the following initial results:

Boid Radius Setting               Mean Distance btw Boids
          5.0                                       0.42
          1.0                                       0.44
          0.1                                       0.48

So this does match the hypothesis: as the boid radius parameter, which effectively dictates how far a bird can see,is increased, this means that particular birds can see farther, and hence join up with more distant flocks, the mean distance between flock members reduces.

This seems to be a way to work out the cohesiveness of the flock: I’m aiming to do a report on particle swarm optimisation starting next week, so I’ll look to see if there is anything in the literature on the measurement of cohesiveness in groups.  The next problem I need to solve, is how to measurethe degree of polarisation within the flock.  From the simulation I’m running, I have managed to extract velocity data — I now just need to turn this into useful information, in a bid to trying to do something about the state of the flock.

Blog at WordPress.com.