Closed emhart closed 9 years ago
Hi @emhart:
Good catch! As you note, the difference should be exponentiated to get it back into ratio form. However, we do not want to use the reverse sort. In this literature, the ratio is always calculated as
size_ratio(ab) = larger(a)/(next larger(b))
For your example, the smallest ratio is 6/5, and the correct answer is 1.2, not 0.1823. So the correct code should be:
min_ratio3 <- function(m=runif(20)) {
m <- sort(log(m))
mr <- exp(min(diff)))
return(mr)
}
Thus, it is the exponentiated value of my original log difference that we want, based on an increasing order for the sort. I guess the wording is a bit ambiguous about how the ratio should be calculated for adjacent ordered values. I will change the code and adjust the wording to say "minimum size ratio difference between adjacent, ordered values (larger/next larger)".
@ngotelli I was working on tests, and I'm not sure I understand the logic behind
min_ratio()
.Here's a sequence:
So on it's face I'd expect the minimum ratio to be 2/3 ~= 0.66667
But
min_ratio()
gives 0.1823 Which is strange because looking at the code it seems that you would want to exponentiate to get the ratio in non-log terms. When I do that, I get 1.2 (which is 6/5). So the reason we get that is because when diff is working on a sorted vector of a,b,c, it takes b - a and c - b. Is that what you want? e.g.Just ask because based on the description you wrote of the function I would write it as:
This gives me what I think of as: "the minimum size ratio difference between adjacent, ordered values".
I just came across this while I was writing tests and need to get back the expected values from a known vector.