The Art of Evolutionary Algorithms Programming

Preview:

Citation preview

The art of

Evolutionary Algorithms

programming,by Dr. Juan-Julián Merelo, Esq.Calling from the University of Granada

in the Old Continent of Europe

Art of Evolutionary Algorithms Programming/2

You suck

Art of Evolutionary Algorithms Programming/3

Don't worry

I suck too

Art of Evolutionary Algorithms Programming/4

This is about

sucking less

At programming evolutionary

algorithms, no less!

Or any other, for that matter!

Art of Evolutionary Algorithms Programming/5

And about the

zen

Art of Evolutionary Algorithms Programming/6

And about writing And about writing publishable papers publishable papers painlessly through painlessly through

efficient, efficient, maintainable, maintainable,

scientific scientific programmingprogramming

Art of Evolutionary Algorithms Programming/7

1. Mind your

environment

Art of Evolutionary Algorithms Programming/8

Tools of the tradeUse real operating systems.

Programmer's editor: kate, emacs, geany (your favorite editor here) + Debugger (gdb, language-specific debugger)

Set up macros, syntax-highlighting and -checking, online debugging.

IDE: Eclipse, NetBeans

Steep learning curve, geared for Java, and too heavy on the resource usage side

But worth the while eventually

Art of Evolutionary Algorithms Programming/9

2. Open source your code and data

Art of Evolutionary Algorithms Programming/10

Aw, maaaan!Open source first, then program

Scientific code should be born free

Science must be reproducible

Easier for others to compare with your approach

Increased H

Heaven!

Manifest hidden assumptions.

If you don't share, you don't care!

Art of Evolutionary Algorithms Programming/11

3. Minimize bugs via

test-driven programming

Art of Evolutionary Algorithms Programming/12

Tests before codeWhat do you want your code to do?

Mutate a bit string, for instance.

Write the test

Is the result different from the original?

Of course!

But will it be even if you change an upstream function? Or the representation?

Does it change all bits in the same proportion?

Doest it follow (roughly) the mutation rate?

Art of Evolutionary Algorithms Programming/13

Use testing frameworksUnit testing tries to catch

bugs in the smallest atom of a program

Interface, class, function, decision

Every language has its testing framework

PHPUnit, jUnit, xUnit, DejaGNU...

Write tests for failure, not

Art of Evolutionary Algorithms Programming/14

4. Control

the source of your power

Art of Evolutionary Algorithms Programming/15

Source control systems save the day

Source code management systems allow

Checkpoints

Code repositories

Individual responsability over code changes

Branches

Distributed are in: git, mercurial, bazaar

Centralized are out: subversion, cvs.

Instant backup!

Art of Evolutionary Algorithms Programming/16

Code complete Check out code/Update code

Make changes

Commit changes (and push to central repository)

Check out code/Update code

Make changes

Test your code

Commit changes (and push to central repository)

Art of Evolutionary Algorithms Programming/17

5. Be

language agnostic

Art of Evolutionary Algorithms Programming/18

Language shapes thought

Don't believe the hype:

Compiled languages are faster... NOT

Avoid programming in C in every language you use

Consider DSL: Damn Small Languages

Python, Perl, Lua, Ruby, Javascript... interpreted languages are faster.

Art of Evolutionary Algorithms Programming/19

Language agnoticism at its best

Evolving Regular Expressions for GeneChip Probe Performance Prediction

http://www.springerlink.com/content/j3x8r108x757876w/

The regular expresions are coded in AWK scripts:

Although this may seem complex, gawk (Unix’ free interpreted pattern scanning and processing language) can handle populations of a million

Art of Evolutionary Algorithms Programming/20

Programming speed

> program speed6

Art of Evolutionary Algorithms Programming/21

Scientists, not software engineers

Our deadlines are for papers – not for software releases

What should be optimized is speed-to-publish.

Make no sense to spend 90% time programming – 10 % writing paper

Scripting languages rock

And maximize time-to-publish

Art of Evolutionary Algorithms Programming/22

Perl faster than Java?Algorithm::Evolutionary, a flexible Perl module for

evolutionary computation

http://www.springerlink.com/content/8h025g83j0q68270/

Class-by-class, Perl library much more compact

Less code to write

In pure EC code, Algorithm::Evolutionary was faster than ECJ

Art of Evolutionary Algorithms Programming/23

10.Become an

adept of the chosen language

Art of Evolutionary Algorithms Programming/24

Don't teach an old dog new tricks

The first language you learn brands you with fire

But no two languages are the same

Every language includes very efficient solutions

Regular expressions

Symbolic processing

Graphics

Efficiency/knowledge balance

Art of Evolutionary Algorithms Programming/25

11

Don't assume: measure

Art of Evolutionary Algorithms Programming/26

Performance mattersBasic measure: CPU time as measured by time

jmerelo@penny:~/proyectos/CPAN/Algorithm-Evolutionary/benchmarks$ time perl onemax.pl

0; time: 0.003274

1; time: 0.005438

[...]

498; time: 1.006539

499; time: 1.00884

Art of Evolutionary Algorithms Programming/27

Goin

g a

bit d

eep

er

Art of Evolutionary Algorithms Programming/28

Size matters

Art of Evolutionary Algorithms Programming/29

There's always a better

algorithm/data

structure

12

Art of Evolutionary Algorithms Programming/30

And differences are huge

Sort algorithms are an example

Plus, do you need to sort the population?

Cache fitness evaluations

Cache them permanently in a database?

Measure how much fitness evaluation takes

Thousand ways of computing fitness

How do you compute the MAXONES?

$fitness_of{$chromosome} = ($copy_of =~ tr/1/0/);

Algorithms and data structures interact

Art of Evolutionary Algorithms Programming/31

1 3

Learn the tricks of the trade

Art of Evolutionary Algorithms Programming/32

Two tradesEvolutionary algorithms

Become one with your algorithm

It does not work, but for a different reason that what you think it does

Programming languages

What function is better implemented?

Is there yet another library to do sorting?

Where should you go if there's a problem?

Even a third trade: programming itself.

Art of Evolutionary Algorithms Programming/33

Case study: sortSorting is routinely used in evolutinary algorithms

Roulette wheel, rank-based algorithms

Faster sorts (in Perl): http://raleigh.pm.org/sorting.html

Sorting implies comparing

Orcish Manoeuver, Schwartzian transform

Sort::Key, fastest ever http://search.cpan.org/dist/Sort-Key/

Do you even need sorting?

Art of Evolutionary Algorithms Programming/34

Make output

processing easy14

Art of Evolutionary Algorithms Programming/35

Avoid drowning in dataEvery experiment produces megabytes of data

Timestamps, vectors, arrays, hashes

Difficult to understand a time from production

Use serialization languages for storing data

YAML: Yet another markup language

JSON: Javascript Object Notation

XML: eXtensible Markup languajge

Name your own

Art of Evolutionary Algorithms Programming/36

Case study: MastermindEntropy-Driven Evolutionary Approaches to the

Mastermind ProblemCarlos Cotta et al., http://www.springerlink.com/content/d8414476w2044g2m/

Output uses YAML

Includes

Experiment parameters

Per-run and per-generation data

Final population and run time

Open source!

Art of Evolutionary Algorithms Programming/37

When everything

fails visualize

Art of Evolutionary Algorithms Programming/38

15 to 25

backup your data

Art of Evolutionary Algorithms Programming/39

Better safe than unpublished

Get an old computer, and backup everything there.

In some cases, create virtual machines to reproduce one paper's environment

Do you think gcc 3.2.3 will work on your new one?

Use rsync, bacula or simply cp

It's not if your hard disk will fail, it's when

Cloud solutions are OK, but backup that too

Art of Evolutionary Algorithms Programming/40

26

Keep stuff together

Art of Evolutionary Algorithms Programming/41

Where did I left my keys?

Paper: program + data + graphics + experiment logs + text + revisions + referee reports + presentations

Experiments have to be rerun, graphics replotted, papers rewritten

Use logs to know which parameters produced which data which produced that graph

And put them all in the same directory tree

Art of Evolutionary Algorithms Programming/42

Get out and smell the

air

27

Art of Evolutionary Algorithms Programming/43

New is always betterProgramming paradigms are changing on a daily

basis

NoSQL, cloud computing, internet of things, Google Prediction API, map/reduce, GPGPU

Keep a balance between following fashions and finding more efficient ways of doing evolutionary algorithms.

And by doing I mean publishing

Art of Evolutionary Algorithms Programming/44

Nurture your code

28

Art of Evolutionary Algorithms Programming/45

A moment of joy, a lifetime of grief

Run tests periodically, or when there is a major upgrade of interpreter or upstream library.

Can be automated

Maintain a roadmap of releases

Remember this is free software

Get the community involved

Your research is for the whole wide world.

Art of Evolutionary Algorithms Programming/46

Publish, don't perish!

Art of Evolutionary Algorithms Programming/47

(no cats were harmed doing this presentation)

http://geneura.wordpress.com

http://twitter.com/geneura

Or camels!

Recommended