Maximum entropy principle

Florent Leclercq,
Institute of Cosmology and Gravitation, University of Portsmouth,
[email protected]

In [1]:
from scipy.optimize import fsolve
from math import log, pow

Dice example

In [2]:
mean=4
In [3]:
# x=exp(lambda) in the notations of the lecture notes
def Z(x):
    return (1-pow(x,-6))/(x-1)
def p1(x):
    return pow(x,-1)/Z(x)
def p2(x):
    return pow(x,-2)/Z(x)
def p3(x):
    return pow(x,-3)/Z(x)
def p4(x):
    return pow(x,-4)/Z(x)
def p5(x):
    return pow(x,-5)/Z(x)
def p6(x):
    return pow(x,-6)/Z(x)
In [4]:
def f(x):
    return x/(x-1) - 6/(pow(x,6)-1) - mean
    # This is -dlnZ/dZ-mean, which should be 0
x0=fsolve(f,2)[0]
x0
Out[4]:
0.83976857486597933
In [5]:
p1(x0), p2(x0), p3(x0), p4(x0), p5(x0), p6(x0)
Out[5]:
(0.10306524522362508,
 0.12273053351641969,
 0.14614804267474113,
 0.17403371244043664,
 0.20724008691110057,
 0.24678237923367699)
In [6]:
# check normalization constraint
p1(x0)+p2(x0)+p3(x0)+p4(x0)+p5(x0)+p6(x0)
Out[6]:
1.0
In [7]:
# check mean constraint
1*p1(x0)+2*p2(x0)+3*p3(x0)+4*p4(x0)+5*p5(x0)+6*p6(x0)
Out[7]:
3.9999999999999991

Cosmic web example

In [8]:
# Volume of the different structures (arbitrary normalization)
# (based on numbers given in table II in Leclercq et al. 2015a, arXiv:1502.02690)
V0 = 60
V1 = 20
V2 = 8
V3 = 1
In [9]:
# The average volume of a random cosmic web structure
V = 30
In [10]:
# x=exp(-beta) in the usual thermodynamic notations
def Z(x):
    return pow(x,V0)+pow(x,V1)+pow(x,V2)+pow(x,V3)
def p0(x):
    return pow(x,V0)/Z(x)
def p1(x):
    return pow(x,V1)/Z(x)
def p2(x):
    return pow(x,V2)/Z(x)
def p3(x):
    return pow(x,V3)/Z(x)
def dlnZdx(x):
    return p0(x)*V0+p1(x)*V1+p2(x)*V2+p3(x)*V3
In [11]:
def f(x):
    return dlnZdx(x)-V
x0=fsolve(f,0.9)[0]
x0
Out[11]:
1.0134673199344182
In [12]:
P0=p0(x0); P1=p1(x0); P2=p2(x0); P3=p3(x0)
P0,P1,P2,P3
Out[12]:
(0.39392560584840686,
 0.23068759870801528,
 0.19647498278472048,
 0.17891181265885733)
In [13]:
# check normalization constraint
P0+P1+P2+P3
Out[13]:
1.0
In [14]:
# check average volume constraint
P0*V0+P1*V1+P2*V2+P3*V3
Out[14]:
30.000000000001336