sampling¶
UniformSphereSurfaceSampler¶
-
class
morgana.sampling.
UniformSphereSurfaceSampler
(centre, radius)[source]¶ Bases:
torch.distributions.distribution.Distribution
Samples points uniformly on an n-dimensional sphere’s surface.
Notes
This is the same sampling procedure used by the von Mises-Fisher distribution for \(\kappa = 0\). von Mises-Fisher distribution
UniformEllipsoidSurfaceApproximateSampler¶
-
class
morgana.sampling.
UniformEllipsoidSurfaceApproximateSampler
(centre, radii)[source]¶ Bases:
torch.distributions.distribution.Distribution
Samples points ~uniformly on an n-dimensional ellipse’s surface.
Notes
This is not a fair sampler, at the poles (especially for dimensions with large radii) samples will be denser.
-
sample_angles
(self, shape)[source]¶ Samples angles from n-1 uniform distributions.
One of these angles is in the range [0, 2*pi] and it determines tha angle in the first two dimensions. The remaining n-2 angles are in the range [0, pi] and determine the angle in the remaining dimensions.
-
rsample
(self, sample_shape=torch.Size([]))[source]¶ Computes the transformation for each cartesian dimension
n
.\[ \begin{align}\begin{aligned}x_1 &= r_1 * \cos( \theta_1 )\\x_2 &= r_2 * \sin( \theta_1 ) * \cos( \theta_2 )\\x_3 &= r_3 * \sin( \theta_1 ) * \sin( \theta_2 ) * \cos( \theta_3 )\\...\\x_{n-2} &= r_{n-2} * \sin( \theta_1 ) * \sin( \theta_2 ) * ... * \sin( \theta_{n-3} ) * \cos( \theta_{n-2} )\\x_{n-1} &= r_{n-1} * \sin( \theta_1 ) * \sin( \theta_2 ) * ... * \sin( \theta_{n-2} ) * \cos( \theta_{n-1} )\\x_n &= r_{n} * \sin( \theta_1 ) * \sin( \theta_2 ) * ... * \sin( \theta_{n-1} )\end{aligned}\end{align} \]Note the first dimension \(x_1\) does not use \(\sin\), and the final dimension \(x_n\) does not use \(\cos\).
This is equivalent to,
\[ \begin{align}\begin{aligned}\mathtt{cumprod\_sin}_1 &= 1.\\\mathtt{cumprod\_sin}_n &= \prod_{i=1}^n \sin( \theta_i )\\\begin{split}\\\end{split}\\\mathtt{cos}_n &= \cos( \theta_n )\\\mathtt{cos}_N &= 1.\\\begin{split}\\\end{split}\\x_n &= r_n * \mathtt{cumprod\_sin}_n * \mathtt{cos}_n\end{aligned}\end{align} \]
-