Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SimonEnsemble/f7a010d221196a57dc63f2af56b279d4 to your computer and use it in GitHub Desktop.
Save SimonEnsemble/f7a010d221196a57dc63f2af56b279d4 to your computer and use it in GitHub Desktop.
an orange peel in high dimensions: what fraction of the volume does the peel comprise?
using LinearAlgebra
"""
sample a uniform random point inside a unit orange centered at the origin.
* `d::Int`: dimension of the space
"""
function random_point_inside_unit_orange(d::Int)
x = 2 * (rand(d) .- 0.5)
if norm(x) < 1.0
return x
else
return random_point_inside_unit_orange(d)
end
end
"""
via MC sim, determine the fraction of a unit orange that comprises the peel.
* `δr::Float64`: thickness of the peel
* `d::Int`: dimension of the space
* `nb_samples::Int`: # of MC samples
"""
function fraction_peel(δr::Float64, d::Int;
nb_samples::Int=10000)
nb_points_in_peel = 0
for s = 1:nb_samples
x = random_point_inside_unit_orange(d)
if norm(x) > 1.0 - δr
nb_points_in_peel += 1
end
end
return nb_points_in_peel / nb_samples
end
fraction_peel(0.1, 3) # 0.26
fraction_peel(0.1, 10) # 0.65
fraction_peel(0.1, 15) # =-O stack overflow, too many rejections in `random_point_inside_unit_orange`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment