aboutsummaryrefslogtreecommitdiff
path: root/README.md
blob: cb1f48553c5305e62b30817cfd42797a21c6a868 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# sambal

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))
```

# Citing

If you use this code for your research, please cite the paper [An O(n)
algorithm for generating uniform random vectors in n-dimensional
cones](https://arxiv.org/abs/2101.00936).