Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I've got quite a puzzle for ya mathematicians here :)

This could go in the regular stackoverflow but since the subject matter of the question is primarily math I figure I'd ask it here.

I wasn't satisfied with any of the keyword cloud plugins I could find so I quickly hacked my own. Here is what the output of it looks like:

enter image description here

And here is the code:

<span style="border-bottom:1px dotted #eee;padding-left:3px;padding-right:3px;font-size:'+Math.log(((triggered_keywords[key]/total)*1300))+'em;">'+key+'</span> '

I'll copy just the math portion here:

Math.log(((triggered_keywords[key]/total)*1300))

So, I have an array of values like: [['watch', 5300], ['sky', 521], ['gas', 34]] I add them all together, divide each by the total and so for each keyword I arrive at a number.

(If you're curious, these words and the numbers represent search queries and the corresponding number of times they've been triggered)

I slept through my intro to calc class when I went to college but I sort of thought, hey, log() should help me "tame" the larger numbers so to speak. I added the *1300 in a series of trial and errors and made it look more or less nice.

As you can see some of the words though are being rendered tiny (with an em font-size of under 1). Is there a way to modify my "formula" to introduce a cap on how small a value will will come out?

I don't want the output number for any keyword to be smaller than about 0.85

share|improve this question

1 Answer 1

up vote 2 down vote accepted

So mainly you want the size to scale like its relative frequency but you also want to lower-cut off, correct?

Then the simplest way is:

Starting with your array of values, instead of "adding them all together and divide each by the total", do

"adding them all together and divide each by the total, and if the resulting number is less than a critical threshold, 'round it up' to the critical threshold".

You have to choose the threshold yourself by trial and error.

Starting with your data [['watch', 5300], ['sky', 521], ['gas', 34]] , if your threshold is 0.01, then the value assigned to 'gas' would be instead of

$$ \frac{34}{5300 + 521 + 34} = \frac{34}{5855} \approx 0.006 $$

the threshold value of 0.01.

If you chose your threshold to be 0.2, then not only would 'gas' be "rounded up" to 0.2, also 'sky':

$$ \frac{521}{5855} \approx 0.09 < 0.2 $$


As to how to program that logic: well, that depends on your computer language of choice and is outside the scope of this forum.

share|improve this answer
    
The solution was a lot easier than I was expecting... –  dsp_099 Dec 14 '12 at 13:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.