No description, website, or topics provided.
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Butterfly Algorithm

This is my attempt to make the Butterfly Algorithm more palatable by using pictures, text, math and code.

The notebook can be viewed on nbviewer.

Running the Code

Before running from the command line, check out this repository and then generate the module (from the IPython notebook)

$ git clone
$ make generated-module

after doing this, the simulation can be run

$ ./ --M=50 --L=10

to specify the number of terms in the Taylor series (M=50) and the number of refinements (L=10).


The code has been profiled using RunSnakeRun to create an image which shows where the code spends its time. The image was made with M = 50 and L = 10:

$ apt-get install python-wxgtk2.8
$ pip install SquareMap RunSnakeRun
$ make generated-module
$ python -m cProfile -o --M=50 --L=10
$ runsnake


To avoid using STIX fonts (don't look great for LaTeX slides), you can manually edit your IPython install.

First locate it

$ python -c 'import IPython; print IPython.__file__'

then edit. For example, if it is installed in


as above, edit the files


The key change is in the "HTML-CSS" key passed in to MathJax.Hub.Config:

    "HTML-CSS": {
        availableFonts: ["TeX"],  // Line added
        preferredFont: "TeX",  // Line added
        styles: {'.MathJax_Display': {"margin": 0}},
        linebreaks: { automatic: true }

The blue whale image and the butterfly image are Creative Commons licensed via Attribution 2.0 Generic.