Skip to content

Instantly share code, notes, and snippets.

View mkingopng's full-sized avatar
🎯
Focusing

Michael Kingston mkingopng

🎯
Focusing
View GitHub Profile
@mkingopng
mkingopng / travellers_dilemma.py
Created March 7, 2022 10:16
travellers_dilemma
import random
x = int(input("What's your input: "))
y = random.randint(5, 20)
x_payoff = []
y_payoff = []
if x > y:
from matplotlib import pyplot as plt
import seaborn as sns
import numpy as np
from matplotlib.pyplot import axvline
from scipy.stats import skewnorm, rv_histogram
data = skewnorm.rvs(5, loc=100, scale=200, size=1000).astype(int) # create some random data
ax = sns.distplot(data, kde_kws={'label': 'kde of given data'}, label='histogram') # draw histogram & kde of data
params = skewnorm.fit(data, 10, loc=80, scale=40) # parameters to fit a skewnorm to the data
@mkingopng
mkingopng / cournot_competition.py
Created March 6, 2022 03:20
plot of cournot competition example
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots()
x = np.linspace(0, 50, 100)
# plot the first function
plt.plot(x, -0.5*x + 24, '-r', label="Firm 1's best response function")
# plot the second function
@mkingopng
mkingopng / meeting_game.py
Created January 5, 2022 02:44
the meeting game
import nashpy as nash
import numpy as np
row = np.array([[10, 0], [0, 0]])
column = np.array([[10, 0], [0, 0]])
meeting_game = nash.Game(row, column)
print(meeting_game)
equilibria = meeting_game.support_enumeration()
for eq in equilibria:
print(f"The unique Nash equilibrium is {eq}")
@mkingopng
mkingopng / bars_game.py
Created January 5, 2022 02:43
2 bars in competition
import nashpy as nash
import numpy as np
row = np.array([[90, 120, 120], [80, 120, 160], [100, 100, 150]])
column = np.array([[90, 80, 100], [120, 120, 100], [120, 160, 150]])
bars_v2 = nash.Game(row, column)
print(bars_v2)
equilibria = bars_v2.support_enumeration()
for eq in equilibria:
print(f"The unique Nash equilibrium is {eq}")
@mkingopng
mkingopng / prisoners_dilemma.py
Created January 5, 2022 02:41
the classic prisoner's dilemma
import nashpy as nash
import numpy as np
row = np.array([[-3, 0], [-5, -1]])
column = np.array([[-3, -5], [0, -1]])
prisoners_dilemma = nash.Game(row, column)
print(prisoners_dilemma)
equilibria = prisoners_dilemma.support_enumeration()
for eq in equilibria:
print(f"The unique Nash equilibrium is {eq}")
@mkingopng
mkingopng / quadratic_function_&_derivative.py
Created January 5, 2022 02:38
Quardratic Function & derivative
import numpy as np
from scipy.misc import derivative
import matplotlib.pyplot as plt
# define the parabola
# the quadratic function, which is y = -x^2 + 2.5x + 6 here
def function(x):
return -x ** 2 + 2.5 * x + 6
# define the parabola derivative
@mkingopng
mkingopng / mpc.py
Created November 19, 2021 01:46
mpc gist
import pandas as pd
import glob
full_month_file = open('result.txt')
directory = '../data/*.txt'
def read_mpc_txt_files():
read_files = glob.glob(directory)
with open('result.txt', 'wb') as outfile:
We can't make this file beautiful and searchable because it's too large.
recency,history,used_discount,used_bogo,zip_code,is_referral,channel,offer,conversion
10,142.44,1,0,Surburban,0,Phone,Buy One Get One,0
6,329.08,1,1,Rural,1,Web,No Offer,0
7,180.65,0,1,Surburban,1,Web,Buy One Get One,0
9,675.83,1,0,Rural,1,Web,Discount,0
2,45.34,1,0,Urban,0,Web,Buy One Get One,0
6,134.83,0,1,Surburban,0,Phone,Buy One Get One,1
9,280.2,1,0,Surburban,1,Phone,Buy One Get One,0
9,46.42,0,1,Urban,0,Phone,Buy One Get One,0
9,675.07,1,1,Rural,1,Phone,Discount,0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.