Slide 1

Slide 1 text

Money,  Sex  and  Evolu0on   Agent-­‐based  modeling   with  Ruby   Sau  Sheong  Chang   PayPal   Oct  2014  

Slide 2

Slide 2 text

About  me  

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

Common  Starling  (Sturnus  vulgaris)  

Slide 6

Slide 6 text

•  Boids  by  Craig  Reynolds   •  Models  animal  mo0ons   through  3  simple  rules,   resul0ng  in  flocking  behavior   •  Emergence  –  complex  behavior   arises  from  simple  rules   •  Eventual  basis  for  some  impressive  cinema   anima0on  –  Lord  of  the  Rings,  Batman  Returns,   Lion  King  etc  

Slide 7

Slide 7 text

Agent-­‐based  modeling     •  Autonomous  agents  interac0ng  with  each   other  and  the  environment   •  Used  in  analysing  supply  chain  op0miza0on,   traffic  paSerns,  economic  models,  spread  of   epidemics   •  Influenced  by  John  Conway’s  Game  of  Life   •  Heavily  influenced  by  Epstein  and  Axtell’s   Sugarscape  simula0ons  

Slide 8

Slide 8 text

Utopia   •  Ar0ficial  world  called  Utopia   •  Populated  by  roids  (implementa0on  of  boids   in  Ruby)   •  Free  to  wander  through  an  infinite  landscape   •  Simula0ons  are  created  with  Ruby  and  the   Gosu  library  

Slide 9

Slide 9 text

Base  simula0on  

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

Why  does  income   inequality  exist?  

Slide 13

Slide 13 text

Change  behavior  in  base  simula0on   •  Roids  now  have  an  energy  level  (randomly   assigned,  max  100)   •  At  every  0ck,  roids  lose  1  energy   •  If  energy  level  reaches  0,  it  will  die   •  To  prevent  this,  it  will  ac0vely  seek  out  food   and  consume  it   •  Consuming  food  replenishes  energy  level   •  (But  roids  are  s0ll  immortal)  

Slide 14

Slide 14 text

Data  collec0on   •  At  every  0ck  record  the  energy  level  of  each   roid   •  Do  this  un0l  the  end  of  the  world  (simula0on   completes)  

Slide 15

Slide 15 text

First  simula0on  

Slide 16

Slide 16 text

Energy  level  analysis  

Slide 17

Slide 17 text

On  the  day  of  reckoning   Most  roids  are  dead   A  few  roids  have  a   lot  of  energy  

Slide 18

Slide 18 text

Gini  coefficient  and  Lorenz  curve   •  The  Gini  coefficient  is  a   measure  of  the  inequality  of   a  distribu0on,  0  is  perfect   equality  and  1  is  perfect   inequality   •  Defined  mathema0cally   based  on  the  Lorenz  curve   Area  is  the  amount   of  inequality  

Slide 19

Slide 19 text

Lorenz  curve  on  inequality   Not  much   inequality   A  lot  of   inequality!  

Slide 20

Slide 20 text

Observa0on   •  Over  a  period  of  0me,  a  small  percentage  of   the  popula0on  gets  a  large  propor0on  of  the   energy   •  What  is  the  cause  of  this?  

Slide 21

Slide 21 text

Why  the  inequality?   •  Hard  work  and  inherent  talent/ability?   – All  roids  are  the  SAME   •  Some  roids  luckier  than  others  i.e.   random  distribu0on?   – If  it’s  random  then  it  should  follow  a  normal   distribu0on  

Slide 22

Slide 22 text

The  rich  get  richer,  the  poor  get   poorer   •  Back  to  where  we  started  –  emergence   •  Small  changes  ripple  down  to  large  effects   over  a  period  of  0me   •  Simple  local  rules  brings  complex  global   changes  

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

Spicing  things  up  with  sex   •  Roids  have  gender  now  –  male  and  female   •  Males  are  blue,  females  are  red,  underaged  are     •  If  female  is  within  childbearing  age  (25  to  50   0cks)  and  if  it  has  enough  energy,  it  will  look  for  a   nearby  male     •  If  the  male  it  encounters  is  also  within   childbearing  age  and  have  enough  energy,  they   will  procreate  and  produce  a  baby  roid   •  Both  male  and  female  loses  energy  each  0me   they  procreate  

Slide 25

Slide 25 text

Grim  reaper  arrives   •  With  birth  we  introduce  death   •  Each  roid  has  a  randomly  assigned  lifespan   •  Each  0ck  increases  the  age  of  the  roid   •  Roid  dies  when  it  reaches  its  lifespan  (no   maSer  how  much  energy  it  has)  

Slide 26

Slide 26 text

Data  collec0on   •  We  want  to  inves0gate  how  the  popula0on   changes  once  we  introduce  sex  and  death   •  At  every  0ck  we  collect  the  popula0on  of  the   en0re  world,  as  well  as  popula0on  of  males   and  females  

Slide 27

Slide 27 text

Second  simula0on  

Slide 28

Slide 28 text

Data  analysis   Popula0on   fluctuates  

Slide 29

Slide 29 text

With  a  minor  change   What  happens  here?  

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

What  just  happened?   •  I  changed  a  parameter  -­‐  the  childbearing  age   •  Original   – CHILDBEARING_AGE  =  25..50   •  Changed   – CHILDBEARING_AGE  =  30..50   •  Does  it  happen  all  the  0me?  NO  -­‐  4  out  of  5   0mes  

Slide 32

Slide 32 text

Looks  familiar?   •  Financial  crashes,  social  unrest  (Arab  Spring?),   animal  ex0nc0ons,  climate  change?   •  Simula0on  suggests  small  internal  factors  can   be  enough  to  trigger  crises  that  cannot  be   recovered   •  Not  necessarily  need  large  external  triggers    

Slide 33

Slide 33 text

Things  are  NOT  as  stable   or  as  unrelated  as  we   like  to  think  it  is  

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Natural  selec0on   •  A  central  concept  in  evolu0on   •  “Survival  of  the  fiSest”   •  Organisms  with  more  suitable  aSributes  are   more  likely  to  reproduce  and  pass  these   aSributes  to  the  next  genera0on   •  Over  0me  these  aSributes  become   more  prominent  

Slide 36

Slide 36 text

Natural  selec0on  in  Utopia   •  Previously  all  roids  have  the  same  aSributes,  only   difference  is  maximum  lifespan  and  energy  level   •  In  this  simula0on,  we  add  2  new  aSributes   –  Metabolism   How  well  the  roid  converts  the  food  it  eats  into  energy  (higher   number  beSer)   –  Vision  range   How  far  away  it  can  see  food  (higher  number  beSer)   •  Roid  babies  inherit  these  2  aSributes  from  their   parents  

Slide 37

Slide 37 text

Crossover  of  gene0c  aSributes   •  We  follow  very  simple  Mendelian  rules  for   crossover   •  Assume  the  father  has  the  genotype  (m,v)  and   the  mother  has  genotype  (M,V)   •  Possible  genotypes  of  baby  are  (m,v),  (m,V),   (M,v)  and  (M,V)   •  We  randomly  chose  1  of  these  4  possibili0es    

Slide 38

Slide 38 text

Data  collec0on   •  We  want  to  find  out  how  the  metabolism  and   vision  range  aSributes  of  the  popula0on   changes  over  0me   •  At  every  0ck,  we  calculate  the  average   metabolism  and  vision  range  of  all  roids  that   are  alive  

Slide 39

Slide 39 text

Third  simula0on  

Slide 40

Slide 40 text

Natural  selec0on  in  ac0on!   Metabolism   improves  over   0me   Vision  range   improves  over   0me   Natural  selec0on  is   not  a  straight  line  

Slide 41

Slide 41 text

What  did  we  just  see?   •  Natural  selec0on  -­‐  the  roids  with  the  beSer   aSributes  are  able  to  survive  longer  and   reproduce  with  similar  aSributes   •  Natural  selec0on  is  not  necessarily  a  straight   line  (vision  range  meanders  for  a  while)  

Slide 42

Slide 42 text

One  more  thing  …  

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

Is  inheritance  any  good?   •  In  our  simula0ons,  when  a  roid  dies  of  old  age,   his  collected  energy  dissipates   •  What  happens  if  the  collected  energy  of  a  roid   is  passed  on  to  his  children  instead?   •  This  simulates  wealth  gathered  by  the  parents   being  inherited  by  the  children  

Slide 45

Slide 45 text

Fourth  simula0on   •  Simula0on  the  same  as  the  evolu0on   simula0on  except  that  when  a  roid  dies,  the   energy  he  collects  over  his  life0me  is   distributed  to  his  children   •  Compare  the  evolu0on  simula0on  with  the   inheritance  simula0on  

Slide 46

Slide 46 text

One  more  0me,  with  inheritance   With  inheritance,   natural  selec0on  gets   there  but  takes  a  longer   0me  

Slide 47

Slide 47 text

Effects  of  inheritance   •  From  the  simula0on,  inheritance  seem  stunt   evolu0onary  advances,  causing  natural   selec0on  to  take  a  longer  0me  

Slide 48

Slide 48 text

Base   Money   Sex   Evolu0on   Inheritance   Recap  

Slide 49

Slide 49 text

Wrapup   •  Simula0ons  ≠  real  life,  but  is  good  to  isolate   factors  for  inves0ga0on   •  Conclusions  open  for  interpreta0on  (Lies,   damn  lies  and  simula0ons)   •  Programming  as  tools  to  discover  the  world   around  us  

Slide 50

Slide 50 text

Miscellaneous  stuff   •  Simula0on  –  Ruby,  Gosu   •  Analysis  –  Ruby,  Gruff   •  hSps://github.com/sausheong/utopia   •  [email protected]  -­‐  personal   •  [email protected]  -­‐  work   •  @sausheong  -­‐  TwiSer