Author Topic: Top Images Adapted for Weighted Average & Minimum # Votes for Top 10  (Read 8384 times)

0 Members and 1 Guest are viewing this topic.

Offline RuthE

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Discover Kate Gallery
I'd like to have both, if not just the second thing.

I'd like for the top 20 images to have a requirement on how many votes it's received. For say, an image must have the highest rank and at least 15 votes before it will be the top ranked images in top.php. Is this possible?

The other thing is that if images raitings were based on number of votes and the rating of an image. Not important to me if the above is met. Especially since voters can only see the top twenty.

Thanks.

Ruth

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Top Images Adapted for Weighted Average & Minimum # Votes for Top 10
« Reply #1 on: June 11, 2005, 08:10:38 PM »
I'd like for the top 20 images to have a requirement on how many votes it's received. For say, an image must have the highest rank and at least 15 votes before it will be the top ranked images in top.php. Is this possible?
in the mysql query for rating add AND i.image_votes > 15
for example:
Quote
        WHERE i.image_active = 1 AND i.cat_id NOT IN ($cat_id_sql) AND i.cat_id = c.cat_id AND i.image_votes > 15

The other thing is that if images raitings were based on number of votes and the rating of an image. Not important to me if the above is met. Especially since voters can only see the top twenty.
by default there is "top" by votes section...
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline RuthE

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Discover Kate Gallery
Re: Top Images Adapted for Weighted Average & Minimum # Votes for Top 10
« Reply #2 on: June 13, 2005, 06:55:04 PM »
Many thanks for your reply. The minimum votes required was quite easy to do.

However, I am still trying to use a 'weighted average' for the pictures, but not to much avail. Here is the formula I've been trying to incorporate for use in 4images.

The formula is also known as True Bayesian Estimate Calculation:

Weighted average = (v / (v+m)) * R + (m / (v+m)) * C

R  =  the regular average for the picture
v  =  number of votes for the picture
m  =  minimum votes required to be listed in the top 10 (currently 20)
C  =  the mean vote across the whole pictures

I've tried a few ways, but the rating never ends up 'right'. It's either way too low or too high. I guess it's just been too long since I've practiced any math skills. Any help would be appreciated.

We've been trying to do it via the new_raiting line in the functions.php file.

Offline V@no

  • If you don't tell me what to do, I won't tell you where you should go :)
  • Global Moderator
  • 4images Guru
  • *****
  • Posts: 17.849
  • mmm PHP...
    • View Profile
    • 4images MODs Demo
Re: Top Images Adapted for Weighted Average & Minimum # Votes for Top 10
« Reply #3 on: June 14, 2005, 05:16:01 AM »
C = the mean vote across the whole pictures
what does that mean?
Your first three "must do" before you ask a question:
Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)

Offline RuthE

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Discover Kate Gallery
Re: Top Images Adapted for Weighted Average & Minimum # Votes for Top 10
« Reply #4 on: July 02, 2005, 02:49:52 PM »
The mean vote would be the average rating given to all images.

Offline alekseyn1

  • Full Member
  • ***
  • Posts: 102
    • View Profile
    • My Project
Re: Top Images Adapted for Weighted Average & Minimum # Votes for Top 10
« Reply #5 on: December 05, 2010, 07:15:54 AM »
Wow, an old subject, but I am trying to figure this out myself and need help...

I am trying to come up with the proper approach to the ratings system.

At the moment I have a formula listed above working on my site with the following code:

// Rating
//formula used at IMDB for rating of their movies
//
//    v               m 
//------- * R  +  ------- * c 
//  v + m           v + m 
//
//Where:
//v = number of votes
//m = minimum number of votes to be considered (on IMDB = 1250)
//R = average "vote" given to the image
//c = average "vote" for all the image (on IMDB currently = 6.9)

$cat_id_sql get_auth_cat_sql("auth_viewcat""NOTIN");

$vote_number 30//"m" parameter from the above formula
$cutoff_time time() - 60 60 24 30;
$time "AND i.image_date >=".$cutoff_time."";
$time_av "AND image_date >=".$cutoff_time."";

$sql1 "SELECT AVG(image_rating) as avg, image_active, cat_id
        FROM "
.IMAGES_TABLE."
        WHERE image_active = 1 "
.$time_av." AND cat_id NOT IN ($cat_id_sql) AND image_rating <> 0";
	


$result1 $site_db->query_firstrow($sql1);
$average_of_all_images $result1['avg'];

//this is checking if the average rating is 5.0. If so, the system will sort by 
if (($average_of_all_images == 5) || (!$average_of_all_images)) {
$order_by "image_votes";

} else {

$order_by "(((i.image_votes/(i.image_votes+".$vote_number."))*i.image_rating)+((".$vote_number."/(i.image_votes+".$vote_number."))*".$average_of_all_images."))";
}

//echo "M = ".$vote_number.". Average of all ".$average_of_all_images."... ";
	

$sql "SELECT i.image_id, i.user_id, i.cat_id, i.image_name, i.image_thumb_file, i.image_rating, i.image_votes, c.cat_name, u.user_name, c.hide_author
        FROM "
.IMAGES_TABLE." i, ".CATEGORIES_TABLE." c, ".USERS_TABLE." u
        WHERE i.image_active = 1 "
.$time." AND i.cat_id NOT IN (".$cat_id_sql.") AND i.cat_id = c.cat_id AND i.user_id = u.user_id ".$cat_match_sql."
        ORDER BY "
.$order_by." DESC
	
	
LIMIT 10"
;
	



but it sometimes gives me weird results still.... especially when I set the cutoff time for 24 hours and M parameter to 3 votes only....
I do not fully understand how the ORDER BY ".$order_by." DESC line works in the context of the task.... does it perform properly? Is there another way (maybe using a temporary table) to list the images based on the formula?

There is another approach to calculating the ratings though that I have not tested yet... it will only work if you have installed the mod for saving the votes to the DB though...

The approach is to calculate a weighted average rating for an image instead of arithmetic average that is being calculated in the standard installation and then just simply sort by rating.
(taken from here)

If you have the mod installed then running this query will give you a weighted average rating for all your images:


//arithmetic mean for all images
SELECT sumvt ) / sumcnt )
FROM (
SELECT countvote ) * countvote ) AS cntvote countvote ) * countvote ) AS vt
FROM 4images_voted
GROUP BY vote
)a



//arithmetic mean for an image
SELECT sumvt ) / sumcnt )
FROM (
SELECT countvote ) * countvote ) AS cntvote countvote ) * countvote ) AS vt
FROM 4images_voted
WHERE image_id 
$image_id
GROUP BY vote
)a


I may be breaking my head over nothing, but image ratings are important for my site and I need them working as accurate as possible... So please MySQL gurus, I need help with this. Which approach you think is the best?

in Russian here
« Last Edit: December 05, 2010, 01:25:08 PM by alekseyn1 »