Try changing various conditions to "gather 1000 people in the room and keep giving money to random opponents"

Introduction

["Gather 100 people in a room and keep giving money to a random partner" will gradually make a difference between rich and poor](http://gigazine.net/news/20170711-random-people-give-money-to- There is a Gigazine article called random-other-people /).

I think there are various impressions such as "Oh, that's right" and "Oh, I was surprised", but since it is a simple experiment, I tried changing various conditions and it was surprisingly interesting, so I will introduce it.

Try changing various conditions to "gather 1000 people in the room and keep giving money to random opponents"

I felt that there were few people with 100 people, so I will try with 1000 people.

If 1000 people initially have 1000 gold and randomly give 1 gold to someone each turn

The histograms of the amount of money possessed on turns 10, 100, 1000, and 10000 and the number of people are as follows.

Kobito.0rXvUI.png

Basically, it feels like a normal distribution centered around 1000. You can see that the base expands as the trial is repeated.

If 1000 people initially have 1000 gold and give it randomly each turn * If you give it to a richer person than yourself, there is a 10% chance of rethinking who to give it again *

When giving to a richer person than yourself, there is a 10% chance of re-deciding who to give.

Kobito.621N5V.png

The distribution is similar, but the base is narrower than before. Is it safe to say that wealth is being redistributed?

If 1000 people initially have 1000 gold and give it randomly each turn * If you give it to a poorer person than yourself, there is a 10% chance to reconsider who to give it again *

On the contrary, when giving to a poorer person than yourself, there is a 10% chance of re-deciding who to give.

Kobito.u3hiSE.png

This time, on the contrary, the base has expanded greatly. It is a disparity society w Is it a microcosm of a society that does not ask the poor to work?

If 1000 people * initially have 50 gold and give 1 gold to someone at random each turn

This time, there are no particular conditions for giving money like the very first, but if the first money you have is 50.

Kobito.FFphBG.png

The number of people whose money becomes 0 increases, and those who do not have money do not give it to anyone, so it seems to be quite biased.

script

This is the script I used this time. You can run it on Jupyter Notebook.

import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt

%matplotlib inline

N = 1000  #Number of people
M = 1000  #First money
P = 0     #Probability of rethinking when handing over to the rich and poor.If not 0.10%Then 0.1。
plot_index = [10, 100, 1000, 10000]  #Turn number to display the graph
T = max(plot_index)
plt.figure(figsize=(24, 6))


def transfer_money(moneys):
    transfer = np.zeros_like(moneys)
    for i in range(N):
        if moneys[i] > 0:
            while True:
                to_money = np.random.randint(0, N)
                #If you do not give it to the rich: `moneys[to_money] > moneys[i]`
                #If you do not give it to the poor: `moneys[to_money] < moneys[i]`
                if moneys[to_money] < moneys[i] and np.random.random() < P:
                    continue
                break
            transfer[i] -= 1
            transfer[to_money] += 1
    moneys += transfer

moneys = np.ones((N, )) * M

for i in range(T+1):
    if i in plot_index:
        plt.subplot(1, len(plot_index), plot_index.index(i)+1)
        ax = sns.distplot(moneys, kde=False, bins=20)
        ax.set_title("i=%d" % i)
        ax.set_xlabel("money")
        ax.set_ylabel("person count")
    transfer_money(moneys)

plt.show()

at the end

This kind of thing is fun.

Recommended Posts

Try changing various conditions to "gather 1000 people in the room and keep giving money to random opponents"
Cython to try in the shortest
Various comments to write in the program
I want to visualize where and how many people are in the factory
Try to display the Fibonacci sequence in various languages in the name of algorithm practice