Bringing numbers in a set closer together

1.8k Views Asked by At

I'm trying to express the relative scale of items compared to an "average" scale for all items in the set. This produces values like { 0.5, 1.8, 0.3, 1.2 ... }

I then wish to use this number to visually transform the items so that items that had a smaller relative scale grow somewhat and larger items shrink. Something along the lines of new_size = old_size / scale.

However, this produces too extreme of a transformation. I need to "dampen" this scale value by a controllable amount. So scales < 1.0 would get bigger (but not exceed 1.0) and scales > 1.0 would get smaller (but not be less than 1.0), and an item whose relative scale was 1.0 would remain 1.0.

There must be an easy way to do this, but my math skills are insufficient to the task.

If possible, please express your answer in algorithmic form, since this will be incorporated into a software solution.

2

There are 2 best solutions below

3
On BEST ANSWER

You can compute the average of all your numbers, call it $A$. Then given a number $x$ you can adjust its distance from $A$ by scale factor $s$, so $x \to A+s(x-A)$ If you let $s=\frac 23$ the distance from the average will shrink to $\frac 23$ of its previous value. The average will not change.

3
On

Boy, this was simpler than I thought.

m = ( ( n - 1 ) / d ) + 1;

where 'd' here is the "dampening amount". My mistake was not seeing that "1" was just my offset from 0. Everything works when the offset is 0, so we shift the number down by the offset and then after the dampening transformation, shift it back up.

Am I missing something?