This document illustrates how to sample α-shapes from a true probability
distribution in three dimensions. The main function within the package
to do this is sampling3Dashape
, which generates α-shapes given the parameters.
Package rgl
is needed for plotting, and plots will show in
a pop out window.
There are several ways to adjust the hierarchical distribution of the function which will be discussed throughout the document. The function requires only parameter N, the number of shapes to be sampled. All other parameters are set to default, and the function samples an α-shape from the following distribution:
α ∼ 𝒩T(μ = 0.25, σ = 0.5, a = min (0.1, τ/4), b = τ/2) n|α = ncmin(α, δ = 0.05) x1, ..., xn ∼ Unif(ℳ)
where n the number of points sampled is dependent on the number of points needed to produce a connected shape for a randomly selected α, δ is the probability that the generated shape has more than one connected component, and points are selected uniformly from some manifold ℳ. We could allow the lower bound of the truncated normal distribution of α to be as small as a = 0, however, we set it to a = min(0.1, tau/4) to prevent computational bottleneck. Bounds of the truncated normal distribution are fixed for the user. Values of τ for different underlying manifolds are as follows:
The condition number is not a user adjusted parameter.
For demonstration purposes, we set N = 1. The
sampling3Dashape
function returns a list of length N of those objects.
set.seed(100001)
my_ashape = sampling3Dashape(N=1)
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.2434609
rglwidget()
To make the number of points a random variable in and of itself, we can add a discrete distribution π to n|α. In the code, this discrete distribution is a Poisson distribution with default λ = 3. Parameter λ can be adjusted by the user. The distribution from which the new shape is sampled is then given by:
α ∼ NT(μ = 0.25, σ = 0.5, a = min (0.1, τ/4), b = τ/2) n|α = nmin(α, δ = 0.05) + Poisson(λ) $$x_1, ..., x_n \stackrel{i.i.d.}{\sim} \text{Unif}(\mathcal{M}) $$
To make the code dynamic, set n.noise = TRUE
. This code
is where λ = 3.
my_ashape = sampling3Dashape(N=1, n.noise = TRUE)
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.2092051
rglwidget()
Code with the adjustment λ = 10:
my_ashape = sampling3Dashape(N=1, n.noise = TRUE, lambda = 10)
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.231029
rglwidget()
We can also change the dependence of n relative to α. First, we can make n independent of α by setting
n.dependent = FALSE
. Then n = 20 is the default number of
points used. (If n.noise=TRUE
, then 20 is the minimum
number of points used before adding more based on a Poisson random
variable.) Making n
independent from α allows for
more variation in the resulting shapes, including the number of
connected components. Example code with independent n and noise:
my_ashape = sampling3Dashape(N=1, n.dependent=FALSE, n.noise=TRUE, lambda = 5)
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.2488231
rglwidget()
In the other direction, we can choose to make n dependent on α such that the underlying
manifold’s topology is preserved. In the case of a square, this means we
will have one connected component with no holes with probability 1 − δ. Here, it is strict that α/2 < τ, which defaults
to 1. Note that the smaller τ
is, the smaller α has to be,
the more points which must be sampled, and thus the slower the
algorithm. Users will see the variation in the shapes will lie on the
boundaries when setting nhomology=TRUE
:
my_ashape = sampling3Dashape(N=1, nhomology = TRUE)
#> Warning in sampling3Dashape(N = 1, nhomology = TRUE): Both nhomology and
#> nconnect are true, default to nhomology for choosing n.
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.1794529
rglwidget()
While the default manifold is the unit square, we can also adjust the size of the square with parameter r, which defaults to r = 1. For example, we can change the size of the square such that the length of one side is r = 0.5:
my_ashape = sampling3Dashape(N=1, r=0.5)
#> Warning in sampling3Dashape(N = 1, r = 0.5): Mean of alpha outside of truncated
#> distribution range for alpha
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.1188233
rglwidget()
We can also make the square bigger by increasing r. Note that the number of points to
meet the minimum conditions to meet thresholds for no isolated point or
maintaining the underlying homology increases as the area of the
underlying manifold increases, and thus may take longer to compute.
Other shape options include the sphere and the shell. To sample points
from a sphere, we set bound="sphere"
. Default radius is
r = 1, but we can adjust that
as with the cube. To sample α-shapes with points from the
interior of the unit sphere, use the following code:
my_ashape = sampling3Dashape(N=1, bound="sphere")
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.3469765
rglwidget()
For the shell, r represents
the outer radius while rmin = 0.25
is the inner radius. Both parameters can be adjusted but it is required
that 0 < rmin < r.
The following code demonstrates sampling an α-shape with points sampled
uniformly from the shell with inner radius rmin=0.5
and
r=0.75
.
my_ashape = sampling3Dashape(N=1, r=0.75, rmin=0.5, bound="shell")
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.1389428
rglwidget()
Finally, we can adjust the distribution for α itself. First, we can fix α to a set number for all α-shapes being sampled by setting
afixed=TRUE
. The default value of α for this function is α = 0.24 but will automatically
adjust to τ/2 − 0.001 if it is
larger than τ/2. Note that
when n.dependent=TRUE
then as α approaches 0 n will approach infinity and cause a
computational bottleneck. The following is example code for fixed α = 0.2 on the unit sphere:
my_ashape = sampling3Dashape(N=1, afixed = TRUE, alpha=0.2, bound="sphere")
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.2
rglwidget()
We can also adjust the truncated normal distribution mean μ and standard deviation σ. We recommend that μ is less than τ/2, the upper bound of the truncated normal distribution, and larger than 0. A warning will pop up if this is not the case but otherwise the code will run normally. We require σ to be larger than 0. The following code is for a distribution where μ = 0.2 and σ = 0.1:
my_ashape = sampling3Dashape(N=1, mu=0.2, sigma = 0.1)
plot(my_ashape[[1]])
#> Device 1 : alpha = 0.1927994
rglwidget()
If afixed=TRUE
, even if values of mean mu
and standard deviation sigma
are input, they are
ignored.