1
$\begingroup$

I have a list of positive numbers given.

By dividing each element by the sum of all elements, I receive a normalized result between 0 and 1 while keep the weights:

before [12, 12, 0, 0, 0] -> after [12/24, 12/24, 0, 0, 0] = [0.5, 0.5, 0, 0, 0]

However, I want to normalize the result between 0.5 and 1 rather than 0 and 1.

Desired result:

[12, 12, 0, 0, 0] -> [0.75, 0.75, 0.5, 0.5, 0.5]

[12, 0, 0, 0, 0] -> [1, 0.5, 0.5, 0.5, 0.5]

How can this be achieved?

$\endgroup$
3
  • $\begingroup$ Can you elaborate on your first example, why $0.75$, can I map $12$ to $1$? $\endgroup$ Commented Jan 19, 2022 at 4:47
  • $\begingroup$ I want to normalize on the sum on one hand (so 12 -> 0.5 because the sum is 24). But on the other hand I want to have a min value of 0.5. So the result of 12 -> 0.5 turns into 0.75 because 0.75 is in the middle of [0.5, 1], just as 0.5 was in the middle of [0, 1]. $\endgroup$
    – TeaCup
    Commented Jan 19, 2022 at 8:27
  • 1
    $\begingroup$ So do your original calculations, halve the results and then add $0.5$. It will not be directly meaningful $\endgroup$
    – Henry
    Commented Jan 19, 2022 at 12:38

1 Answer 1

1
$\begingroup$

Let the smallest element be $m$ and let the sum be $M$.

We want to map $m$ to $0.5$ and $M$ to $1$. View it as you are trying to interpolate $(m, 0.5)$ and $(M, 1)$.

We have

$$\frac{y-1}{x-M}=\frac{0.5}{M-m}$$

$$y = 1 + 0.5\cdot \frac{x-M}{M-m}=\frac{x}{2(M-m)} + 1-\frac{M}{2(M-m)}=1-\frac{M-x}{2(M-m)}$$

For example, for your first vector, $m=0, M=24$.

Then $0$ is being mapped to $1-\frac{24}{2(24)}=0.5$ and $12$ is being mapped to $1-\frac{24-12}{2(24)}=0.75$.

For the second vector $m=0, M=12$,

Then $0$ is being mapped to $1-\frac{12}{2(12)}=0.5$ and $12$ is being mapped to $1-\frac{12-12}{2(12-0)}=1$.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .