Maths question (log() maybe).

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Maths question (log() maybe).

Post by onion2k »

(This is actually related to the table of scores I had a question about in databases.)

I have a table of score data. I'm fetching the top 25 scores and outputting them using a system that makes the highest score biggest:

Code: Select all

	function scoreToSize($s,$min,$max) { //Score, minimum score, maximum score
	
		static $scoreSize = array("tiny","small","medium","large","verylarge","huge"); //These are CSS classes
		
		$range = $max-$min; //Find the full range
		$s = $s-$min; //Zero base the current score value.
		$per = (($s/$range)*100); //Work out the percentile value of the score in the range
		$rper = 100/count($scoreSize)+1; //Work out the 'band width' of each size
		$level = round($per / $rper); //Calculate which band the score is in
		
		return $scoreSize[$level]; // Return the band class
			
	}
This works fine, it calculates the 'band' in which the score appears as a percentage of the difference between the biggest and the smallest.

However, it really only works if there is a reasonably even distribution of scores across the range. If they're 1,2,2,3,3,5,6,6,6,6,7,10,12 there's no problem, but if there's a score that's very different, such as 50, it means the table displays with 1 'huge' score and all the rest are 'tiny'.

Is there a solution to this? I thought about making it a logarithmic scale, but I'm not sure how to go about doing that.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Number of bands: ceil(sqrt(high - low))
I'd then use standard deviation for the destribution.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

feyd wrote:Number of bands: ceil(sqrt(high - low))
The number of bands has to be fixed as they're defined as CSS classes.
feyd wrote:I'd then use standard deviation for the destribution.
I've got the standard deviation, but I've no idea what to do with it. :cry:
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

I'm not sure what thesis you are using behind this logic( name of the formula could be of help).

But defnitely standard deviation is a standard way for such average scores and ranks.

I think a tutorial on standard deviation could be of help.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Standard deviation tells you where the bulk of your population is. Data within one standard deviation (as an edge) is 68.27% of your sample's arithmetic mean, within two widens that to 95.45% and the third brings it to 99.73%.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

I'm pretty sure that the standard deviation isn't any use in this case. In a set with one outlying result all the rest are going to be within 1 standard deviation of the mean. That's no help at all, it's the same as what I have now (all the smaller scores being tiny with one big score). I'm trying to get a more linear distribution of sizes. I think I'm just going to have to make the first 3 the biggest, next 3 the next biggest down, and so on.
Post Reply