import numpy as np
import matplotlib.pyplot as plt
import scipy.special
from itertools import combinations
mstate_count = 0
nlevels = 6
for p1 in range(nlevels):
for p2 in range(nlevels):
for p3 in range(nlevels):
for p4 in range(nlevels):
for p5 in range(nlevels):
mstate_count += 1
print(mstate_count)
assert(mstate_count == 6**5)
allowed_mstate_count = 0
nlevels = 6
e_constraint = 5
for p1 in range(nlevels):
for p2 in range(nlevels):
for p3 in range(nlevels):
for p4 in range(nlevels):
for p5 in range(nlevels):
if p1 + p2 + p3 + p4 + p5 == e_constraint:
allowed_mstate_count += 1
print(allowed_mstate_count)
nlevels = 6
e_constraint = 5
configs = []
for p1 in range(nlevels):
for p2 in range(nlevels):
for p3 in range(nlevels):
for p4 in range(nlevels):
for p5 in range(nlevels):
if p1 + p2 + p3 + p4 + p5 == e_constraint:
iconfig = np.zeros(nlevels)
for p in [p1, p2, p3, p4, p5]:
iconfig[p] += 1
configs.append(iconfig)
print(np.array(configs))
unique = np.unique(np.array(configs), axis=0)
print(unique)
print(np.size(unique, 0))
unique_with_weights = np.unique(np.array(configs), axis=0, return_counts=True)
for idx in range(len(unique_with_weights[0])):
print(f'Configuration {unique_with_weights[0][idx]} has weight {unique_with_weights[1][idx]}')
unique = unique_with_weights[0]
weights = unique_with_weights[1]
total_weight = sum(weights)
p_is = np.zeros(nlevels)
N = 5
for e_i in range(nlevels):
for config_index in range(len(unique)):
config = unique[config_index]
weight = weights[config_index]
n_i = config[e_i]
p_is[e_i] += n_i / N * (weight / total_weight)
print(p_is)
print(sum(p_is))
y = np.log(p_is)
x = np.arange(nlevels)
plt.plot(x,y)