diff options
author | Arun Isaac | 2021-03-31 14:49:21 +0530 |
---|---|---|
committer | Arun Isaac | 2021-03-31 14:51:51 +0530 |
commit | 06c60f361fe9a96cb73ee2ae32de13f5c324ae16 (patch) | |
tree | 1ab6ff025b74b38b268cddc9436ed11f49ec01d9 | |
parent | 82e25e86ca4c8fa0d4441a360330af0dda715c8a (diff) | |
download | sambal-06c60f361fe9a96cb73ee2ae32de13f5c324ae16.tar.gz sambal-06c60f361fe9a96cb73ee2ae32de13f5c324ae16.tar.lz sambal-06c60f361fe9a96cb73ee2ae32de13f5c324ae16.zip |
Document usage information in README.
* README.md (Usage): New section.
-rw-r--r-- | README.md | 52 |
1 files changed, 52 insertions, 0 deletions
@@ -4,3 +4,55 @@ sambal provides functions to - uniformly sample a sphere - uniformly sample a spherical cap of a sphere + +# Usage + +## Random vector on sphere + +Generate a random vector on a 100-dimensional unit sphere. +```python +import numpy as np +from sambal import random_on_sphere + +dim = 100 +print(random_on_sphere(dim)) +``` + +The same as above, but with a random number generator seeded to 0. +```python +import numpy as np +from sambal import random_on_sphere + +dim = 100 +rng = np.random.default_rng(0) +print(random_on_sphere(dim, rng)) +``` + +## Random vector on spherical cap + +Generate a 100-dimensional random vector on a spherical cap whose +central axis is `[1, 1, 1, ..., 1] / sqrt(100)` and whose maximum +planar angle is `pi/3`. +```python +import numpy as np +from sambal import random_on_cap + +dim = 100 +axis = np.ones(dim) +axis = axis / np.linalg.norm(axis) +max_planar_angle = np.pi/3 +print(random_on_cap(axis, max_planar_angle)) +``` + +The same as above, but with a random number generator seeded to 0. +```python +import numpy as np +from sambal import random_on_cap + +rng = np.random.default_rng(0) +dim = 100 +axis = np.ones(dim) +axis = axis / np.linalg.norm(axis) +max_planar_angle = np.pi/3 +print(random_on_cap(axis, max_planar_angle, rng)) +``` |