Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 206129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:37:05+00:00 2026-05-11T17:37:05+00:00

I’ve read a bunch of tutorials about the proper way to generate a logarithmic

  • 0

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:

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<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

Basically, without the logarithmic calculation of the individual count, it would generate a straight line between the points, (mincount, minsize) and (maxcount, maxsize).

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 “or 1” to the logcount line.

Is there a more correct algorithm to draw a curve between the two points?

Update Mar 3: 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.

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 must be a solution to this and that someone has probably come up with a solution.

UPDATE Apr 6: A simple google search turns up a many of the tutorials I’ve read, but this is probably the most complete example of stepped tag clouds.

UPDATE Apr 28: 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?

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T17:37:05+00:00Added an answer on May 11, 2026 at 5:37 pm

    Thanks to antti.huima’s help, I re-thought out what I was trying to do.

    Taking his method of solving the problem, I want an equation where the logarithm of the mincount is equal to the linear equation between the two points.

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

    While this gives me a good starting point, I need to make it pass through the point (MAX, max_weight). It’s going to need a constant:

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

    Solving for K we get:

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

    So, to put this all back into some python 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<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
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a bunch of posts stored in text files formatted in yaml/textile (from
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.