Say we have an interval \([a, b]\) and we want to evenly spread \(n\) numbers in this interval, however \(m\) of these \(n\) numbers have been chosen beforehand, so we have to fithe the other \(n - m\) in around them the best we can. Our goal is to maximize the minimum distance between adjacent elements.
SpreadSpecific(interval, specific, n, log = FALSE)
A length 2 numeric vector. The real interval over which one wants to spread the numbers.
A numeric vector. The specific numbers that one wants to be part of our spread.
A number. The total number of numbers that you want to be in the
spread (including the number(s) in specific
).
Measure the difference between adjacent elements as the difference in their log instead?
A numeric vector. The chosen \(n\) numbers.
The idea is to, for an interval of size \(s\), put in \(floor(s / (n - m))\) numbers into each of these intervals. Then, if there any numbers left over, put exactly one into each of the intervals with the biggest \((s / (n - m)) - `floor`(s / (n - m))\) (starting with the biggest and working one's way down) until there are no numbers left to assign. The end intervals need special treatment since (assuming the ends are not in the specific numbers), the end intervals are open on one side (one boundary has no point on it), whereas all the middle intervals are not.
# NOT RUN {
SpreadSpecific(c(0, 10), 1, 3)
# }
Run the code above in your browser using DataLab