What is the correct algortma for the logarithmic distribution curve between two points?

I read a bunch of tutorials on the correct way to generate the logarithmic distribution of tagcloud weights. Most of them group tags into stages. This seems a little silly for me, so I developed my own algorithm based on what I read so that it dynamically distributes the tag counter along the logarithmic curve between the threshold and maximum. Here's the gist of it in python:

from math import log
count = [1, 3, 5, 4, 7, 5, 10, 6]
def logdist(count, threshold=0, maxsize=1.75, minsize=.75):
    countdist = []
    # mincount is either the threshold or the minimum if it over the threshold
    mincount = threshold<min(count) and min(count) or threshold
    maxcount = max(count)
    spread = maxcount - mincount
    # the slope of the line (rise over run) between (mincount, minsize) and ( maxcount, maxsize)
    delta = (maxsize - minsize) / float(spread)
    for c in count:
        logcount = log(c - (mincount - 1)) * (spread + 1) / log(spread + 1)
        size = delta * logcount - (delta - minsize)
        countdist.append({'count': c, 'size': round(size, 3)})
    return countdist

In principle, without a logarithmic calculation of a separate account, he would create a straight line between the points (mincount, minsize) and (maxcount, maxsize).

, . Mincount - , . , mincount minsize. , , , . mincount "or 1" .

?

3 . , . , y = lnx x = 1, y = 0. , mincount. mincount , 0 .

. mincount , , , . , , -, , .

Apr 6: google , read, , , .

28 . antti.huima: , , . , , , . , - , , . ? , - , ?

+5
5

antti.huima, , .

, , mincount .

weight(MIN) = ln(MIN-(MIN-1)) + min_weight
min_weight = ln(1) + min_weight

, (MAX, max_weight). :

weight(x) = ln(x-(MIN-1))/K + min_weight

K :

K = ln(MAX-(MIN-1))/(max_weight - min_weight)

, python:

from math import log
count = [1, 3, 5, 4, 7, 5, 10, 6]
def logdist(count, threshold=0, maxsize=1.75, minsize=.75):
    countdist = []
    # mincount is either the threshold or the minimum if it over the threshold
    mincount = threshold<min(count) and min(count) or threshold
    maxcount = max(count)
    constant = log(maxcount - (mincount - 1)) / (maxsize - minsize)
    for c in count:
        size = log(c - (mincount - 1)) / constant + minsize
        countdist.append({'count': c, 'size': round(size, 3)})
    return countdist
+2

. :

   size
    |
max |_____
    |   /
    |  /|
    | / |
min |/  |
    |   |
   /|   |
0 /_|___|____
    0   a

min max - , a = log (maxcount) -b. y = mx + c, x = log (count) -b

, , m, (maxsize-minsize)/a.

x = 0 y = minsize, log (mincount) -b = 0 β†’ b = log (mincount)

:

mincount = min(count)
maxcount = max(count)
xoffset = log(mincount)
gradient = (maxsize-minsize)/(log(maxcount)-log(mincount))
for c in count:
    x = log(c)-xoffset
    size = gradient * x + minsize

, 1, :

mincount = min(count+[1])

1 . , maxcount 1. , , :

from math import log
count = [1, 3, 5, 4, 7, 5, 10, 6]
def logdist(count, maxsize=1.75, minsize=.75):
    countdist = []
    mincount = min(count+[1])
    maxcount = max(count+[1])
    xoffset = log(mincount)
    gradient = (maxsize-minsize)/(log(maxcount)-log(mincount))
    for c in count:
        x = log(c)-xoffset
        size = gradient * x + minsize
        countdist.append({'count': c, 'size': round(size, 3)})
    return countdist
+1

, , MIN MAX; , , .

"", "", ( ) . -, MAX max_weight ( , 1.75):

weight(MAX) = max_weight

-, count MIN min_weight ( 0.75):

weight(MIN) = min_weight

, , 1, K < 1, :

weight(x) = weight(x + 1) * K

, :

weight(x) = weight_max * (K ^ (MAX - x))

, x = MAX , 1.

, (MIN) = min_weight, :

weight_min = weight_max * (K ^ (MAX - MIN))

K ^ (MAX - MIN) = weight_min / weight_max

(MAX - MIN) ln K = ln weight_min - ln weight_max

.

ln K = (ln weight_min - ln weight_max) / (MAX - MIN)

, K < 1.

K = exp((ln weight_min - ln weight_max) / (MAX - MIN))

, K. MIN MAX:

weight(x) = max_weight * (K ^ (MAX - x))

.

+1

( , , , , ).

- , , . - , , .

0

, , . , , .

0

All Articles