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

KeepRubyWeird 2015: Prepare yourself against Zombie epidemic

KeepRubyWeird 2015: Prepare yourself against Zombie epidemic

Christophe Philemotte

October 26, 2015
Tweet

More Decks by Christophe Philemotte

Other Decks in Programming

Transcript

  1. Benjamin Lehman, ©2011

    View Slide

  2. Benjamin Lehman, ©2011
    Prepare yourself
    against
    Zombie epidemic

    View Slide

  3. Agent
    Based
    Model

    View Slide

  4. View Slide

  5. View Slide

  6. View Slide

  7. View Slide

  8. View Slide

  9. Agent
    Based
    Model

    View Slide

  10. Map
    National Geographics, ©2011

    View Slide

  11. map = Map.new(4, 4)

    View Slide

  12. point = Point.new
    point_north = Point.new
    point.neighborhood[:north] = point_north
    point_north.neighborhood[:south] = point
    # ...

    View Slide

  13. John DellAngelo, ©2013
    Agent

    View Slide

  14. agent = Agent.new(age, start_point, stm)

    View Slide

  15. agent.perceive
    # => {}

    View Slide

  16. agent.act
    # => :walk
    agent.walk(:east)

    View Slide

  17. View Slide

  18. agent.age
    # => 1

    View Slide

  19. agent.commit
    # => ## @name=:susceptible, ...

    View Slide

  20. State

    View Slide

  21. state = State.new(:susceptible)
    state.define_possible_actions(
    ->(agent) {
    [:walk, :stay, :fight].sample
    }
    )

    View Slide

  22. state.decide_action_for(agent)
    # => :walk

    View Slide

  23. infected = State.new(:susceptible)
    state.add_transition(
    infected,
    ->(state, agent) {
    true
    }
    )

    View Slide

  24. state.trigger_transition(agent)
    # => ## @name=:infected, ...

    View Slide

  25. View Slide

  26. State
    Transition
    Machine

    View Slide

  27. stm = StateTransitionMachine.new
    # create states:
    # - susceptible
    # - infected
    # - zombie
    # - dead
    # create transitions
    # set default initial state

    View Slide

  28. Simulation
    Loop

    View Slide

  29. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  30. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  31. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  32. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  33. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  34. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  35. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  36. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  37. steps = 100
    agents = create_the_agents
    steps.times do
    agents.each do |agent|
    agent.act; agent.age
    end
    agents.each { |agent| agent.commit }
    remove_the_deads(agents)
    end

    View Slide

  38. View Slide

  39. View Slide

  40. Validation
    &
    Calibration

    View Slide

  41. # validation
    # ==
    # functional test

    View Slide

  42. View Slide

  43. View Slide

  44. # Calibration
    # f(x, y, z, ?) = a

    View Slide

  45. Simulate
    &
    Prepare yourself

    View Slide

  46. Live Demo

    View Slide

  47. View Slide

  48. Outro

    View Slide

  49. ?
    toch
    _toch
    toch/zombie_epidemic

    View Slide