开发者

Algorithm for logarithmically converting a number to a percentage

开发者 https://www.devze.com 2022-12-12 14:37 出处:网络
I am looking for a way to convert any number to a percentage in the following way: 1.00 is 50% numbers below 1.00 approach 0% logarithmically

I am looking for a way to convert any number to a percentage in the following way:

  1. 1.00 is 50%

  2. numbers below 1.00 approach 0% logarithmically

  3. numbers above 1.00 approach 100% logarithmically.

    x > 0. So y needs to approach 0 as x becomes infinitely small on the开发者_Python百科 positive side.

I'm sure this is simple to do, but I can't recall how to do it.


try 1 / (1 + e^(1-x))

it's the logistic function shifted by 1 unit

Algorithm for logarithmically converting a number to a percentage

If you want it to approach faster, you can change e to something higher

Edit:

to have f(0) = 0 you could use 1 - 2^(-x)

Algorithm for logarithmically converting a number to a percentage


When you say logarithmically, do you mean asymptotically? If so, then "y needs to approach 0 as x becomes infinitely small on the positive side" just means f(0)=0 if f is continuous. In that case x/(x+1) will work: http://www.wolframalpha.com/input/?i=x%2F%28x%2B1%29


how about y = f(t) = 1 - exp(-t/tau) ?

For t near 0, y is approximately t/tau. For t approaching infinity, y asymptotically approaches 1.

As for the f(1)=0.5 approach, this can be used to solve for tau = 1/log(2).


From what you're describing, I'm hearing the graph of x cubed -- very basic, and should be efficient in most languages.

Graph http://jedsmith.org/static/S01813305.png

This was graphed with y=(x-1)^3+1 (transforms to make (1,1) the origin). You can, of course, make the results a percentage by simply scaling by 50.

You are, ultimately, trying to have an efficient solution to give you a rough percentage behavior in a programming language and not Mathematica, right?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号