-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleAveragePredictor.java
More file actions
executable file
·52 lines (44 loc) · 1.59 KB
/
SimpleAveragePredictor.java
File metadata and controls
executable file
·52 lines (44 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/**
* An class to compute the target user's predicted rating for the target item (item-based CF) using the simple average technique.
*
* Michael O'Mahony
* 20/01/2011
*/
package alg.ib.predictor;
import java.util.Map;
import alg.ib.neighbourhood.Neighbourhood;
import profile.Profile;
import similarity.SimilarityMap;
public class SimpleAveragePredictor implements Predictor
{
/**
* constructor - creates a new SimpleAveragePredictor object
*/
public SimpleAveragePredictor()
{
}
/**
* @returns the target user's predicted rating for the target item or null if a prediction cannot be computed
* @param userId - the numeric ID of the target user
* @param itemId - the numerid ID of the target item
* @param userProfileMap - a map containing user profiles
* @param itemProfileMap - a map containing item profiles
* @param neighbourhood - a Neighbourhood object
* @param simMap - a SimilarityMap object containing item-item similarities
*/
public Double getPrediction(final Integer userId, final Integer itemId, final Map<Integer,Profile> userProfileMap, final Map<Integer,Profile> itemProfileMap, final Neighbourhood neighbourhood, final SimilarityMap simMap)
{
double above = 0;
int counter = 0;
for(Integer id: userProfileMap.get(userId).getIds()) // iterate over the target user's items
{
if(neighbourhood.isNeighbour(itemId, id)) // the current item is in the neighbourhood
{
Double rating = userProfileMap.get(userId).getValue(id);
above += rating.doubleValue();
counter++;
}
}
return (counter > 0) ? new Double(above / counter) : null;
}
}