Skip to content

Instantly share code, notes, and snippets.

@Vayel
Last active July 27, 2018 15:22
Show Gist options
  • Select an option

  • Save Vayel/13393f5f21f4f4a6012ae85dfc09e53a to your computer and use it in GitHub Desktop.

Select an option

Save Vayel/13393f5f21f4f4a6012ae85dfc09e53a to your computer and use it in GitHub Desktop.

Revisions

  1. Vayel revised this gist Jul 27, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions coin_model.py
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@
    # `p` is the probability of throwing tail
    # `side` is either 'head' or 'tail'
    def coin_model(p, seed=None):
    # The seeds allows us to control randomness and ensure reproducibility
    # The seed allows us to control randomness and ensure reproducibility
    random.seed(seed)

    # Mathematically, `side_output` is a discrete random variable
    @@ -13,7 +13,7 @@ def coin_model(p, seed=None):
    return side_output

    if __name__ == '__main__':
    setup_model = coin_model(0.7, seed=123)
    coin = coin_model(0.7, seed=123)
    runs = 5
    for _ in range(runs):
    print(setup_model())
    print(coin())
  2. Vayel revised this gist Jul 23, 2018. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion coin_model.py
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ 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')
    # with a Bernoulli distribution B(p) (1 is 'tail' and 0 is 'head')
    side_output = lambda: 'tail' if random.random() < p else 'head'
    return side_output

  3. Vayel revised this gist Jul 23, 2018. 1 changed file with 1 addition and 2 deletions.
    3 changes: 1 addition & 2 deletions coin_model.py
    Original file line number Diff line number Diff line change
    @@ -9,8 +9,7 @@ def coin_model(p, seed=None):

    # 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'
    side_output = lambda: 'tail' if random.random() < p else 'head'
    return side_output

    if __name__ == '__main__':
  4. Vayel revised this gist Jul 23, 2018. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions coin_model.py
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,9 @@
    # `p` is the probability of throwing tail
    # `side` is either 'head' or 'tail'
    def coin_model(p, seed=None):
    # The seeds allows us to control randomness and ensure reproducibility
    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():
  5. Vayel revised this gist Jul 23, 2018. 1 changed file with 6 additions and 3 deletions.
    9 changes: 6 additions & 3 deletions coin_model.py
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,18 @@
    import random

    # A stochastic model with a single input `p` and a single output `side`
    def coin_model(p):
    # `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)
    # 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)
    setup_model = coin_model(0.7, seed=123)
    runs = 5
    for _ in range(runs):
    print(setup_model())
  6. Vayel revised this gist Jul 19, 2018. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion coin_model.py
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,8 @@

    # A stochastic model with a single input `p` and a single output `side`
    def coin_model(p):
    # Mathematically, `side_output` is a random variable
    # Mathematically, `side_output` is a discrete random variable
    # with a Bernoulli distribution B(p)
    def side_output():
    return 'tail' if random.random() < p else 'head'
    return side_output
  7. Vayel renamed this gist Jul 19, 2018. 1 changed file with 4 additions and 3 deletions.
    7 changes: 4 additions & 3 deletions coin_abm.py → coin_model.py
    Original file line number Diff line number Diff line change
    @@ -1,13 +1,14 @@
    import random

    def coin_abm(p):
    # A stochastic model with a single input `p` and a single output `side`
    def coin_model(p):
    # Mathematically, `side_output` is a random variable
    def side_output():
    return 'tail' if random.random() < p else 'head'
    return side_output

    if __name__ == '__main__':
    configured_coin_abm = coin_abm(0.7)
    setup_model = coin_model(0.7)
    runs = 5
    for _ in range(runs):
    print(configured_coin_abm())
    print(setup_model())
  8. Vayel revised this gist Jul 19, 2018. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions coin_abm.py
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,7 @@
    import random

    def coin_abm(p):
    # Mathematically, `side_output` is a random variable
    def side_output():
    return 'tail' if random.random() < p else 'head'
    return side_output
  9. Vayel revised this gist Jul 19, 2018. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions coin_abm.py
    Original file line number Diff line number Diff line change
    @@ -2,11 +2,11 @@

    def coin_abm(p):
    def side_output():
    return 'tail' if random.rand() < p else 'head'
    return 'tail' if random.random() < p else 'head'
    return side_output

    if __name__ == '__main__':
    configured_coin_abm = coin_abm(0.8)
    print(configured_coin_abm())
    print(configured_coin_abm())
    print(configured_coin_abm())
    configured_coin_abm = coin_abm(0.7)
    runs = 5
    for _ in range(runs):
    print(configured_coin_abm())
  10. Vayel created this gist Jul 19, 2018.
    12 changes: 12 additions & 0 deletions coin_abm.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,12 @@
    import random

    def coin_abm(p):
    def side_output():
    return 'tail' if random.rand() < p else 'head'
    return side_output

    if __name__ == '__main__':
    configured_coin_abm = coin_abm(0.8)
    print(configured_coin_abm())
    print(configured_coin_abm())
    print(configured_coin_abm())