-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexercise1.py
More file actions
31 lines (25 loc) · 822 Bytes
/
exercise1.py
File metadata and controls
31 lines (25 loc) · 822 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
'''
Exercise: Write a script (say in Python, or some other language)
that selects 400 points uniformly at random (or approximately uniformly at random)
from the annulus {(x,y)|0.952≤x^2+y^2≤1.052} in R2.
Compute its persistent homology barcodes using Ripser.
'''
import random
import math
# Return the next random floating-point number in the range 0.0 <= X < 1.0
def get_annulus_points():
random.seed(10)
r = random.uniform(math.sqrt(0.952), math.sqrt(1.052))
theta = random.uniform(0,360)
x = r * math.cos(theta)
y = r * math.sin(theta)
return (x,y)
def test(points):
result = points[0]**2+points[1]**2
return ((0.952 <= result) & (result <= 1.052))
def main():
points = get_annulus_points()
print(points)
print(test(points))
if __name__ == "__main__":
main()