hypersphere.sample: Sample uniformly from an n-hypersphere

View source: R/sample.R

hypersphere.sampleR Documentation

Sample uniformly from an n-hypersphere

Description

Generates uniform random variates over an n-hypersphere

Usage

hypersphere.sample(n, N)

Arguments

n

Dimension of the hypersphere

N

Number of samples

Value

A single n-dimensional sample from the hypersphere.

Author(s)

Tommi Tervonen <tommi@smaa.fi>

Examples

n <- 3 # Dimension
N <- 5 # Nr samples

sample <- hypersphere.sample(n, N)

# Check summing to unity
vec.norm <- function(x) { sum(x^2) }
stopifnot(all.equal(apply(sample, 1, vec.norm), rep(1, N)))

hitandrun documentation built on May 28, 2022, 1:09 a.m.