Jon’s PhD Journal

January 29, 2009

Thursday: Smiley, Smiley module action …

Filed under: Notes — JDE @ 7:54 pm

from

path.append(

import

Melper

 x = Melper.returnFilenameTimestamp()

 

print x

Oh yes … !

Meetings for Feb-2009

  • 5-Feb: TC @ 4.30pm
  • 12-Feb: TC @ 4.30pm
  • 20-Feb: F2F @ 2pm

Progress

 Today got the Analysis/Mung code to work, when controlled by the Controller. Woot.

January 28, 2009

Wednesday: joy of Global variables …

Filed under: Notes — JDE @ 7:54 pm

Worked out why my loop was failing — a pretty important array was not being cleared out during each loop. Problem resolved now though.

Ran out of time on the case of importing modules from other directories … but the answer can be found here!: http://stackoverflow.com/questions/456481/cant-get-python-to-import-from-a-different-folder

January 27, 2009

Tuesday: looping madness

Filed under: Notes — JDE @ 7:51 pm

Changing the code to remove toroidality was remarkably straight forwards — just delete the offending section of code!! Boids now start within same starting area, but can move off to wherever they fancy … need to visualise this soon to actually see what they are doing.

Then moved onto the controller code, to start looping through the simulation to generate lots of data. However, for some reason code runs more times than anticipated .. for further investigation tomorrow methinks.

January 26, 2009

Monday: back from holiday and struggling …

Filed under: Notes — JDE @ 7:56 pm

Back from hols today and trying to remember where everything got left, prior to a rather trying week at work …

The toriodality issue and mapping to a new plane is a non starter, as it will screw up the dynamics of a flock. Leaning to a huge world for the babies to play in, but starting them off in a smaller playpen, that does not have outlimits — only looking at the numbers, baby, not the true world.

January 11, 2009

Sunday: New toroidal world …

Filed under: Notes — JDE @ 7:13 pm

How to get over the convex hull / toroidal issue:

  • # current stage, no new velocities have been applied
  • # next stage, new velocities wrap flock around boundary
  • # take current coordinates; map to new world, around point of 0,0
  • # apply velocities
  • # calculate area
  • # delete new world
  • # in original world, apply velocities again, by adding velocities to original coordinates

Annoyingly this will have to be done in Model code, and not in Analysis code, unless a great thought strikes me from above.

To consider: Regarding toroidality of flocks: need to surely include a scale of the difference when moving boids over the boundary, not just a flat reset to w.g. widh parameter?

January 8, 2009

Thursday: limited R action and thoughts on toroidal convex hulls …

Filed under: Notes — JDE @ 7:41 pm

R

Nice quote on mathematical models btw from http://stats.lse.ac.uk/penzer/ST419materials/CSchpt3.pdf:

Mathematical models fall into two categories, deterministic and stochastic. For a deterministic
model, if we know the input, we can determine exactly what the output will be. This is not true
for a stochastic model; the output of a stochastic model is a random variable.

See above link and http://cran.r-project.org/doc/contrib/Lemon-kickstart/kr_rfunc.html for details on writing your own R functions.

Convex hulls and toroidal behaviour

Don’t you just hate it when your flock breaks through the toroid-ality of your environment, screwing up your convex hull calculation? If so, why not take your flock to the next dimension, chull their coords around a common reference point, and then return them to the dimension they came from … ?

January 7, 2009

Tuesday: more R …

Filed under: Notes — JDE @ 7:57 pm

NB Beginners Guide To R: http://cran.r-project.org/doc/contrib/Paradis-rdebuts_en.pdf

  • a <- list() # make a list called a
  • for (i in 1:length(x)) {a[[i]] <- as.vector(unlist(x[i,]))} # add each row of x to a as a list item
  • sapply(a, sd) # for each entry in a, calculate the stdev

Stop the press!: R has a convex hull function in it, called chull() — could be useful. Will need to use matrix()

# read in area information and plot to screen
coords <- read.table(“c:/temp/file_coords.txt”, sep=”,”, fill=TRUE, row.names = 1)
coords = coords[,1]
time = 1:length(coords)
plot(coords ~ time)

# read in velocity information and plot to scren
vels <- read.table(“c:/temp/file_vels.txt”, sep=”,”, row.names = 1)
vels <- vels[,-length(vels)]
a <- list()
for (i in 1:length(x)) {a[[i]] <- as.vector(unlist(x[i,]))}
std_devs = sapply(a, sd)
time = (1:length(s))
plot (time ~ std_devs)

And saveplot() apparently saves your plot (maybe see http://www.nabble.com/Very-new—beginners-questions-to12125162.html#a12126867) — go figure …

January 6, 2009

Tuesday: this took 90min to unearth in R …

Filed under: Notes — JDE @ 7:38 pm
  • x <- read.table(“c:/temp/file_vels.txt”, sep=”,”, row.names = 1) # read in an external file, with the name of the rows in column 1
  • x <- x[,-12] # remove column 12
  • r <- x[1,] # save the first row
  • t(x) # tranpose data
  • class(x) # find out type of x
  • length(x) # returns length of x
  • x[1,] # row 1 of x
  • x[,1] # column 1 of x
  • r1 <- as.vector(unlist(x[1,])) # return row 1 of data frame x as a vector
  • sd(r1) # the standard deviation of r1
  • to knock out “NA” values, see this post (http://www.nabble.com/removing-NA-from-a-data-frame-td3463459.html#a3463459)
    • could be  x[!sapply(x, function(z)any(is.na(z)))]
  • apply(x,1,sd) # calculate the stdev of each row in x

January 5, 2009

Monday: pain with R

Filed under: Notes — JDE @ 7:48 pm

New year, new problems … !

Playing around with R today, to try some initial analysis. Things learnt so far:

  • any line starting with a ‘#’ is treated as a comment, and blanked out — be useful to start each code line with ‘#’ going forwards
  • R looks at data vertically, whereas data produced so far is horizontal — i.e. in rows. Surely there must be a way to go from cols –> rows ? and don’t call me Shirley, etc.

Blog at WordPress.com.