15.08.2015 Views

Introduction to the Modeling and Analysis of Complex Systems

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

introduction-to-the-modeling-and-analysis-of-complex-systems-sayama-pdf

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

10.4. SIMULATION WITHOUT PYCX 181Code 10.10: r<strong>and</strong>om-walk-2D-pSetter.pydef num_particles (val = n):’’’Number <strong>of</strong> particles.Make sure you change this parameter while <strong>the</strong> simulation is not running,<strong>and</strong> reset <strong>the</strong> simulation before running it. O<strong>the</strong>rwise it causes an error!’’’global nn = int(val)return valimport pycxsimula<strong>to</strong>rpycxsimula<strong>to</strong>r.GUI(parameterSetters = [num_particles]).start(func=[initialize, observe, update])Once you apply this modification <strong>to</strong> Code 10.6 <strong>and</strong> run it, <strong>the</strong> new parameter setter appearsunder <strong>the</strong> “Parameters” tab <strong>of</strong> <strong>the</strong> control window (Fig. 10.3). You can enter a newvalue in<strong>to</strong> <strong>the</strong> input box, <strong>and</strong> <strong>the</strong>n click ei<strong>the</strong>r “Save parameters <strong>to</strong> <strong>the</strong> running model”or “Save parameters <strong>to</strong> <strong>the</strong> model <strong>and</strong> reset <strong>the</strong> model,” <strong>and</strong> <strong>the</strong> new parameter value isreflected in <strong>the</strong> model immediately.Exercise 10.2 To <strong>the</strong> code developed above, add one more parameter setter forsd (st<strong>and</strong>ard deviation <strong>of</strong> Gaussian noise for r<strong>and</strong>om motion <strong>of</strong> particles).10.4 Simulation without PyCXFinally, I would like <strong>to</strong> emphasize an important fact: The PyCX simula<strong>to</strong>r file used in thischapter was used only for creating a GUI, while <strong>the</strong> core simulation model was still fullyimplemented in your own code. This means that your simulation model is completelyindependent <strong>of</strong> PyCX, <strong>and</strong> once <strong>the</strong> interactive exploration <strong>and</strong> model verification is over,your simula<strong>to</strong>r can “graduate” from PyCX <strong>and</strong> run on its own.For example, here is a revised version <strong>of</strong> Code 10.6, which au<strong>to</strong>matically generatesa series <strong>of</strong> image files without using PyCX at all. You can generate an animated moviefrom <strong>the</strong> saved image files using, e.g., Windows Movie Maker. This is a nice examplethat illustrates <strong>the</strong> main purpose <strong>of</strong> PyCX—<strong>to</strong> serve as a stepping s<strong>to</strong>ne for students <strong>and</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!