Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the correct algorthm for a logarthmic distribution curve between two points?
    primarykey
    data
    text
    <p>I've read a bunch of tutorials about the proper way to generate a logarithmic distribution of tagcloud weights. Most of them group the tags into steps. This seems somewhat silly to me, so I developed my own algorithm based on what I've read so that it dynamically distributes the tag's count along the logarthmic curve between the threshold and the maximum. Here's the essence of it in python:</p> <pre><code>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's over the threshold mincount = threshold&lt;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 </code></pre> <p>Basically, without the logarithmic calculation of the individual count, it would generate a straight line between the points, (mincount, minsize) and (maxcount, maxsize).</p> <p>The algorithm does a good approximation of the curve between the two points, but suffers from one drawback. The mincount is a special case, and the logarithm of it produces zero. This means the size of the mincount would be less than minsize. I've tried cooking up numbers to try to solve this special case, but can't seem to get it right. Currently I just treat the mincount as a special case and add "<code>or 1</code>" to the logcount line.</p> <p>Is there a more correct algorithm to draw a curve between the two points?</p> <p><strong>Update Mar 3</strong>: If I'm not mistaken, I am taking the log of the count and then plugging it into a linear equation. To put the description of the special case in other words, in y=lnx at x=1, y=0. This is what happens at the mincount. But the mincount can't be zero, the tag has not been used 0 times.</p> <p>Try the code and plug in your own numbers to test. Treating the mincount as a special case is fine by me, I have a feeling it would be easier than whatever the actual solution to this problem is. I just feel like there <em>must</em> be a solution to this and that someone has probably come up with a solution.</p> <p><strong>UPDATE Apr 6</strong>: A simple <a href="http://www.google.com/search?q=logarithmic%20tag%20cloud" rel="nofollow noreferrer">google</a> search turns up a many of the tutorials I've read, but <a href="http://www.echochamberproject.com/node/247" rel="nofollow noreferrer">this</a> is probably the most complete example of stepped tag clouds.</p> <p><strong>UPDATE Apr 28</strong>: In response to antti.huima's solution: When graphed, the curve that your algorithm creates lies below the line between the two points. I've been trying to juggle the numbers around but still can't seem to come up with a way to flip that curve to the other side of the line. I'm guessing that if the function was changed to some form of logarithm instead of an exponent it would do exactly what I'd need. Is that correct? If so, can anyone explain how to achieve this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload