probability_demo_2D

library(ashapesampler)

This document illustrates how to sample α-shapes from a true probability distribution in two dimensions. The main function within the package to do this is sampling2Dashape, which generates α-shapes given the parameters.

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:

α ∼ TN(μ = 0.25, σ = 0.5, a = min (0.1, τ/4), b = τ/2) n|α = nmin(α, δ = 0.05) $$x_1, ..., x_n \stackrel{i.i.d.}{\sim} \text{Unif}(\mathcal{M}) $$

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 sampling2Dashape function returns a list of length N of those objects.

set.seed(100001)
my_ashape = sampling2Dashape(N=1)
plot(my_ashape[[1]])

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:

To make the code dynamic, set n.noise = TRUE. This code is where λ = 3.

my_ashape = sampling2Dashape(N=1, n.noise = TRUE)
plot(my_ashape[[1]])

Code with the adjustment λ = 10:

my_ashape = sampling2Dashape(N=1, n.noise = TRUE, lambda = 10)
plot(my_ashape[[1]])

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 = sampling2Dashape(N=1, n.dependent=FALSE, n.noise=TRUE, lambda = 5)
plot(my_ashape[[1]])

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 = sampling2Dashape(N=1, nhomology = TRUE)
#> Warning in sampling2Dashape(N = 1, nhomology = TRUE): Both nhomology and
#> nconnect are true, default to nhomology for choosing n.
plot(my_ashape[[1]])

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 = sampling2Dashape(N=1, r=0.5)
#> Warning in sampling2Dashape(N = 1, r = 0.5): Mean of alpha outside of truncated
#> distribution range for alpha
my_alpha = my_ashape[[1]]$alpha

plot(my_ashape[[1]])

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 circle and the annulus. To sample points from a circle, we set bound="circle". Default radius is r = 1, but we can adjust that as with the square. To sample α-shapes with points from the interior of the unit circle, use the following code:

my_ashape = sampling2Dashape(N=1, bound="circle")
plot(my_ashape[[1]])

For the annulus, 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 annulus with inner radius rmin=0.5 and r=0.75.

my_ashape = sampling2Dashape(N=1, r=0.75, rmin=0.5, bound="annulus")
plot(my_ashape[[1]])

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 circle:

my_ashape = sampling2Dashape(N=1, afixed = TRUE, alpha=0.2, bound="circle")
plot(my_ashape[[1]])

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 = sampling2Dashape(N=1, mu=0.2, sigma = 0.1)
plot(my_ashape[[1]])

If afixed=TRUE, even if values of mean mu and standard deviation sigma are input, they are ignored.