User activity algorithm - algorithm

I am not sure if this is the right place to ask this question. Here it goes, I am looking to calculate a user activity score for a game.
Consider this:
User A wants to attack a User B...Z
Users B....Z can attack any of Users A...Z
I need a way to sort Users B...Z to User A, so they can choose who to attack. We want to make sure that everyone gets to play this game. Which means each user gets advertised as a potential opponent to user A, based on a score determined by:
The user B...Z has already been attacked (this user's score should drop, because we want to display someone who hasn't been attacked)
User B...Z responds to the attack (this user's score should increase, since they actually are playing the game)
What is the simplest algorithm to calculate such a score?

The simplest algorithm is a simple formula:
Rank = weight1 * TimesResponded - weight2 * TimesAttacked
In which both weights are positive constants, which you can adapt to change the gameplay a little bit.

Related

Displaying the most relevant advertisements to web users based on their visited pages

I am asked to develop a pop-up ad display system for website. What it does is that the website will record the urls that the users visit and display the most relevant pop-up ad for them.
The website administrator first needs to define some groups (e.g. "Golfers", "Video game players") and then define some rules such as:
If the user visits the url pattern http://www.domain.com/golf-clubs/* and stay on that page for more than 10 seconds, he will be assigned to the Golfers group.
Also, the website administrator can create ads and assign them to different groups. For example, he can create a golf club promotion ad for users with the Golfers group. When the user visits the website again, the system will check if he belongs to any group(s) and display the most relevant ad for him.
For the user identification part, I am going to simply use cookies, which is to assign an unique cookie to every new website visitor.
The difficult part for me is to design the logic about which pop-up ad to display when the user belongs to multiple groups. For example, if he belongs to both Golfers and Video game players groups. Rather than randomly choosing one to display, is there a better way to handle such situation?
I have come up with a solution that I don't know if it's good or not. That is when a user is assigned a group it also comes with a score for that group. For example, if a user belongs to both Golfers and Video game players groups but he has a higher score for the Golfers group, the system will display a Golfers group ad for him as the first priority.
But this creates another difficult problem, how should the group scores calculated for each user? I also need to account for that recent page visits are of more importance, for example, maybe the user was a golfer and belongs to the Golfers group with a very high score but he recently visits a lot of video game web pages and gets assigned the Video game players group, how many scores should he get in this group?
Any thoughts would be appreciated.
Your problem is really close to some Operating System problems. For example when it decides about what to keep in cache and what to delete. Both "number" and "time" of visits influence the decision, and of course there are plenty of policies to select.
Here I try to make one in order to show how they work. I want to make it simple and manageable, so I use weights for time wand number of visits v. For each category, keep number of visits n and their relative times t. Then calculate sum of weight of time divided by relative times (except the expired ones) plus times of visits multiplied by corresponding weight: w/t+n*v.
Larger t leads to smaller score, while larger n (number of visits) improves the score.

Searching for an efficient algorithm for: When was the chatroom empty?

A protocol (in form of a tableview) is keeping track on the activity of all its users (wlog: there are n users), when they entered and when they left the chat room.
The table view consists of the three columns, user, time user logged in, time user logged out.
I am now tasked to find an algorithm, which finds out, when the chat room is empty.
A fast and easy way seems to me to first define:
An empty chatroom has the value: 0
If a person enters the chatroom, the value of the chatroom increases by 1
If a person leaves the chatroom, the value of the chatroom decreases by 1
Now I sort all times, 2*n, in a list and simply check for every time the current value of the room and check everytime, if the current value is 0, in which cases I win, jobs done.
Overall the algorithm may take me O(n* log(n)) time, however I wonder, if there is a faster/better way doing this. I appreciate any constructive comment or answer.
As always thanks in advance.

How to manage multiple positive implicit feedbacks?

When there are no ratings, a common scenario is to use implicit feedback (items bought, pageviews, clicks, ...) to suggests recommendations. I'm using a model-based approach and I wondering how to deal with multiple identical feedback.
As an example, let's imagine that consummers buy items more than once. Should I have to consider the number of feedback (pageviews, items bought, ...) as a rating or compute a custom value ?
To model implicit feedback, we usually have a mapping procedure to map implicit user feedback into the explicit ratings. I guess in most domains, repeated user action against the same item indicates that the user's preference over the item is increasing.
This is certainly true if the domain is music or video recommendation. In a shopping site, such a behavior might indicate the item is consumed periodically, e.g., diapers or printer ink.
One way I am aware of to model this multiple implicit feedback is to create a numeric rating mapping function. When the number of times (k) of implicit feedback increases, the mapped value of rating should increase. At k = 1, you have a minimal rating of positive feedback, for example 0.6; when k increases, it approaches 1. For sure, you don't need to map to [0,1]; you can have integer ratings, 0,1,2,3,4,5.
To give you a concrete example of the mapping, here is what they did in a music recommendation domain. For short, they used the statistic info of the items per user to define the mapping function.
We assume that the more
times the user has listened to an artist the more the user
likes that particular artist. Note that user’s listening habits
usually present a power law distribution, meaning that a few
artists have lots of plays in the users profile, while the rest
of the artists have significantly less play counts. Therefore,
we compute the complementary cumulative distribution of
artist plays in the users’ profile. Artists located in the top
80-100% of the distribution are assigned a score of 5, while
artists in the 60-80% range assign a score of 4.
Another way I have seen in the literature is to create another variable besides a binary rating variable. They call it confidence levels. See here for details.
Probably not that helpful for OP any longer, but it might be for others in the same boat.
Evaluating Various Implicit Factors in E-commerce
Modelling User Preferences from Implicit Preference Indicators via Compensational Aggregations
If anyone knows more papers/methods, please share as I'm currently looking for state of the art approaches to this problem. Thanks in advance.
You typically use a sum of clicks, or some weighted sum of events, as a "score" for each user-item pair in implicit feedback systems. It's not a rating, and that's more than a semantic distinction. You won't get good results if you feed these values into a process that's expecting rating-like and trying to minimize a squared-error loss.
You treat 3 clicks as adding 3 times the value of 1 click to the user-item interaction strength. Other events, like a purchase, might be weighted much more highly than a click. But in the end it also adds to a sum.

How to give players a score on a ranking/prediction task?

I have a website built with php/mysql, and I am looking for help in communicating to a Programmer what I want him to do with a Poll/Prediction game that I am trying to create.
For purposes of discussion, assume a game where perhaps 100 players try to predict the top 5 finishers in a Golf Tournament of perhaps 9 Golfers.
I am looking for help in how to create and assign a score based upon the accuracy of prediction.
The players provide a rank ordering using a drag and drop function to order the players from 1 through 5. This ordering has already been coded, and the ranks are stored somehow in the DB (I do not know how).
My initial thinking is to ask the coder to create a script which will assign a score from 1 to 5 for each Golfer that the player nominated to be in the Top 5.
So, a player who predicted perfectly would be awarded a perfect score of 12345.
His first golfer received a 1 for finishing first, second a 2 for finishing second, third golfer receives a 3 for finishing third, and so on.
Anybody less than perfect would have a score higher than 12345.
Players who got the first four positions correct would have to be differentiated on the basis of the finish of their fifth Golfer.
So, one might score 12347 and the other 12348 and the player with the highest score (12348) would be the loser in a matchup of the two players.
A player who did poorly, might have a score of 53419.
Question:
Is this a viable way of creating a score which the players of my game can be ranked upon?
Is it possible to instead simply have something like a Spearman Rank-Order Correlation calculated comparing the Actual Finish Positions with the Predicted Finish Positions for each player,
and then rank players on the basis of the correlation coefficients for their rankings?
Thanks for any help in clarifying how to conceptualize this before approaching a programmer who gets annoyed when I don't really know what I want him to do ahead of time.
It's a quite interesting problem.
It seems that there are three components that need to be considered in the scoring: the number of correct predictions, the order of correct predictions, and the weight of correct predictions.
For example, assume the truth is:
1,5,10,15,20
Here are some predictions:
1,6,7,8,9 : only predicted first one
2,1,10,21,30 : 1 and 10, but the order of 1 is incorrect
20,15,1,5,30 : hit four in the top 5, but the orders are incorrect
It depends on what you value most. You may first check how many in the top 5 the user has predicted, add a value, and then penalize wrong orders. The weight for each position should also be different, this way
1,5,10,15,20 will rank higher than 1,5,10,20,15 and higher than 1,10,5,20,15
Spearman may be working, but I feel it could be too coarse for your purpose.
This is actually a very similar problem that search engines have. EG, in search engine evaluation, the actual outcomes are preferred results provided by humans, and the predicted outcomes are the results delivered by the search engine. In both your task and for search engines, I'd guess you care a lot more about the accuracy of the winner than the accuracy of the 5th place finisher. If that is the case, then the mean average precision is probably a good measure.

Parse.com: get rank within leaderboard

Actually my question is the same as stated here https://parse.com/questions/issue-with-using-countobjects-on-class-with-large-number-of-objects-millions which is a 9 months old thread that unfortunately never got a real answer.
I have a parse backend for a mobile game, and I want to query the global rank of the user based on his score.
How can I query this, assuming I have more than 1000 users, and a lot more score entries?
Also, I want to be able to query the all-time rank as well as the last-24-hours rank.
Is this even possible with parse?
If you need to do large queries like that, you should redesign your solution. Keep a leaderboard class that gets updated with cloud code; either in an afterSave hook, or with a scheduled job that runs regularly. Your primary focus must be on lightning fast lookups. As soon as your lookups start getting large or calculation heavy, you should redesign your backend for scalability.
Solution for all time and time based leader boards is
You should keep records all users score in separate entity suppose LeaderBoard and maintain top users of all time leader board or time base leader board users list in separate entity suppose TopScoreUsers. In this way you do not need to run query every time on actual leader board entity(i.e LeaderBoard) to get your top users.
Suppose your app/game has all time leader board that should show 100 top users only. When any user submit score then you check first, is this user fall in top 100 users list (from TopScoreUser), if yes then add it in separate entity named TopScoreUser (if this list already has 100 users then find place of current user in this list and remove last record) and then update user's own score in LeaderBoard entity otherwise only update user score in LeaderBoard entity.
Same case is for Time based leader board.
For user rank, recommended way is to use some calculation or formula to determine approximately rank otherwise it is tough to find/manage user actual rank if users are in millions.
Hopefully this will help you.

Resources