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

RockyMountain 2015: Prepare yourself against Zombie epidemic

RockyMountain 2015: Prepare yourself against Zombie epidemic

The news is everywhere: some weird disease makes the dead walking. We do not know yet if it is highly contagious. What should we do? What we do everyday: writing code. We can develop an agent based model, simulate the disease, and hopefully find the best strategy to survive. We can code, we'll be prepared ... or not.

code: https://github.com/toch/zombie_epidemic

Christophe Philemotte

September 24, 2015
Tweet

More Decks by Christophe Philemotte

Other Decks in Programming

Transcript

  1. Christophe
    toch
    _toch

    View full-size slide

  2. Benjamin Lehman, ©2011

    View full-size slide

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

    View full-size slide

  4. Agent
    Based
    Model

    View full-size slide

  5. Agent
    Based
    Model

    View full-size slide

  6. Map
    National Geographics, ©2011

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. John DellAngelo, ©2013
    Agent

    View full-size slide

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

    View full-size slide

  11. agent.perceive
    # => {}

    View full-size slide

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

    View full-size slide

  13. agent.age
    # => 1

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  19. State
    Transition
    Machine

    View full-size slide

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

    View full-size slide

  21. Simulation
    Loop

    View full-size slide

  22. 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 full-size slide

  23. 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 full-size slide

  24. 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 full-size slide

  25. 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 full-size slide

  26. 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 full-size slide

  27. 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 full-size slide

  28. 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 full-size 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 full-size 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 full-size slide

  31. Validation
    &
    Calibration

    View full-size slide

  32. # validation == integration test
    #
    # check:
    # - obvious case
    # - against theoretical model
    # - against real data

    View full-size slide

  33. # not everything known
    # so calibration:
    #
    # varying a few parameters
    # to get what you want

    View full-size slide

  34. Simulate
    &
    Prepare yourself

    View full-size slide

  35. ?
    toch
    _toch
    toch/zombie_epidemic

    View full-size slide