-
bold math
\mathbf{a}\bm{\alpha}// requires:\usepackage{bm} -
double line font (expectation, probability, real numbers)
\mathds{E},\mathds{P} // requires: \usepackage{dsfont}
| import sys | |
| import random | |
| SLOTS = 4 | |
| class Colors: | |
| G = 'g' # green | |
| R = 'r' # red | |
| B = 'b' # blue |
| """ | |
| Simple class that finds the stationary distribution of a | |
| Continuous Time Markov Chain with two examples | |
| """ | |
| from collections import defaultdict | |
| import numpy as np | |
| """ | |
| The following is an attempt to gather various useful usecases of | |
| collections.Counter in python. Some were once contributed to | |
| Stackoverflow Documentation Experiment but since its shut down | |
| I could not recover them. | |
| """ | |
| # imports | |
| from collections import Counter | |
| import random |
bold math
\mathbf{a}
\bm{\alpha} // requires: \usepackage{bm}
double line font (expectation, probability, real numbers)
\mathds{E},\mathds{P} // requires: \usepackage{dsfont}
| """ | |
| Generic example of experiment that compares two methods | |
| COS, SIN in two different experiments EXPERIMENT1, EXPERIMENT2 | |
| Experiments can be lengthy so one can choose to SAVE the | |
| files so that the plots can be generated again when the | |
| appropriate RUNTAG is set and the PLOT program option is chosen. | |
| """ | |
| import os | |
| import matplotlib.pyplot as plt |
| import matplotlib.pyplot as plt | |
| import numpy as np | |
| def myplot(q, t, label, color=None, mean_in_legend=False, linewidth=0.5): | |
| if mean_in_legend: | |
| mean_total_q = np.dot(t, q) / t.sum() | |
| plt.plot(t.cumsum(), q, color=color, | |
| label='{} {:.2f}'.format(label, mean_total_q), | |
| linewidth=linewidth) |
| #!/usr/bin/python | |
| """ | |
| Display the per-commit size of the current git branch. | |
| source: http://stackoverflow.com/questions/23907/how-can-i-graph-the-lines-of-code-history-for-git-repo | |
| """ | |
| import subprocess | |
| import re | |
| import sys |
| class Spellbook: | |
| def cast(self, enemy): | |
| raise NotImplementedError | |
| class SpellbookFire(Spellbook): | |
| def cast(self, enemy): | |
| print("I've lit the {} on fire.".format(enemy)) | |
| from collections import Counter | |
| class A(object): | |
| def __init__(self, name, val): | |
| self.name = name | |
| self.val = val | |
| def __repr__(self): | |
| return 'A(val={})'.format(self.val) |
| import types | |
| from functools import partial | |
| class Resource1(object): | |
| def __init__(self, value, update_strategy): | |
| self.value = value | |
| self.update = types.MethodType(update_strategy, self) | |
| class Resource2(object): |