Generate U distribution in Python

Book: I wanted to generate the U distribution described in "Hands with Invisible Data: The Laws of Humans, Organizations, and Society Revealed by Wearable Sensors", so I programmed with Python. 2017.2.12 Fixed a code error.

More information about the book can be found on my blog at the link below. [Link] http://kansetsulight.seesaa.net

code

import numpy as np import matplotlib.pyplot as plt

nindex = []

n = 0 nxxx = 0 nyyy = 0 x = np.random.rand(1000)*100 y = np.random.rand(1000)*100

while n < 1000: if x[n] < 10: nxxx = 1 elif x[n] < 20: nxxx = 2 elif x[n] < 30: nxxx = 3 elif x[n] < 40: nxxx = 4 elif x[n] < 50: nxxx = 5 elif x[n] < 60: nxxx = 6 elif x[n] < 70: nxxx = 7 elif x[n] < 80: nxxx = 8 elif x[n] < 90: nxxx = 9 elif x[n] <= 100: nxxx = 10

if y[n] < 10: nyyy = 1 elif y[n] < 20: nyyy = 2 elif y[n] < 30: nyyy = 3 elif y[n] < 40: nyyy = 4 elif y[n] < 50: nyyy = 5 elif y[n] < 60: nyyy = 6 elif y[n] < 70: nyyy = 7 elif y[n] < 80: nyyy = 8 elif y[n] < 90: nyyy = 9 elif y[n] <= 100: nyyy = 10

nindex.append([nxxx, nyyy]) n = n + 1 nxxx = 0 nyyy = 0 ite = 0 chk = 0 while ite < 1e4:

chk1 = 0 while chk1 == 0: x_strt = np.random.randint(1,11) y_strt = np.random.randint(1,11)

chk1 = nindex.count([x_strt,y_strt])

strt = nindex.index([x_strt,y_strt]) print 'index of start: ',strt print 'index of start: ',nindex[strt] print 'x_strt, y_strt: ',x_strt, y_strt

chk2 = 0 while chk2 == 0: x_dest = np.random.randint(1,11) y_dest = np.random.randint(1,11) chk2 = nindex.count([x_dest,y_dest]) print chk2

dest = nindex.index([x_dest,y_dest])

x[strt] = float(x_dest10)-np.random.uniform(0,10) y[strt] = float(y_dest10)-np.random.uniform(0,10) print 'dest x,y index: ', x_dest,' ', y_dest print 'dest crd: ',x[strt],y[strt] print

Update for nindex nindex[strt] = nindex[dest] ite = ite + 1

fig = plt.figure()

ax = fig.add_subplot(1,1,1)

ax.scatter(x,y,s=1) ax.set_title('random plot') ax.set_xlabel('x') ax.set_ylabel('y')

ax.grid(True)

plt.savefig('testfig') plt.show()

The code is also up on GitHub. [Link] https://github.com/yama89/U-distribution1.0

result

<1 step later> up1.png

It's still even.

<10 steps later> up10.png

Does not change much

<100 steps later> up100.png

This also doesn't change much (at all?).

<1000 steps later> up1000.png

I feel that the bias has finally come out.

<2000 steps> up2000.png

This has come. The bias is clearly visible.

<10000 steps later> up10000.png

This is the U distribution.

I want to use this for something. I think.

Recommended Posts

Generate U distribution in Python
Logistic distribution in Python
Generate rounded thumbnails in Python
Write beta distribution in Python
Generate QR code in Python
Generate 8 * 8 (64) cubes in Blender Python
[Python] Generate QR code in memory
Mixed normal distribution implementation in python
Automatically generate frequency distribution table in one shot with Python
Generate a first class collection in Python
Quadtree in Python --2
Python in optimization
CURL in python
Geocoding in python
SendKeys in Python
Generate AWS-S3 signed (time-limited) URLs in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
Automatically generate Python Docstring Comment in Emacs
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Module to generate word N-gram in Python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
StepAIC in Python
N-gram in python
Generate a class from a string in Python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Generate C language from S-expressions in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Generate the Look-and-say Sequence featured in QuizKnock in Python
Convert Unicode escape sequences like \ u in Python
How to generate permutations in Python and C ++
Match the distribution of each group in Python
Create a standard normal distribution graph in Python