Re: "scale" numbers?



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)
.



Relevant Pages

  • Re: OT: Determining the size of plotting area
    ... rounding has come up here more than once, ... I don't recall the routines as being much more than half a dozen ... (Sometimes one wants to force zero to be ... included in the scale; other times one doesn't). ...
    (comp.lang.fortran)
  • Re: Rounding
    ... Subtracting 0.0049 and then casting to DECIMAL with a scale of 2 will ... effectively truncate the third digit to the right of the decimal point: ... > All of the functions that I have tested, with regards to rounding, round ...
    (microsoft.public.sqlserver.programming)
  • Re: floats, doubles and maths
    ... Patricia Shanahan writes: ... choice for financial calculations that need two decimal place rounding ... is java.math.BigDecimal, with scale factor 2. ...
    (comp.lang.java.help)
  • Re: rounding
    ... Rounding .5625 to two places should result in .57 and rounding 6.125 to two places should result in 6.13, ... double RoundToMultiple(double num, double multiple) ... return Math.Round(num * scale) / scale; ... Note that if you pick something that is theoretically divisible into 1.0, but which is not representable in binary, you may wind up wind rounding error. ...
    (microsoft.public.dotnet.languages.csharp)