-Created by dan mackinlay on 2010-10-18.
-Copyright (c) 2010 __MyCompanyName__. All rights reserved.
+Created by dan mackinlay on 2012-09-12.
->>> simstate = do_flocking_sim(basic_flock_factory(DEFAULT_PARAMS))
+consider calculating MI between relative axial positions of pairs of particles, which also might work.
+(As we have no reason to suppose that MI is "concentrated" in one part of the state vector,
+and avial positions are quicker to calculate, AND don't have as much additional noise)
from __future__ import division
- "A holder for some simulation state."
+ """A holder for some simulation state.
+ TODO: ensure that params is always copied by value."""
+ statevars = ['vels', 'locs']
def __init__(self, params):
- self.params = params.copy()
+ self.params = params.copy()
+ """make a new copy of me with arrays pointing to the same memory locations
+ but with params dict cloned."""
+ clone = self.__class__(self.params.copy())
+ for name in self.statevars:
+ setattr(clone, name, getattr(self, name))
+ """Initialise a sim with basic random state."""
sim = SimState(params=params)
sim.locs = np.random.uniform(size=(params['num_agents'], 2))
sim.vels = random_unit_vectors(params)
-def do_flocking_sim(simstate, steps=100, seed=None):
- simstate = copy(simstate)
+def do_flocking_sim(simstate, steps=100, seed=1):
+ Starting from the state in *simstate*, iterate the simulation *steps* times.
+ simstate = simstate.clone()
+ #update seed to reflect the most recent seed used. I suppose that's kind of variable overloading.
for step in xrange(steps):
+def branched_flocking_experiment(params=DEFAULT_PARAMS, seed=1):
+ Run a sim, stop it after a number of iterations.
+ Then run alternate versions with a given seed, keeping the results.
+ base_simstate = do_flocking_sim(basic_flock_factory(params), steps=params['discard_steps'], seed=seed)
+ base_simstate.params['base_seed'] = seed
+ do_flocking_sim(base_simstate, steps=params['branch_steps'], seed=seed+i)
+ for i in xrange(params['num_branches'])
"""normalise the lengths of some stacked row vectors.