Sample transformation power.py

From Werner KRAUTH

(Difference between revisions)
Jump to: navigation, search
Revision as of 13:22, 6 June 2024
Werner (Talk | contribs)

← Previous diff
Current revision
Werner (Talk | contribs)

Line 1: Line 1:
 +==Context==
 +This page is part of my [[BegRohu_Lectures_2024|2024 Beg Rohu Lectures]] on "The second Markov chain revolution" at the [https://www.ipht.fr/Meetings/BegRohu2024/index.html Summer School] "Concepts and Methods of Statistical Physics" (3 - 15 June 2024).
 +
 +==Python program==
 +
import random, math import random, math
import matplotlib.pyplot as plt import matplotlib.pyplot as plt

Current revision

Context

This page is part of my 2024 Beg Rohu Lectures on "The second Markov chain revolution" at the Summer School "Concepts and Methods of Statistical Physics" (3 - 15 June 2024).

Python program

import random, math
import matplotlib.pyplot as plt

N_trials = 1000000
data = []
gamma = -0.7
for iter in range(N_trials):
    Upsilon = random.uniform(0.0, 1.0)
#
#   This is the sample transformation SMAC eqs (1.28), (1.29)
#
    x = Upsilon ** (1.0 / (gamma + 1))
    data.append(x)

plt.title('power-law distribution (sample transformation)  $\gamma = $ '+ str(gamma))
plt.xlabel('$x$')
plt.ylabel('$\pi(x)$')
plt.hist(data, bins=100, density=True,label='data')
XValues = []
YValues = []
for i in range(5, 1000):
    x = i / 1000.0
    XValues.append(x)
    YValues.append((gamma + 1.0) * x ** gamma)
plt.plot(XValues, YValues, label='theory')
plt.legend(loc='upper right')
plt.show()
Personal tools