Документация Engee

Sampling

Страница в процессе перевода.

sample([rng], object, method)

Sample elements or points from geometric object with method. Optionally, specify random number generator rng.

SamplingMethod

A method for sampling from geometric objects.

DiscreteSamplingMethod

A method for sampling from discrete representations of geometric objects such as meshes or collections of geometries.

ContinuousSamplingMethod

A method for sampling from continuous representations of geometric objects. In this case, geometric objects are interpreted as a set of points in the embedding space.

Discrete sampling

UniformSampling

UniformSampling(size, replace=false, ordered=false)

Sample elements uniformly from a given domain/data. Produce a sample of given size with or without replacement depending on the replace option. The option ordered can be used to return samples in the same order of the domain/data.

grid = CartesianGrid(20, 20)

# uniform sampling without replacement
sampler = UniformSampling(100, replace=false)
blocks  = sample(grid, sampler)

viz(blocks)
AweN4IWszLkFAAAAAElFTkSuQmCC

WeightedSampling

WeightedSampling(size, [weights]; replace=false, ordered=false)

Sample elements from a given domain/data using weights. Produce a sample of given size with or without replacement depending on the replace option. The option ordered can be used to return samples in the same order of the original domain/data. By default weights are uniform.

grid = CartesianGrid(20, 20)

# upper blocks are 10x more likely
weights = [fill(1, 200); fill(10, 200)]

# weighted sampling without replacement
sampler = WeightedSampling(100, weights, replace=false)
blocks  = sample(grid, sampler)

viz(blocks)
QAAAABJRU5ErkJggg==

BallSampling

BallSampling(radius; [options])

A method for sampling isolated elements from a given domain/data according to a norm-ball of given radius.

Options

  • metric - Metric for the ball (default to Euclidean())

  • maxsize - Maximum size of the resulting sample (default to none)

grid = CartesianGrid(20, 20)

# sample blocks that are apart by a given radius
sampler = BallSampling(5.0)
blocks  = sample(grid, sampler)

viz(blocks)
G6nXJd0kojsAAAAASUVORK5CYII=

Continuous sampling

RegularSampling

RegularSampling(n1, n2, ..., np)

Generate samples regularly using n1 points along the first parametric dimension, n2 points along the second parametric dimension, …​, np points along the last parametric dimension.

Examples

Sample sphere regularly with 360 longitudes and 180 latitudes:

sample(Sphere((0,0,0), 1), RegularSampling(360, 180))
grid = CartesianGrid(20, 20)

# sample points regularly
sampler = RegularSampling(20, 30)
points  = sample(grid, sampler) |> collect

viz(points)
+539+J5XnzjvvzLuEeOTIkQcffHDv3r1+v7+urm779u133nlnW1vbeQurDhRCAAAAAAAAjcKiMgAAAAAAABqFQggAAAAAAKBRKIQAAAAAAAAahUIIAAAAAACgUSiEAAAAAAAAGoVCCAAAAAAAoFEohAAAAAAAABqFQggAAAAAAKBRKIQAAAAAAAAahUIIAAAAAACgUSiEAAAAAAAAGoVCCAAAAAAAoFEohAAAAAAAABqFQggAAAAAAKBRKIQAAAAAAAAahUIIAAAAAACgUSiEAAAAAAAAGoVCCAAAAAAAoFEohAAAAAAAABqFQggAAAAAAKBRKIQAAAAAAAAahUIIAAAAAACgUSiEAAAAAAAAGoVCCAAAAAAAoFEohAAAAAAAABqFQggAAAAAAKBRKIQAAAAAAAAahUIIAAAAAACgUSiEAAAAAAAAGoVCCAAAAAAAoFEohAAAAAAAABqFQggAAAAAAKBRKIQAAAAAAAAahUIIAAAAAACgUf8HmuuxddBLAogAAAAASUVORK5CYII=

HomogeneousSampling

HomogeneousSampling(size, [weights])

Generate sample of given size from geometric object according to a homogeneous density. Optionally, provide weights to specify custom sampling weights for the elements of a domain.

grid = CartesianGrid(20, 20)

# sample points homogeneously
sampler = HomogeneousSampling(100)
points  = sample(grid, sampler) |> collect

viz(points)
LLZ7E033XQ8teh973vfIacQS2BsVwgBAABiyk1lAAAAYkohBAAAiCmFEAAAIKYUQgAAgJhSCAEAAGJKIQQAAIgphRAAACCmFEIAAICYUggBAABiSiEEAACIKYUQAAAgphRCAACAmFIIAQAAYkohBAAAiCmFEAAAIKYUQgAAgJhSCAEAAGJKIQQAAIgphRAAACCmFEIAAICYUggBAABiSiEEAACIKYUQAAAgphRCAACAmFIIAQAAYkohBAAAiCmFEAAAIKYUQgAAgJhSCAEAAGJKIQQAAIgphRAAACCmFEIAAICYUggBAABiSiEEAACIqf8fOSUWVgzOcvUAAAAASUVORK5CYII=

MinDistanceSampling

MinDistanceSampling(α, ρ=0.65, δ=100, metric=Euclidean())

Generate sample from geometric object such that all pairs of points are at least α units of distance away from each other. Optionally specify the relative radius ρ for the packing pattern, the oversampling factor δ and the metric.

This method is sometimes referred to as Poisson disk sampling or blue noise sampling in the computer graphics community.

References

grid = CartesianGrid(20, 20)

# sample points that are apart by a given radius
sampler = MinDistanceSampling(3.0)
points  = sample(grid, sampler) |> collect

viz(points)
wFD7eA71jp0twAAAABJRU5ErkJggg==

FibonacciSampling

FibonacciSampling(n, ϕ = (1 + √5)/2)

Generate n Fibonacci points with parameter ϕ.

The golden ratio is used as the default value of ϕ, but other irrational numbers can be used.

sphere = Sphere((0.,0.,0.), 1.)

# sample points using the Fibonacci lattice method
sampler  = FibonacciSampling(100)
points  = sample(sphere, sampler) |> collect

viz(points)
AV9Cmk9K9YsjAAAAAElFTkSuQmCC