# start with 3 points
# calculate their mid point, assumming normal distribution
start_init <- 10
mid_init <- 20
end_init <- 50
start <- start_init
end <- mid_init
mid_1 <- mean(c(start,end))
start <- mid_init
end <- end_init
mid_2 <- mean(c(start,end))
# now we have 3 points
c(start_init, mid_1, mid_init, mid_2, end_init)
# further calculate the mid points between
start <- start_init
end <- mid_1
mid_1_1 <- mean(c(start,end))
start <- mid_1
end <- mid_init
mid_1_2 <- mean(c(start,end))
start <- mid_init
end <- mid_2
mid_2_1 <- mean(c(start,end))
start <- mid_2
end <- end_init
mid_2_2 <- mean(c(start,end))
# now we have 9 data points
res <- c(start_init, mid_1_1 ,mid_1, mid_1_2, mid_init, mid_2_1, mid_2, mid_2_2, end_init)
我想压缩上面的代码,这样递归深度就可以被定义。
例如,当深度等于1时,我们需要为所有可用的连续点的组合生成1个新点。
如上例所示,我们从3个点(A,B,C)开始,因此当深度等于1时,我们最多会有2个额外的新点,即在A和B之间以及B和C之间。