0
$\begingroup$

Let $S$ be a finit set of real numbers (well not exactly "real" numbers but as "real" as it is possible by representing them by the primitive type "float" on the computer). I need to find a function

$f:\mathbb{R}\to[0,1], f(s)\in[0,1],s\in S$

such that:

$\sum_{s\in S}f(s)=1$

Ist there a straightforward way to achieve this?


Edit:

Since my question was ambiguous I'll try to explain my problem respecting more details.

I have an an algorithm, that works this way:

  1. Given is a list of objects $L$ and an integer $k$, where $k=|L|$.
  2. For each label $l\in L$ the algorithm computes $k$ real numbers. The numbers are the elements of the $S$ mentioned above.

I want to normalize the output data (the dataset $S$ produced by the algorithm). An example would be an output $S=\{a_1,\dots ,a_i\}$ where $a_k\in\mathbb{R}$ for $1\leq i\leq k$.

After the normalization the data should satisfy the conditions I mentioned above.

  1. $\sum_{i=1}^{k}a_i=1$
  2. $a_i\in [0,1]$ for each $a_i$

I hope, that the questoin is now more clear.

  • 0
    The question is not any clearer. Could you please answer my follow-up questions? (In particular, I suspect you want $f$ to be injective and possibly order-preserving even though you aren't saying this.)2011-06-16

4 Answers 4

2

Let $g(s) = \arctan s + \frac{\pi}{2}$ and let

f(s) = \frac{g(s)}{\sum_{s' \in S} g(s')}.

I think this has all the properties you could want and aren't specifying.

  • 0
    Although I was not able to provide more information (it was all the information I got), you provided the right answer. Thank you!2011-06-16
0

Maybe you want to describe the conditions on this function a little bit more? It seems like sending one of them to 1 and the rest to 0 would work.

The answer to what you probably wanted to ask is to let $A$ be the sum of all the $s \in S$ and let $ f(s) = \frac{s}{A} $

This works as long as $A$ is nonzero, which will be automatically true if, for example, the $s$ are positive.

  • 0
    @Aufwind: okay, so how about $f(s) = \frac{s^2}{A}$ where $A$ is the sum of the squares of the $s$? Again, you haven't provided enough information for me to tell if that's the kind of thing you want or not.2011-06-16
0

Define $l_\min$ to be the minimum value in the set $L$, and then

f(l) = \frac{l - l_\min}{\sum_{l'\in L} (l' - l_\min)}

This is linear and order-preserving, it's fast to compute, all of the $f(l)$ lie in [0, 1] and they sum to one.

  • 0
    It's not clear to me whether the OP wants translation-invariance or not.2011-06-16
0

The two options are:

  • Add a constant (like the negative of minimum of those numbers) and normalize as usual for positive numbers.

  • Transform from $(-\infty, \infty)$ to $[0, \infty]$ with a function like, say exponentiation, or arctan, and normalize as usual.