private static List<int[]> getPerfectTags(BookmarkReader reader, int sampleSize, int limit) { List<int[]> tags = new ArrayList<int[]>(); int trainSize = reader.getUserLines().size() - sampleSize; for (UserData data : reader.getUserLines().subList(trainSize, trainSize + sampleSize)) { List<Integer> t = data.getTags(); while (t.size() < limit) { t.add(-1); } tags.add(Ints.toArray(t)); } return tags; }
public static void predictPopularTags(String filename, int trainSize, int sampleSize) { // filename += "_res"; BookmarkReader reader = new BookmarkReader(trainSize, false); reader.readFile(filename); List<int[]> values = getPopularTags(reader, sampleSize, 10); // List<int[]> values = getPerfectTags(reader, sampleSize, 10); reader.setUserLines(reader.getUserLines().subList(trainSize, reader.getUserLines().size())); PredictionFileWriter writer = new PredictionFileWriter(reader, values); writer.writeFile(filename + "_mp"); Utilities.writeStringToFile("./data/metrics/" + filename + "_mp" + "_TIME.txt", timeString); }
private static List<int[]> getPopularResources(BookmarkReader reader, int count, int trainSize) { List<int[]> resources = new ArrayList<int[]>(); Map<Integer, Integer> countMap = new LinkedHashMap<Integer, Integer>(); for (int i = 0; i < reader.getResources().size(); i++) { countMap.put(i, reader.getResourceCounts().get(i)); } Map<Integer, Integer> sortedCountMap = new TreeMap<Integer, Integer>(new IntMapComparator(countMap)); sortedCountMap.putAll(countMap); for (int userID : reader.getUniqueUserListFromTestSet(trainSize)) { List<Integer> userResources = UserData.getResourcesFromUser(reader.getUserLines().subList(0, trainSize), userID); // System.out.println(userResources.size()); List<Integer> resIDs = new ArrayList<Integer>(); int i = 0; for (Integer key : sortedCountMap.keySet()) { if (i < count) { if (!userResources.contains(key)) { resIDs.add(key); i++; } } else { break; } } resources.add(Ints.toArray(resIDs)); } return resources; }
private static List<int[]> getRandomResources(BookmarkReader reader, int count, int trainSize) { List<int[]> resources = new ArrayList<int[]>(); int resCount = reader.getResources().size(); for (int userID : reader.getUniqueUserListFromTestSet(trainSize)) { List<Integer> userResources = UserData.getResourcesFromUser(reader.getUserLines().subList(0, trainSize), userID); List<Integer> resIDs = new ArrayList<Integer>(); int i = 0; for (Integer res : Utilities.getRandomIndices(0, resCount - 1)) { if (i < count) { if (!userResources.contains(res)) { resIDs.add(res); i++; } } else { break; } } resources.add(Ints.toArray(resIDs)); } return resources; }