Mercurial > hg > python
annotate distr_1.py @ 40:f13017bb4502
works on markup with -v ecclerig...
author | Henry S. Thompson <ht@inf.ed.ac.uk> |
---|---|
date | Mon, 03 Jan 2022 19:19:20 +0000 |
parents | 6c389c0f1b40 |
children |
rev | line source |
---|---|
27
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
1 #!/usr/bin/python3 |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
2 '''Display a bell curve for a fake normal distribution''' |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
3 # experimenting with normal distributions of coin flips |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
4 # Usage: distr.py Nexprs Mflips [differentN] |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
5 # Requires python3.6 as of 2021-07-28 |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
6 import sys, random, signif |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
7 from nltk import FreqDist |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
8 |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
9 n=int(sys.argv[1]) |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
10 m=int(sys.argv[2]) |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
11 if len(sys.argv)>3: |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
12 nn=int(sys.argv[3]) |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
13 else: |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
14 nn=None |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
15 fd=FreqDist() |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
16 for i in range(n): |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
17 fd[sum(random.randint(0,1) for i in range(m))]+=1 |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
18 |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
19 if nn is not None: |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
20 fd2=FreqDist() |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
21 for i in range(nn): |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
22 fd2[sum(random.randint(0,1) for i in range(m))]+=1 |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
23 |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
24 fd.bell(xtra=fd2) |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
25 else: |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
26 fd.bell() |
6c389c0f1b40
first half of old /c/Drive_F/merged_d/src/python/distr.py
Henry S. Thompson <ht@inf.ed.ac.uk>
parents:
diff
changeset
|
27 |