Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Money, Sex and Evolution

Money, Sex and Evolution

Simulation and Data Analysis with Ruby and R

Sau Sheong Chang

December 01, 2011
Tweet

More Decks by Sau Sheong Chang

Other Decks in Technology

Transcript

  1. Money,  Sex  and  Evolu0on   Simula0on  and  Data  Analysis  with

        Ruby  and  R   Chang  Sau  Sheong   Director,  Applied  Research,   HP  Labs  Singapore   Dec  2011  
  2. Base  simula0on   •  Boids  by  Craig  Reynolds   • 

    Models  animal  mo0ons  through   simple  rules,  resul0ng  in  flocking   behavior   •  Emergent  behavior  –  complex   behavior  arising  from  simple  rules   •  Eventual  basis  for  some  of  the  more  impressive   cinematographic  anima0on  –  Lord  of  the  Rings,   Batman  Returns,  Lion  King  etc  
  3. 3  simple  rules   •  Separa0on   – Move  to  avoid

     crowding  in  the   flock   •  Alignment   – Move  in  the  same  direc0on  as   the  flock   •  Cohesion   – Move  towards  the  center  of  the   flock  
  4. Simula0ons   •  Ar0ficial  world  called  Utopia   •  Populated

     by  ‘roids’   •  Free  to  wander  through  an  infinite  landscape   •  Simula0ons  are  created  with  Ruby  using  the   Shoes  UI  toolkit  
  5. Agent-­‐based  modeling     •  Also  known  as  mul0-­‐agent  simula0on

      •  Autonomous  agents  interac0ng  with  each  other  and   the  environment   •  Influenced  by  John  Conway’s  Game  of  Life   •  Earliest  ABM  simula0ons  by  Thomas  Schelling’s   (economist)  segrega0on  model   •   This  presenta0on  heavily  influenced  by  Epstein  and   Axtell’s  Sugarscape  simula0ons   •  Used  in  analysing  supply  chain  op0miza0on,  traffic   pa[erns,  economic  models,  spread  of  epidemics  
  6. US  average  income  (a\er  taxes)   A  report  from  the

     Congressional  Budget  Office  (CBO)  points  out  that  income   inequality  in  America  has  not  risen  drama0cally  over  the  past  20  years— when  the  top  1%  of  earners  are  excluded.  
  7. How  it  behaves   •  Roids  now  have  an  energy

     level   •  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)  
  8. Data  collec0on   •  At  every  0ck  record  the  energy

     level  of  each   roid   •  Do  this  un0l  the  end  of  the  simula0on  
  9. On  the  day  of  reckoning   Most  roids  are  dead

      A  few  roids  have  a   lot  of  energy  
  10. 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  
  11. Energy  ==  money   •  Over  a  period  of  0me,

     a  small  percentage  of   the  popula0on  gets  a  propor0on  of  the  energy   •  What  is  the  cause  of  this?  
  12. Why  the  inequality?   •  Hard  work  and  inherent  talent/ability?

      – All  roids  are  the  SAME   •  Some  lucky  roids  i.e.  random   distribu0on?   – If  it’s  random  then  it  should  follow  a  normal   distribu0on  
  13. The  rich  get  richer,  the  poor  get   poorer  

    •  Back  to  where  we  started  –  emergent   behavior   •  Small  changes  ripple  down  to  large  effects   over  a  period  of  0me   •  Simple  local  rules  brings  complex  global   changes  
  14. Spicing  things  up  with  sex   •  Roids  have  gender

     now  –  male  and  female   •  Males  are  blue,  females  are  grey   •  If  female  is  within  childbearing  age  (20  to  50   0cks)  and  if  it  has  enough  energy,  it  will  look  for  a   nearby  male     •  If  male  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  
  15. 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  
  16. 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  
  17. What  just  happened?   •  I  changed  a  parameter  -­‐

     the  childbearing  age   •  Original   – CHILDBEARING_AGE  =  20..50   •  Changed   – CHILDBEARING_AGE  =  25..50  
  18. Endogenous  vs  Exogenous   •  Are  ex0nc0ons  (and  other  crisis

     events)  solely   due  to  external  factors  (exogenous)?   •  Simula0on  suggests  internal  factors   (endogenous)  are  enough  to  trigger  crises  that   cannot  be  recovered   •  Other  crises  can  be  mapped  –  financial   crashes  (external  factors  or  inherent   instability?),  social  unrest  (external  agents  or   internal  issues?)  etc  
  19. Evolu0on   •  Previously  all  roids  have  the  same  a[ributes,

     only   difference  is  maximum  lifespan  and  energy  level   •  In  this  simula0on,  we  add  2  new  a[ributes   –  Metabolism   How  well  the  roid  converts  the  food  it  eats  into  energy  (higher   number  be[er)   –  Vision  range   How  far  away  it  can  see  food  (higher  number  be[er)   •  Roid  babies  inherit  these  2  a[ributes  from  their   parents  
  20. Crossover  of  gene0c  a[ributes   •  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    
  21. Data  collec0on   •  We  want  to  find  out  how

     the  metabolism  and   vision  range  a[ributes  of  the  popula0on   changes  over  0me   •  At  every  0ck,  we  calculate  the  average   metabolism  and  vision  range  of  all  roids  that   are  s0ll  alive  
  22. Evolu0on  in  ac0on!   Metabolism   improves  over   0me

      Vision  range   improves  over   0me  
  23. Evolu0on  explained   •  Survival  of  the  fi[est  –  the

     roids  with  the   be[er  a[ributes  are  able  to  survive  longer   and  reproduce  with  similar  a[ributes   •  Evolu0on  is  not  necessarily  a  straight  line   (vision  range  meanders  for  a  while)  
  24. Conclusion   •  The  rich  get  richer,  and  the  poor

     get  poorer   unless  the  system  is  regulated   •  Internal  changes  in  an  ecosystem  can  EASILY   trigger  crises  that  cannot  be  recovered   •  Evolu0on  is  not  always  a  straight  line      
  25. Miscellaneous  stuff   •  Simula0on  –  Ruby  and  Shoes  

    •  Analysis  –  R,  with  ggplot2,  ineq   •  Code  available  in  GitHub     h[ps://github.com/sausheong/everyday   •  h[p://blog.saush.com   •  [email protected]  -­‐  personal   •  [email protected]  -­‐  work/HP  related