Algorithms to Live By
The Computer Science of Human Decisions
CMPSC-511
Sp2021 2
How Can CS Help Us In Our Lives?
● Based on the namesake book by Brian
Christian and Tom Griffiths
CMPSC-511
Sp2021 3
Optimal Stopping (The 37% Rule)
● The “Secretary Problem”
– Have a list of candidates for a position. Want to choose the best. Do not have
enough resources to interview everyone. When to stop interviewing?
– Formulated in 1960, published in Scientific American
– Take the best applicant after interviewing 37% (1/e) applicants!
● “Lover’s Leap”: at what age to stop dating and start building a
family?
– Have a time range (say, from 18 to 40). The 37% rule: when you are 26 y/o
(37% of 18--40), marry one of those dates!
CMPSC-511
Sp2021 4
Optimal Stopping (cont.)
● When to park?
– Move along an infinitely long street with parking meters towards your
destination
– Get N blocks close to the destination, then take the first available spot
● N is the function of occupancy rate: 1 for 50%, 7 for 90%, 69 for
99%, 693 for 99.9% (this is ridiculous!)
● When to sell?
● When to quit a risky business?
CMPSC-511
Sp2021 5
Exploit/Explore
● Stick to something old (“exploit”) or try something new (“explore”)?
– “Explore” = gather information [e.g., about restaurants], “exploit” = use
information [e.g., re-visit a known restaurant]
● Possible solution: “Win-Stay, Lose-Shift” (1952)
– As long as exploitation pays off, keep exploiting.
– When it does not, try something else.
– Better than random, but not perfect (“shift” in a rush?)
CMPSC-511
Sp2021 6
Exploit/Explore (cont.)
● Better solution: Gittins Index, a combined measure of wins and losses
– Can be tabulated. Consider two restaurants:
● GI1(2 wins, 2 losses)=0.6010
● GI2(0 wins, 0 losses)=0.7029
– Always follow the strategy with the highest Gittins Index:
● Switch to the second restaurant!
● Yet another alternative solution: minimize regret!
– Regret = satisfaction vs. expectation. Can be quantified.
CMPSC-511
Sp2021 7
Caching
● Libraries are an example of memory hierarchy:
– display space at the front (“primary memory”)
– stacks (“secondary memory”)
– offsite storage (“tertiary memory”)
● Where to put returned books?
– To the front! (“Most Recently Used,” if temporal locality holds)
● What do libraries do?
– Put the most recent acquisitions to the front! (FIFO)
– Turn the library inside out!
CMPSC-511
Sp2021 8
Scheduling
● Gantt charts for your task list (1910s)
● How to execute your task list if you have deadlines?
– Earliest Due Date strategy minimizes maximum lateness
● The optimal strategy
– Modification, Moore’s Algorithm: “throw away the biggest item”
● If you cannot do everything by the due date, minimize the number
of unfinished tasks
CMPSC-511
Sp2021 9
Scheduling (cont.)
● Have no deadlines? Minimize the collective outsider’s delay!
– Shortest Processing Time: always do the quickest task. Get things done!
● What if the tasks have priorities/weights?
– Divide each task’s weight by its processing time to get density
– Execute in the order of decreasing densities
● Paying debts
– Want to minimize the payoff? Funnel the money in the debt with the highest
interest rate.
– Want to minimize the number of debts? Pay the smallest debt.
CMPSC-511
Sp2021 10
Scheduling (cont.)
● Preemption
– Execute tasks in small blocks. Reduces fatigue.
– The price of “context switch” from one task to another (attention switch).
● Metawork! (Rather than “real work.”)
● Thrashing
– Preoccupied with metawork?
– Solution: the art of saying “no.”
CMPSC-511
Sp2021 11
Bayesian Predictions
● To make a prediction, we need to know prior probabilities (“given
that ...”)
● Copernican Principle: absent any prior knowledge about a process,
we are likely to be in the middle of it.
– It will take the process the same time terminate as it took to begin.
– “The [near] future is the same as the [near] past.”
● Will a 99-y/o live another 99 years?
CMPSC-511
Sp2021 12
Bayesian Predictions (cont.)
● Power law data (scale free; no average; “rich get
richer”; preferential attachment)
– Multiplicative rule: predict by multiplying by some
constant (x2 for Copernican principle, x1.4 for lifetime
grosses of movies)
● Normal data
– Average rule (predict the average if below the average; add
small constant if above the average)
– A 99-y/o will live to 99+Y years
● Erlang data (distribution of phone call durations)
– Additive rule (predict some constant additional duration)
– “Just five more minutes!”
CMPSC-511
Sp2021 13
Randomness
● Problem: organize a 10-city world vacation with the cheapest air
transportation
– 10! = 3,628,800 variants
● Greedy approach: always fly to the next cheapest destination
– Does not produce globally optimal solution
● Hill climbing: construct a random itinerary, randomly swap pairs of
cities if a swap decreases the cost
– May end up in a local maximum: good locally, bad globally
CMPSC-511
Sp2021 14
Randomness (cont.)
● Hill climbing with jitter: climb the hill but also randomly accept
results that make the outcome worse
● Hill climbing with restarts: climb the hill many times starting from
different initial random itineraries; continue until no improvement
● Simulated annealing: climb the hill but randomly accept results that
make the outcome worse with the decreasing probability of
acceptance
– Starts as hill climbing with jitter
– Becomes the regular hill climbing at the end
– Best results!

Algorithms

  • 1.
    Algorithms to LiveBy The Computer Science of Human Decisions
  • 2.
    CMPSC-511 Sp2021 2 How CanCS Help Us In Our Lives? ● Based on the namesake book by Brian Christian and Tom Griffiths
  • 3.
    CMPSC-511 Sp2021 3 Optimal Stopping(The 37% Rule) ● The “Secretary Problem” – Have a list of candidates for a position. Want to choose the best. Do not have enough resources to interview everyone. When to stop interviewing? – Formulated in 1960, published in Scientific American – Take the best applicant after interviewing 37% (1/e) applicants! ● “Lover’s Leap”: at what age to stop dating and start building a family? – Have a time range (say, from 18 to 40). The 37% rule: when you are 26 y/o (37% of 18--40), marry one of those dates!
  • 4.
    CMPSC-511 Sp2021 4 Optimal Stopping(cont.) ● When to park? – Move along an infinitely long street with parking meters towards your destination – Get N blocks close to the destination, then take the first available spot ● N is the function of occupancy rate: 1 for 50%, 7 for 90%, 69 for 99%, 693 for 99.9% (this is ridiculous!) ● When to sell? ● When to quit a risky business?
  • 5.
    CMPSC-511 Sp2021 5 Exploit/Explore ● Stickto something old (“exploit”) or try something new (“explore”)? – “Explore” = gather information [e.g., about restaurants], “exploit” = use information [e.g., re-visit a known restaurant] ● Possible solution: “Win-Stay, Lose-Shift” (1952) – As long as exploitation pays off, keep exploiting. – When it does not, try something else. – Better than random, but not perfect (“shift” in a rush?)
  • 6.
    CMPSC-511 Sp2021 6 Exploit/Explore (cont.) ●Better solution: Gittins Index, a combined measure of wins and losses – Can be tabulated. Consider two restaurants: ● GI1(2 wins, 2 losses)=0.6010 ● GI2(0 wins, 0 losses)=0.7029 – Always follow the strategy with the highest Gittins Index: ● Switch to the second restaurant! ● Yet another alternative solution: minimize regret! – Regret = satisfaction vs. expectation. Can be quantified.
  • 7.
    CMPSC-511 Sp2021 7 Caching ● Librariesare an example of memory hierarchy: – display space at the front (“primary memory”) – stacks (“secondary memory”) – offsite storage (“tertiary memory”) ● Where to put returned books? – To the front! (“Most Recently Used,” if temporal locality holds) ● What do libraries do? – Put the most recent acquisitions to the front! (FIFO) – Turn the library inside out!
  • 8.
    CMPSC-511 Sp2021 8 Scheduling ● Ganttcharts for your task list (1910s) ● How to execute your task list if you have deadlines? – Earliest Due Date strategy minimizes maximum lateness ● The optimal strategy – Modification, Moore’s Algorithm: “throw away the biggest item” ● If you cannot do everything by the due date, minimize the number of unfinished tasks
  • 9.
    CMPSC-511 Sp2021 9 Scheduling (cont.) ●Have no deadlines? Minimize the collective outsider’s delay! – Shortest Processing Time: always do the quickest task. Get things done! ● What if the tasks have priorities/weights? – Divide each task’s weight by its processing time to get density – Execute in the order of decreasing densities ● Paying debts – Want to minimize the payoff? Funnel the money in the debt with the highest interest rate. – Want to minimize the number of debts? Pay the smallest debt.
  • 10.
    CMPSC-511 Sp2021 10 Scheduling (cont.) ●Preemption – Execute tasks in small blocks. Reduces fatigue. – The price of “context switch” from one task to another (attention switch). ● Metawork! (Rather than “real work.”) ● Thrashing – Preoccupied with metawork? – Solution: the art of saying “no.”
  • 11.
    CMPSC-511 Sp2021 11 Bayesian Predictions ●To make a prediction, we need to know prior probabilities (“given that ...”) ● Copernican Principle: absent any prior knowledge about a process, we are likely to be in the middle of it. – It will take the process the same time terminate as it took to begin. – “The [near] future is the same as the [near] past.” ● Will a 99-y/o live another 99 years?
  • 12.
    CMPSC-511 Sp2021 12 Bayesian Predictions(cont.) ● Power law data (scale free; no average; “rich get richer”; preferential attachment) – Multiplicative rule: predict by multiplying by some constant (x2 for Copernican principle, x1.4 for lifetime grosses of movies) ● Normal data – Average rule (predict the average if below the average; add small constant if above the average) – A 99-y/o will live to 99+Y years ● Erlang data (distribution of phone call durations) – Additive rule (predict some constant additional duration) – “Just five more minutes!”
  • 13.
    CMPSC-511 Sp2021 13 Randomness ● Problem:organize a 10-city world vacation with the cheapest air transportation – 10! = 3,628,800 variants ● Greedy approach: always fly to the next cheapest destination – Does not produce globally optimal solution ● Hill climbing: construct a random itinerary, randomly swap pairs of cities if a swap decreases the cost – May end up in a local maximum: good locally, bad globally
  • 14.
    CMPSC-511 Sp2021 14 Randomness (cont.) ●Hill climbing with jitter: climb the hill but also randomly accept results that make the outcome worse ● Hill climbing with restarts: climb the hill many times starting from different initial random itineraries; continue until no improvement ● Simulated annealing: climb the hill but randomly accept results that make the outcome worse with the decreasing probability of acceptance – Starts as hill climbing with jitter – Becomes the regular hill climbing at the end – Best results!