I have two values, an address and amount in a game. In each round the user makes his contribution. The users address and the total contribution is sent to a function which maintains a list of players in a sorted manner.
There is a function that rewards the top players and resets the list. What would be the best approach to maintain the list of players and be able to reset it in a round independent manner.
Related
I'm using AWS Personalize to suggest recommendations based on thousands of 'likes' in our platform. Currently using User, User-Interaction and Item data, we get a score between 0.00004 and 0.006.
Firstly, how is the score calculated, and based on the example I gave, is it low?
Thanks,
The formula for calculating scores depends on the use case and recipe. Based on the documentation for the user-personalization recipe:
Models that are based on USER_PERSONALIZATION recipes score all of the items in your Items dataset relative to each other on a scale from 0 to 1 (both inclusive), so that the total of all scores equals 1. For example, if you're getting movie recommendations for a user and there are three movies in the Items dataset, their scores might be 0.6, 0.3, and 0.1. Similarly, if you have 1,000 movies in your inventory, the highest-scoring movies might have very small scores (the average score would be .001), but, because scoring is relative, the recommendations are still valid.
Since the score values you shared have low absolute values, I suspect that you're using user-personalization. The higher number of distinct items in your interactions dataset, the smaller the score values will be. Look at the scores relative to other items in the response rather than reading too much into their absolute values.
However, the scoring formula for the personalized-ranking is different.
Like the scores returned by the GetRecommendations operation, GetPersonalizedRanking scores sum to 1, but because the list of considered items is much smaller than your full Items dataset, recommendation scores tend to be higher.
Mathematically, the scoring function for GetPersonalizedRanking is identical to GetRecommendations, except that it only considers the input items. This means that scores closer to 1 become more likely, as there are fewer other choices to divide up the score
i am trying to implement a minimax algorithm from scratch in java.
General point is known to all, through a tree i try to find the best possible move.
I dont have something crucial from code to show now, first i would like someone to give me a general approach so i can start the project and then update the post with my code.
In addition to that i am also going to implement a random heuristic for my game, that will in random choose the next move and pass it to the game, but this will be added later on.
I will be adding bounty on this question.
P.S.
This is not a duplicate, i dont want to copy someone else's code, i have to do the whole code on my own.
So the main thinking to follow is the following:
Calculate the best move with the given game field and the rating mechanism
field the input field where to calculate from ratingMechanisms the mechanism to rate the move and return the best move.
In a more in depth analysis:
The key to the Minimax algorithm is a back and forth between the two players, where the player whose "turn it is" desires to pick the move with the maximum score. In turn, the scores for each of the available moves are determined by the opposing player deciding which of its available moves has the minimum score. And the scores for the opposing players moves are again determined by the turn-taking player trying to maximize its score and so on all the way down the move tree to an end state.
A description for the algorithm, assuming X is the "turn taking player," would look something like:
-If the game is over, return the score from X's perspective.
-Otherwise get a list of new game states for every possible move
-Create a scores list
-For each of these states add the minimax result of that state to the scores list
-If it's X's turn, return the maximum score from the scores list
-If it's O's turn, return the minimum score from the scores list
-You'll notice that this algorithm is recursive, it flips back and forth between the players until a final score is found.
In the main part you should use a for in order to minimize or maximize each level (also you can try adding some debugging like this: //System.out.println("max/min level " + i);), then while getting the current level of the tree check if it is null so you get no exceptions, and for the that level add it in the max node, while parsing in the min node.
In order to use the max and min nodes you have create the functions for these.
The maximize part of the algorithms: The node will get the biggest rating of his children. WARNING: if no child exists, the rating will be the min.
For the minimize part of the algorithms. The node will get the lowest rating of his children. WARNING: if no child exists, the rating will be max.
I'm working with our IT group to develop an optimizer for logistics operations. The basic design is that it will look at shipments, run a search for additional shipments originating with in XX miles of the previous shipments destination, and link them together in a loop. It will continue to do this until it hits a user defined set of shipment legs where the loop ends at or close to 1st shipment origin.
The issue we are facing is that the materials we ship are chemicals, which can have interactions if placed in a tank that contained XX chemical before it. The obvious solution is to use a different tank or wash it out, but we also need it to compute solutions prior to that.
My problem is, currently, there is no way on the market to do that prior product optimization.
The question is: Is there some kind of logic table function I can write that will allow the optimizer to see an element in the data set (say, Product Family of 1) that will pull from a product database containing predefined product families (i.e. PF 1 = Chemicals A1-B7, PF 2 = Chemical B8-J8, etc.) and then ping off of a logic table that defines a do not ship with list (i.e. PF 1 cannot ship if PF 2 was on the previous leg.
Suppose you want to implement an algorithm that works in the following way:
You read in from a file that contains values of the form:
Mark Buy 20 1 100
Bob Sell 20 2 90
Where the input takes the form:
<name><buy or sell><quantity><time><company><buy maximum or sell minimum>
What's the fastest way to match buyers and sellers (for some company, where buyers and sellers are matched only if the person with the highest buy for that company is greater than the person with the lowest sell for that company). The buy or sell that is top-most will be the one that determines what price to use.
So in the example given we'd have "Mark, at time 1, bought 20 of Google for $100 from Bob, at time 2."
How can we optimize this algorithm for speed? Would reading in the entire file first be an optimal solution?
What you need is two priority queues per commodity: one for active buy bids (prioritized on max-price), and one for active sell bids (prioritized on min-price), plus an overall queue for bid creation/expiry events (prioritized on time). (If your bids are in a batch file as described, rather than a causal/online sequence, you can just sort the creation/expiry events, but you still need the buy and sell queues)
Using priority queues is the crux; everything after that is plumbing:
foreach bid creation/expiry event, in chronological order:
if the event is an expiry:
delete the bid from the appropriate queue
else, the event is a creation:
add the bid to the appropriate queue
repeat until no further transaction can be performed:
find max-active-buy and min-active-sell bids for the given commodity
if they match:
execute (and record) the transaction
update partially fulfilled bids, and remove completely fulfilled ones
When performing as a batch operation, you could simplify things a bit by sorting out each individual commodity, and executing each one separately. However, this will not work if the markets interact in any way (such as checking for sufficient account balance).
Priority queue operations can have asymptotic performance of O(log N) in the number of items. There are many fast, practical priority queue datastructures available which achieve this asymptotic limit.
Since you are evaluating an entire file as a batch, you may want to look into priority queues with amortized performance guarantees -- but if you expect to use your code in a real-time setting, you should probably stick to priority queues with strict per-query guarantees.
For my class, I am making a program that manages a Hotel. My 'Test' method creates random rooms and random customers. Once it has does this, it then takes the random customers it created, and checks them into the random rooms it created.
My goal is for the Test to check-in only HALF of the rooms with customers. And leave the other half of the rooms empty. And also, I can only have 1 customer per room.
The method compiles, but their are some flaws:
The 'Test' fills ALL the rooms with customers (instead of only half of them).
The 'Test' will often assign a single room to multiple customers( For example, Room 301 will now belong to 3 different customers instead of just 1)
Can anyone help me figure out how to fill only half of the rooms that are created.
And also help me figure out how to not let a single room be applied to more than 1 customer? I am pretty sure that the last FOR loop in the method should be the only thing that I need to adjust.
string Hotel::test(int numRooms, int numCustomers)
{
string result;
for(int i=0;i<numRooms;i++) // **********CREATES RANDOM ROOMS
{
Room iRoom(randString(8),
randInt(0,1000),
randInt(0,1000),
randInt(0,1000),
randInt(0,1000));
listofrooms.add(iRoom);
}
for(int i=0;i<numCustomers;i++) // ***********CREATES RANDOM CUSTOMERS
{
Customer cus(randString(8),randNumberString(10),randNumberString(16));
listofcustomers.add(cus);
}
for(int i=0;i<numCustomers+numRooms;i++) // **FILLS RANDOM ROOMS WITH RANDOM CUSTOMERS
{ // **I KNOW THIS IS THE ONLY LOOP I NEED TO ADJUST
checkIn(listofrooms.getRandID(),listofcustomers.getRandID());
}
return result;
}
Part 1
You need half the rooms to be filled. Since only 1 guest can be in any room, you need to fill the rooms numRooms times. So, you just need to adjust your loop to:
for (int i = 0; i < numRooms/2; i++)
Part 2
There are many ways to ensure that. The naive approach would be to retry in a loop
for (int i = 0; i < numRooms/2; i++)
{
int assignedRoom;
do
{
assignedRoom = listofrooms.getRandID();
} while (isFull(assignedRoom);
checkIn(assignedRoom, listofcustomers.getRandID());
}
Of course, you wouldn't want the same customer in two rooms, so you need to do the same thing with customers also.
Another method could be to take a random room, and if it was full iterate to next rooms (wrapping around to first room if overflow) until you find an empty room.
Another method could be to random_shuffle a copy of the rooms and take the first half.
Like I said, whatever you do with the rooms, you need to do with the customers also.
recommendation: Perhaps the best distribution is achieved with the last method (the one with random_shuffle. Note that the naive approach has a non-deterministic (and possibly bad) performance.
In the loop, the end condition should be i<numRooms/2 to fill only half of the rooms.
To have only one customer in each room, you have some choices, depending on your constraints. You have to keep track of which rooms you have assigned already.
For example you can remove the assigned rooms from the list - this may not be allowed in most of the times.
Or you can modify the Room class to containt a boolean that you set when it is filled, and you look for another room if it is filled - again, you said you don't want to change anything but the loop.
You may as well create an array of integers, and index the room array (and, with another one, the customer array, if you don't want to assign costumers more than once) with its randomly selected values, again, removing the values that you assigned before.
Another approach, if you don't need a uniform distribution, to have a couner marking how many rooms have to be filled to have half of them assigned, iterate through the rooms, and for each one, decide if you fill it or not. When the remaining number of unprocessed rooms is equal to the number of rooms to be filled in, fill all of them.