簡(jiǎn)評(píng):反直覺(jué)的問(wèn)題澡为,房間內(nèi)每個(gè)人隨機(jī)給于別人 1 元,你猜不到最后會(huì)發(fā)生什么蛇券。
--- Update ---
知友 KetoneHu 根據(jù)本文也寫(xiě)了一篇相關(guān)的回答缀壤,推薦給大家:從熱力學(xué)看這個(gè)問(wèn)題
「這個(gè)體系用一句熱力學(xué)的語(yǔ)言來(lái)描述的話(huà)是:對(duì)于一個(gè)孤立系統(tǒng),有恒定數(shù)量的粒子和能量(對(duì)應(yīng)人和金錢(qián))纠亚,這些能量是怎么在粒子之間分布的塘慕?」
--- 原文 ---
前幾天我們?cè)賲⒓右粋€(gè)電氣工程與計(jì)算機(jī)科學(xué)的主題會(huì)議,遇到了 Uri Wilensky蒂胞,他和我們分享了一個(gè)很有趣的分配模擬图呢。
問(wèn)題是這樣的:
想象著,有一個(gè)房間骗随,里面有 100 個(gè)人蛤织,每個(gè)人有 100 美元。每過(guò)一會(huì)鸿染,每個(gè)有錢(qián)的人給隨機(jī)的其他人 1 美元指蚜,經(jīng)過(guò)一段時(shí)間后,房間內(nèi)的資金分配情況是怎樣涨椒?
如果摊鸡,你快速的思考,然后認(rèn)為「或多或少的趨于平均」蚕冬,你這個(gè)想法并不孤單免猾。
我問(wèn)了 5 個(gè)超級(jí)聰明的博士,他們也都有同樣的第一感覺(jué)囤热,認(rèn)為會(huì)趨于平均猎提。
所以,真實(shí)的分布狀況應(yīng)該是如何呢旁蔼,請(qǐng)看下面這個(gè) gif锨苏。
- gif 的左上角是次數(shù),每次代表著一次財(cái)富的改變牌芋。
- Y 軸顯示的是美元存量蚓炬,初始 45 美元。
- X 軸顯示的是 45 個(gè)人躺屁。
- 上圖(紅色圖)顯示每時(shí)肯夏,每人的財(cái)富。
- 下圖(藍(lán)色圖)就是把紅色圖遞增排序了一下,方便查看驯击。
不信這個(gè)結(jié)果么烁兰?你可以用 R、tidvverse 和 gganimate 代碼自己跑一跑徊都。
不平等可能源于完全無(wú)害的政策和規(guī)則沪斟,你要時(shí)刻關(guān)注他們。
library(tidyverse)
library(gganimate)
NUMPLAYERS = 45
ROUNDS = 5000
INITWEALTH = 45
#initialize the bank
#columns wealths of the NUMPLAYERS players
#rows show wealths of each of the ROUNDS ticks of the clocks
bank = matrix(0, nrow = ROUNDS, ncol = NUMPLAYERS)
bank[1,] = c(rep(INITWEALTH, NUMPLAYERS))
#function to give a dollar to someone other than oneself
get_recipient = function(player) {
sample(setdiff(1:NUMPLAYERS, player), 1)}
#execute trades and update the ledger
for (i in 2:ROUNDS) {
#every player with wealth chooses another person to receive a buck
recipients = sapply(which(bank[i - 1,] > 0), get_recipient)
#table of the dollars owed each person
count_table = table(recipients)
#get the indices of the people owed money
indices = as.integer(names(count_table))
#everyone gives up a dollar, unless they are at zero
bank[i,] = ifelse(bank[i - 1,] > 0, bank[i - 1,] - 1, bank[i - 1,])
#selected people receive dollars
bank[i, indices] = bank[i, indices] + count_table
}
####################Animate it
#Make a suitable long data frame
df = as.data.frame(bank)
names(df) = 1:NUMPLAYERS
df = df %>%
mutate(frame = 1:ROUNDS) %>%
gather(person, wealth, 1:NUMPLAYERS) %>%
mutate(person = as.numeric(person)) %>%
arrange(frame) %>%
group_by(frame) %>%
mutate(rank = rank(wealth, ties.method = "random")) %>%
ungroup() %>%
gather(histtype,playerid,c(person,rank)) %>%
mutate(histtype = sprintf("Ordered by %s", histtype))
p <- ggplot(df, aes(x = playerid, y = wealth, frame = frame, fill=histtype)) +
theme_minimal() +
theme(panel.grid.major.x = element_blank(),
panel.grid.minor = element_blank()) +
geom_rect(aes( xmin = playerid - .4, xmax = playerid +.4, ymin = 0, ymax = wealth)) +
scale_x_continuous(breaks = 1:NUMPLAYERS) +
coord_cartesian(xlim = c(0, NUMPLAYERS), y = c(0, 5 * INITWEALTH)) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
labs(x='players',y='dollars') +
facet_wrap( ~ histtype,ncol=1) +
theme(legend.position = "none")
p
#set options for the animation package. Need ImageMagick installed on your computer
animation::ani.options(nmax = ROUNDS,
convert = 'C:\\Program Files\\ImageMagick-7.0.6-Q16')
#save the movie
gganimate(p, "dollar_stacked.mp4", interval = .01)
(R 語(yǔ)言版暇矫,Github:give_a_dollar.R)
園長(zhǎng):我想主之,這就是運(yùn)氣吧。
- 賣(mài)水挑戰(zhàn)賽
- 歡迎關(guān)注知乎專(zhuān)欄「極光日?qǐng)?bào)」李根,每天為 Makers 導(dǎo)讀三篇優(yōu)質(zhì)英文文章槽奕。