Created
May 19, 2013 13:54
-
-
Save kdungs/5607711 to your computer and use it in GitHub Desktop.
Analysis of the relation between eaten candies and HP gain in "Candy box!" (http://candies.aniwey.net/).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.stats import linregress | |
# Set nice options for plots and use of LaTeX. | |
from matplotlib import rc | |
rc('text', usetex=True) | |
rc('font', family='serif') | |
rc('font', serif='Tex Gyre Pagella') | |
# load data | |
candies, hp_gains = np.loadtxt('candies_hps.txt', unpack=True) | |
# fit (linear regression on loglog) | |
log_candies = np.log(candies) | |
log_hp_gains = np.log(hp_gains) | |
slope, intercept, _, _, stderr = linregress(log_candies, log_hp_gains) | |
# define model | |
a = np.exp(intercept) | |
b = slope | |
model = lambda x: a * x ** b | |
# plot everything | |
plt.plot(candies, hp_gains, 'ko', label='measurement') | |
xs = np.linspace(0, np.max(candies), 10000) | |
plt.plot( | |
xs, | |
model(xs), | |
'r-', | |
label='$\\Delta(n) = {:.3f}\\cdot n^{{{:.3f}}}$'.format(a, b) | |
) | |
plt.legend(loc='upper left') | |
plt.xlabel('number of candies eaten $n$', ha='right', x=1) | |
plt.ylabel('absolute HP gain $\\Delta$', va='top', y=1) | |
plt.savefig('candies_hps.pdf') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# candies hpGain | |
100 13 | |
2035 44 | |
2514 48 | |
2727 49 | |
3140 52 | |
3504 54 | |
4068 58 | |
4653 61 | |
5001 63 | |
5737 66 | |
7538 74 | |
8625 78 | |
10871 86 | |
12303 90 | |
15814 100 | |
18996 108 | |
22055 114 | |
24904 120 | |
26144 122 | |
28353 126 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment