Ich sehe mir an, wie sich der erwartete minimale euklidische Abstand zwischen zufällig einheitlichen Punkten und dem Ursprung ändert, wenn wir die Dichte zufälliger Punkte ( Punkte pro Quadrateinheit ) um den Ursprung erhöhen . Ich habe es geschafft, eine Beziehung zwischen den beiden als solche zu finden:
Ich kam darauf, indem ich einige Monte-Carlo-Simulationen in R ausführte und eine Kurve manuell anpasste (Code unten).
Meine Frage ist : Hätte ich dieses Ergebnis eher theoretisch als experimentell ableiten können?
#Stack Overflow example
library(magrittr)
library(ggplot2)
#---------
#FUNCTIONS
#---------
#gen random points within a given radius and given density
gen_circle_points <- function(radius, density) {
#round radius up then generate points in square with side length = 2*radius
c_radius <- ceiling(radius)
coords <- data.frame(
x = runif((2 * c_radius) ^ 2 * density, -c_radius, c_radius),
y = runif((2 * c_radius) ^ 2 * density, -c_radius, c_radius)
)
return(coords[sqrt(coords$x ^ 2 + coords$y ^ 2) <= radius, ])#filter in circle
}
#Example plot
plot(gen_circle_points(radius = 1,density = 200)) #200 points around origin
points(0,0, col="red",pch=19) #colour origin
#return euclidean distances of points generated by gen_circle_points()
calculate_distances <- function(circle_points) {
return(sqrt(circle_points$x ^ 2 + circle_points$y ^ 2))
}
#find the smallest distance from output of calculate_distances()
calculate_min_value <- function(distances) {
return(min(distances))
}
#Try a range of values
density_values <- c(1:100)
expected_min_from_density <- sapply(density_values, function(density) {
#simulate each density value 1000 times and take an average as estimate for
#expected minimum distance
sapply(1:1000, function(i) {
gen_circle_points(radius=1, density=density) %>%
calculate_distances() %>%
calculate_min_value()
}) %>% mean()
})
results <- data.frame(density_values, expected_min_from_density)
#fit based off exploration
theoretical_fit <- data.frame(density = density_values,
fit = 1 / (sqrt(density_values) * 2))
#plot monte carlo (black) and fit (red dashed)
ggplot(results, aes(x = density_values, y = expected_min_from_density)) +
geom_line() +
geom_line(
data = theoretical_fit,
aes(x = density, y = fit),
color = "red",
linetype = 2
)