The Art of Evolutionary Algorithms Programming

47
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

Transcript of The Art of Evolutionary Algorithms Programming

Page 1: The Art of Evolutionary Algorithms Programming

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

Page 2: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/2

You suck

Page 3: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/3

Don't worry

I suck too

Page 4: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/4

This is about

sucking less

At programming evolutionary

algorithms, no less!

Or any other, for that matter!

Page 5: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/5

And about the

zen

Page 6: The Art of Evolutionary Algorithms Programming

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

Page 7: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/7

1. Mind your

environment

Page 8: The Art of Evolutionary Algorithms Programming

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

Page 9: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/9

2. Open source your code and data

Page 10: The Art of Evolutionary Algorithms Programming

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!

Page 11: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/11

3. Minimize bugs via

test-driven programming

Page 12: The Art of Evolutionary Algorithms 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?

Page 13: The Art of Evolutionary Algorithms Programming

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

Page 14: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/14

4. Control

the source of your power

Page 15: The Art of Evolutionary Algorithms Programming

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!

Page 16: The Art of Evolutionary Algorithms Programming

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)

Page 17: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/17

5. Be

language agnostic

Page 18: The Art of Evolutionary Algorithms Programming

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.

Page 19: The Art of Evolutionary Algorithms Programming

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

Page 20: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/20

Programming speed

> program speed6

Page 21: The Art of Evolutionary Algorithms Programming

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

Page 22: The Art of Evolutionary Algorithms Programming

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

Page 23: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/23

10.Become an

adept of the chosen language

Page 24: The Art of Evolutionary Algorithms Programming

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

Page 25: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/25

11

Don't assume: measure

Page 26: The Art of Evolutionary Algorithms Programming

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

Page 27: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/27

Goin

g a

bit d

eep

er

Page 28: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/28

Size matters

Page 29: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/29

There's always a better

algorithm/data

structure

12

Page 30: The Art of Evolutionary Algorithms Programming

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

Page 31: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/31

1 3

Learn the tricks of the trade

Page 32: The Art of Evolutionary Algorithms Programming

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.

Page 33: The Art of Evolutionary Algorithms Programming

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?

Page 34: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/34

Make output

processing easy14

Page 35: The Art of Evolutionary Algorithms Programming

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

Page 36: The Art of Evolutionary Algorithms Programming

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!

Page 37: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/37

When everything

fails visualize

Page 38: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/38

15 to 25

backup your data

Page 39: The Art of Evolutionary Algorithms Programming

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

Page 40: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/40

26

Keep stuff together

Page 41: The Art of Evolutionary Algorithms Programming

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

Page 42: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/42

Get out and smell the

air

27

Page 43: The Art of Evolutionary Algorithms Programming

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

Page 44: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/44

Nurture your code

28

Page 45: The Art of Evolutionary Algorithms Programming

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.

Page 46: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/46

Publish, don't perish!

Page 47: The Art of Evolutionary Algorithms Programming

Art of Evolutionary Algorithms Programming/47

(no cats were harmed doing this presentation)

http://geneura.wordpress.com

http://twitter.com/geneura

Or camels!