Home

Progress in the predator prey simulation

  • Jul. 3rd, 2009 at 11:08 PM
Taken in Portugal
Since yesterday a lot things improved.

In this example I killed all but one rabbit after 1200 rounds and all but one wolve after 7700 (of 10000) rounds:

Free Image Hosting at www.ImageShack.us

QuickPost Quickpost this image to Myspace, Digg, Facebook, and others!

Tags:

Taken in Portugal
As you may know I am a biology teacher. Next term I will teach Ecology. One part of that is the relationship between predators and prey (wolves and rabbits, for example). There are quite some mathematical model for these relationships, in school we mostly teach a simplified version of the Lotka-Volterra system.

This kind of stuff really needs a simple application to test the influence of certain factors. For example,


  • what happens if after two years we kill all but 5 predators?

  • what happens if after two years we kill all but 5 prey?

  • what happens if after 1 year, for whatever reasons, the rabbits become more fertile?



There are tools schools can buy, but a) they suck and b) they are very expensive.

Introducing: "Predator and Prey" by Carsten Niehaus (tm)

Free Image Hosting at www.ImageShack.us

QuickPost

As you can see the basic stuff all works. When happens when I start with just on predator but 20 prey but let the predators be more efficient hunters? Look here:

Free Image Hosting at www.ImageShack.us

QuickPost


The application is written in PyQt4 using matplotlib. I would really like to express one thing: Python + Qt4 rocks. Seriously, the whole application has only 306 lines including comments!

Are you interested in the code or even in helping me writing a cool PP-Simulation? Do you think this should go into KDE EDU? I am hosting everything in GitHub: PP in GitHub.
Taken in Portugal
Just like earlier I needed an application. This time I needed something that simulates the relations between predator and prey (see here). My students will use a simple simulation with dices so see those relations. The problem is that it takes ages to roll 400 times (that is what you need to get good statistics). So they only roll the dices for about 50-70 times, discuss the trends they see.

The next step will be my simulation based on the same rules. 77 python lines later that app is done :-) "All" I need is a nice PyQt4 interface for it, right now it is a pure shell application. But it already exports to CSV (just three lines :). In OOCalc this loooks like this:

Free Image Hosting at www.ImageShack.us

QuickPost

Quite nice and the code is really simple. Python rocks.

PS: No clue where to host this, I don't want such a tiny tool on sourceforge.net. Perhaps I should bundle all my biology simulation tools in one application (KSmallBiologyTools like (and no, I will not use that name)) and host _that_ application somewhere.

Tags:

PyQt4: 500 lines of code later

  • May. 1st, 2008 at 7:15 PM
Taken in Portugal
Yesterday I blogged that I decided to use PyQt4 in my class. A few hundred lines of code later I start to like Python. It is quite a nice language so far. The indendation thing still drives me mad from time to time (there seems to be no sane editor for python that autoindents my code... Usually I am using VIM, but it is not correctly indenting my files for some reasons. Need to google a bit more for Python-specific vim scripts/settings, I guess.

But I have one issue I cannot resolve (in a nice way). I am loading data from a CSV file. One data set is just True/False, in the file represented by "1" and "0". The only way to make this work is this code:

liquid = bool(int(row[6]))


Without the casting from string to int the casting to bool is not working. In other words, I cannot directly cast from string to bool. I guess there is a more pythonic way, if you know it please tell me :-)

Tags:

PyQt4 success, a coding class in my school

  • Apr. 29th, 2008 at 6:54 PM
Taken in Portugal
In the next term I will (for the first time) be teaching a coding class at my school. I had a few must-have criteria for the language and toolkit of choice:

Language



  1. Has to be a scripted language as then no compiler is needed. Is easier to understand and less error-prone

  2. Has to be free as in beer and freedom

  3. Has to run on Windows 2000, XP, Vista and Linux

  4. Has to have a german reference (for my students)

  5. Has to have a good textbook (for me), if possible written in german

  6. Has to have a good Editor



  1. Perl, Python, Ruby are left

  2. Perl, Python, Ruby are still left

  3. Perl, Python, Ruby are still left

  4. Perl, Python, Ruby are still left

  5. Perl, Python, Ruby are still left

  6. Perl, Python, Ruby are still left (Notepad++ works great for all three languages)



Ok, so I looked at good toolkits for all three languages. My clear favorite is Ruby, for several reasons. I love the language, I know the language, Richard does a great job maintaining the Qt- and KDE-bindings, the PickAxe is a perfect book to learn Ruby from and so on. But I did not choose Ruby. For a very simple reason. Lets see:

    Toolkit
  1. Has to be free as in beer and freedom

  2. Has to have a good documentation for me (as I need to be a few steps ahead of my students)

  3. Has to have a german documentation for my students

  4. Has to run on Windows 2000, XP, Vista and Linux

  5. Has to have a german examples/tutorials which run out of the box (for my students)



  1. Qt, GTK and wx variants of Perl, Python and Ruby are left

  2. Qt variants of Python and Ruby are left. Sorry for wx and GTK, but there are no good documents I could use. This alone rules you out. Beside this, I'd always prefere Qt as I know that toolkit. But I would have taken wx and GTK to the next level if they had better docs. wxPython has "ok" docs, but compared to what I found for PyQt4 it is still quite thin.

  3. PyQt4 and QtRuby4 are still left. Now wxPython and PyGTK would have died anyway.

  4. PyQt4 is left. Works like a charm on Windows and Linux. I often used QtRuby on Linux and so far never on Windows. It seems it once existed but is no longer maintained. A shame, really, as Ruby is such a great language.



So it will be PyQt4.

  • Python has a great free (beer and freedom, written in german) book which I will probably buy as a dead-tree version (I hate reading a book at the screen).

  • There are many, many, many good tutorials, workshops and so on.

  • Very good class documentation.

  • Even a book for PyQt4 itself (which is a huge plus).



I guess wxPython is on the second place. It also has a good book and compared to the other options a good documentation in general. Well, PyQt4 is nice, I already wrote a few hundred lines of code with it. I hope my students will also like my choice :-)

Tags:

Profile

Taken in Portugal
[info]cniehaus
cniehaus

Advertisement

Latest Month

July 2009
S M T W T F S
   1234
567891011
12131415161718
19202122232425
262728293031 

Syndicate

RSS Atom
Powered by LiveJournal.com
Designed by Tiffany Chow