ranking

Find largest and second largest element in a range

家住魔仙堡 提交于 2019-11-30 14:59:49
How do I find the above without removing the largest element and searching again? Is there a more efficient way to do this? It does not matter if the these elements are duplicates. for (e: all elements) { if (e > largest) { second = largest; largest = e; } else if (e > second) { second = e; } } You could either initialize largest and second to an appropriate lower bound, or to the first two items in the list (check which one is bigger, and don't forget to check if the list has at least two items) using partial_sort ? std::partial_sort(aTest.begin(), aTest.begin() + 2, aTest.end(), Functor); An

Search ranking/relevance algorithms

半腔热情 提交于 2019-11-30 11:04:50
When developing a database of articles in a Knowledge Base (for example) - what are the best ways to sort and display the most relevant answers to a users' question? Would you use additional data such as keyword weighting based on whether previous users found the article of help, or do you find a simple keyword matching algorithm to be sufficient? Perhaps the easiest and most naive approach that will give immediately useful results would be to implement *tf-idf : Variations of the tf–idf weighting scheme are often used by search engines as a central tool in scoring and ranking a document's

Calculating rank in PHP/MySQL

雨燕双飞 提交于 2019-11-30 07:52:26
问题 I've got a table in MySQL lets just say for example its got two fields Username, GameName and Score. I want to calculate the rank of a user for an indivudal game name so I could do the query SELECT * FROM scores WHERE `GameName` = 'Snake' ORDER BY `Score` DESC to get a list of all users in order of highest to lowest and assign a number to each user. But is there an easier way to get the rank for an indivdual user rather than selecting the entire table as that doesn't seem too efficient.

mysql: group by ID, get highest priority per each ID

别说谁变了你拦得住时间么 提交于 2019-11-30 07:17:27
问题 I have the following mysql table called "pics", with the following fields and sample data: id vehicle_id filename priority 1 45 a.jpg 4 2 45 b.jpg 1 3 56 f.jpg 4 4 67 cc.jpg 4 5 45 kt.jpg 3 6 67 gg.jpg 1 Is it possible, in a single query, to get one row for each vehicle_id, and the row be the highest priority? The result I'm looking for: array ( [0] => array( [id] => '2', [vehicle_id] => '45', [filename] => 'b.jpg', [priority] => '1' ), [1] => array( [id] => '3', [vehicle_id] => '56',

Normalizing the edit distance

大兔子大兔子 提交于 2019-11-30 05:00:47
问题 I have a question that can we normalize the levenshtein edit distance by dividing the e.d value by the length of the two strings? I am asking this because, if we compare two strings of unequal length, the difference between the lengths of the two will be counted as well. for eg: ed('has a', 'has a ball') = 4 and ed('has a', 'has a ball the is round') = 15. if we increase the length of the string, the edit distance will increase even though they are similar. Therefore, I can not set a value,

How to balance number of ratings versus the ratings themselves?

徘徊边缘 提交于 2019-11-30 02:11:20
For a school project, we'll have to implement a ranking system. However, we figured that a dumb rank average would suck: something that one user ranked 5 stars would have a better average that something 188 users ranked 4 stars, and that's just stupid. So I'm wondering if any of you have an example algorithm of "smart" ranking. It only needs to take in account the rankings given and the number of rankings. Thanks! You can use a method inspired by Bayesian probability . The gist of the approach is to have an initial belief about the true rating of an item, and use users' ratings to update your

redis的5种数据结构和基本操作

五迷三道 提交于 2019-11-29 19:48:22
1.字符串(string) 1.1设置值 set key value [ex seconds] [px milliseconds] [nx|xx] 例如: 127.0.0.1:6379> set hello world OK 1.2获取值 127.0.0.1:6379> get hello "world" 字符串类型的内部编码有3种: int:8个字节的长整型。 embstr:小于等于39个字节的字符串。 raw:大于39个字节的字符串。 Redis会根据当前值的类型和长度决定使用哪种内部编码实现。 2.哈希(hash) hash由多个field构成,适合存储拥有多个属性的对象。 2.1 设置值 hset key field value 例如添加一个名字为tom的用户,user为key,name为field 127.0.0.1:6379> hset user name tom (integer) 1 再为这个hash添加一个名为age的field 127.0.0.1:6379> hset user age 13 (integer) 1 2.2 获取值 hget key field 例如获取用户的名字 127.0.0.1:6379> hget user name "tom" 获取用户的年龄 127.0.0.1:6379> hget user age 13 3.list

PHP MYSQL group ranking query

佐手、 提交于 2019-11-29 17:55:52
CREATE TABLE `players` ( `pid` int(2) NOT NULL AUTO_INCREMENT, `name` varchar(50) NOT NULL, `team` varchar(20) NOT NULL, `age` int(2) NOT NULL, PRIMARY KEY (`pid`), UNIQUE KEY `name` (`name`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; INSERT INTO `players` (`pid`, `name`, `age`, `team`) VALUES (1, 'Samual', 25, 'aa'), (2, 'Vino', 20, 'bb'), (3, 'John', 20, 'dd'), (4, 'Andy', 22, 'cc'), (5, 'Brian', 21, 'dd'), (6, 'Dew', 24, 'xx'), (7, 'Kris', 25, 'qq'), (8, 'William', 26, 'cc'), (9, 'George', 23, 'nn'), (10, 'Peter', 19, 'aa'), (11, 'Tom', 20, 'aa'), (12, 'Andre', 20, 'aa'); In the above table, I

Search ranking/relevance algorithms

女生的网名这么多〃 提交于 2019-11-29 16:28:41
问题 When developing a database of articles in a Knowledge Base (for example) - what are the best ways to sort and display the most relevant answers to a users' question? Would you use additional data such as keyword weighting based on whether previous users found the article of help, or do you find a simple keyword matching algorithm to be sufficient? 回答1: Perhaps the easiest and most naive approach that will give immediately useful results would be to implement *tf-idf: Variations of the tf–idf

Calculate rank with ties based on more than one variable

旧城冷巷雨未停 提交于 2019-11-29 15:42:52
I'm trying to compute a medal table for a sports event. My data looks like this: test <- data.frame("ID" = c("1_1", "1_2", "1_3", "1_4","1_5","1_6"), "gold"=c(10, 4, 1, 7, 7, 1), "silver"=c(1, 3, 2, 19, 19, 2), "bronze"=c(1, 8, 2, 0, 0, 2)) First, I want to order the data based on number of "gold", "silver", and "bronze", like this: (test_ordered <- with(test, test[order(-gold, -silver, -bronze), ])) Then compute the final medal rank. This is how the final rank column should like: (test_ordered$rank<-c(1, 2, 2, 4, 5, 5)) # ID gold silver bronze rank # 1 1_1 10 1 1 1 # 4 1_4 7 19 0 2 # 5 1_5 7