Last active
July 27, 2018 15:22
-
-
Save Vayel/13393f5f21f4f4a6012ae85dfc09e53a to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import random | |
| # A stochastic model with a single input `p` and a single output `side` | |
| # `p` is the probability of throwing tail | |
| # `side` is either 'head' or 'tail' | |
| def coin_model(p, seed=None): | |
| random.seed(seed) | |
| # Mathematically, `side_output` is a discrete random variable | |
| # with a Bernoulli distribution B(p) (1 being 'tail' and 0 'head') | |
| def side_output(): | |
| return 'tail' if random.random() < p else 'head' | |
| return side_output | |
| if __name__ == '__main__': | |
| setup_model = coin_model(0.7, seed=123) | |
| runs = 5 | |
| for _ in range(runs): | |
| print(setup_model()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment