Skip to content

Instantly share code, notes, and snippets.

@iemcd
Created February 2, 2023 00:53
Show Gist options
  • Save iemcd/9053f09605a030c7b686151c46876b8d to your computer and use it in GitHub Desktop.
Save iemcd/9053f09605a030c7b686151c46876b8d to your computer and use it in GitHub Desktop.
Switch Table Probabilities
#!/usr/bin/python3
# Calculating and plotting "Switch Tables" (see Marcia's blog)
# Ian McDougall, Feb 2023
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib as mpl
import matplotlib.pyplot as plt
sns.set_theme()
def cat_desc_single(a, b): # greater first
return int(str(a)+str(b)) if a>b else int(str(b)+str(a))
cat_desc = np.vectorize(cat_desc_single)
def cat_asc_single(a, b): # lesser first
return int(str(a)+str(b)) if a<b else int(str(b)+str(a))
cat_asc = np.vectorize(cat_asc_single)
def cat_arb_single(a, b): # first first
return int(str(a)+str(b))
cat_arb = np.vectorize(cat_arb_single)
d4 = np.arange(1, 5, dtype=int)
d6 = np.arange(1, 7, dtype=int)
d8 = np.arange(1, 9, dtype=int)
d10 = np.arange(10, dtype=int) # the only die with zero
d12 = np.arange(1, 13, dtype=int)
#d6x = d6[:, np.newaxis]
#d6y = d6[np.newaxis, :]
#d66 = cat_arb(d6x, d6y)
#d66d = cat_desc(d6x, d6y)
#d66a = cat_asc(d6x, d6y)
d10x = d10[:, np.newaxis]
d10y = d10[np.newaxis, :]
d100 = np.ravel(cat_arb(d10x, d10y))
d100d = np.ravel(cat_desc(d10x, d10y))
d100a = np.ravel(cat_asc(d10x, d10y))
d100_frame = {
"Descending": d100d,
"Arbitrary": d100,
"Ascending": d100a
}
fig1 = plt.figure()
ax1 = sns.ecdfplot(data=d100_frame, complementary=True)
ax1.set_xlim(0,100)
plt.xlabel('Result (At Least)')
plt.ylabel('Odds')
fig1.savefig('figure1.png', bbox_inches='tight')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment