Computational Modeling Fall 2005 For today: HomeworkTwenty and HomeworkTwentyOne Today: 1) discussion of reductionism 2) CircleWorld 3) classical models of systems with emergent properties For next time: HomeworkTwentyTwo, implement emergence Reductionism ------------ The questions from HomeworkTwentyOne are: 1. What is a reductionist explanatory model? 2. What other kinds of explanatory models are there? 3. Is a reductionist model a satisfactory answer to a "why question"? 4. If so, is it the only satisfactory kind of explanatory model? 5. What are the candidates for an alternative (holism is one)? 6. What are the criteria we might want to use to evaluate an explanatory model? Where I would like to get to in our discussion is an understanding of 1) what "reductionism" means in various contexts 2) why it has become a term of deprecation 3) what the alternatives are CircleWorld ----------- Download: wget http://wb/cm/code/Gui.py wget http://wb/cm/code/World.py wget http://wb/cm/code/Circle.py As a trivial example of an "emergent" property, consider the following distributed algorithm for drawing a circle: 0) create lots of independent agents and put them where you want the center to be 1) each agent then: a) rotates to a random orientation b) moves forward one radius (pen up) c) turns left d) moves forward a small distance (pen down) e) dies Voila! Un circle! Here's the code: world = TurtleWorld() ts = [Turtle(world, delay=0.01) for i in range(100)] for t in ts: angle = random.uniform(0, 360) t.rt(angle) t.pu() t.fd(100) t.lt() t.pd() t.fd(10) t.die() world.mainloop() This example is atypical of distributed algorithms: 1) we assume that a central "creator" puts the turtles at the center 2) the turtles don't coordinate with each other. Can we clean this up so that it makes a circle, starting from an initial condition where turtles are scattered at random positions and orientations? Stepping and generators ----------------------- TurtleWorld provides a step method that looks like this: def step(self): for animal in self.animals: animal.step() So one way to write Turtle control code is to write a step method that executes one instructions each time it is executed. If Turtles do the same thing over and over, that's easy. If not, then we can use generators. wget http://wb/cm/code/CircleWorld.py First, make an animal whose step method is a generator functions: class CircleTurtle(Turtle): def step(self): angle = random.uniform(0, 360) self.rt(angle) self.pu() yield None self.fd(100) self.lt() yield None self.pd() self.fd(10) yield None self.die() Then make a World that knows how to invoke generator functions: class CircleWorld(TurtleWorld): def step(self): if not hasattr(self, 'iters'): self.iters = [animal.step() for animal in self.animals] for iter in self.iters: try: iter.next() except StopIteration: pass I think this provides a good framework for writing Turtle control code that can be stepped through in parallel.