Re: "scale" numbers?
- From: The Qurqirish Dragon <qurqirishd@xxxxxxx>
- Date: Sat, 24 May 2008 07:38:53 -0700 (PDT)
On May 24, 8:37 am, "saneman" <a...@xxxxxx> wrote:
Assume that:
v = 1,...n
is a vector containing n real numbers.
Is there some procedure to "scale" all the numbers to lie in the range
[a;b]?
v = 1 2 3 4 5 6 7 8 9 10 11 12;
a = 1;
b = 8;
max_elm = max(v);
s = solve(max_elm/x = b);
frac = 1/s;
v_scaled = (v.*frac)+1
but the result is:
2 2 3 4 4 5
6 6 7 8 8 9
How is this done correctly and does it have a more formal name?
It appears you want to scale a set of integers to keep the "same"
relative values, with a smaller range?
In that case, I wouls follow this pattern:
wlog, v_1 <= v_2 <= ... <=v_n
This is just so I can say the smallest value of the given is v_1, and
the largest is v_n.
let v' be the scaled vector into [a,b], and v" be an intermediate
step.
v'_1 = a
v'_n = b
v"_k = (v_k - a) * ((b - a) / (v_n - v_1)) + a ; extra parenthesis
used to emphasize the scaling factor)
v'_k is the approximation used to convert v"_k to an integer.
Depending on the application, you may want floor, ceiling, rounding,
or integer portion. Without any other information, I would use
rounding.
Thus, for your example (v = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] ;
a=1, b=8)
v'_1 = 1
v'_12 = 8
v"_k = (v_k - 1) * (7 / 11) + 1
--> v" = [1, 18/11, 25/11, 32/11, 39/11, 46/11, 53/11, 60/11, 67/11,
74/11, 81/11, 88/11]
rounding, we get:
v' = [1, 2, 2, 3, 4, 4, 5, 5, 6, 7, 7, 8]
if you use the integer portion instead (which is the same as the
floor, since all values are positive), you get:
v' = [1, 1, 2, 2, 3, 4, 4, 5, 6, 6, 7, 8]
Note that if you don't want to restrict yourself to integers for the
scaled vector, then v" is exactly scaled, in the sense that the
relative differences of the entries are the same in each (i.e. if v_3
- v_2 is five times v_2 - v_1, then v"_3 - v"_2 will be five times
v"_2 - v"_1)
.
- References:
- "scale" numbers?
- From: saneman
- "scale" numbers?
- Prev by Date: Re: Scattered sets are G-delta
- Next by Date: Re: Scattered sets are G-delta
- Previous by thread: "scale" numbers?
- Next by thread: MURDEROUSMATHS
- Index(es):
Relevant Pages
|