Here you can find the source of loadTestUserEventRelation(String eventFilePath, HashMap
Parameter | Description |
---|---|
eventFilePath | a parameter |
TestUser2EventIndexSetMap | TestUser2EventIndexSetMap[i] = {indexOf(i, j) | (i, j) \in C} |
public static int[] loadTestUserEventRelation(String eventFilePath, HashMap<Integer, LinkedList<Integer>> TestUser2EventIndexSetMap)
//package com.java2s; //License from project: Apache License import java.io.BufferedReader; import java.io.File; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.util.HashMap; import java.util.LinkedList; import java.util.List; public class Main { /**/*from w w w. j a va2 s . c o m*/ * Build TestUser2EventIndexSetMap and TestUserIndices. * * @param eventFilePath * * @param TestUser2EventIndexSetMap TestUser2EventIndexSetMap[i] = {indexOf(i, j) | (i, j) \in C} * * @return TestUserIndices TestUserIndices[k] is the user index for the k-th event */ public static int[] loadTestUserEventRelation(String eventFilePath, HashMap<Integer, LinkedList<Integer>> TestUser2EventIndexSetMap) { if (!new File(eventFilePath).exists()) { System.err.println(String.format("Event file %s doesn't exist.\n", eventFilePath)); exit(1); } BufferedReader br = null; try { br = new BufferedReader(new FileReader(eventFilePath)); } catch (FileNotFoundException e) { e.printStackTrace(); exit(1); } String line = ""; List<Double> YijList = new LinkedList<Double>(); // List<Vector> XijVectorList = new LinkedList<Vector>(); List<double[]> XijList = new LinkedList<double[]>(); List<Integer> userIdxList = new LinkedList<Integer>(); List<Integer> itemIdxList = new LinkedList<Integer>(); String[] container = null; double label = 0; int userIdx = -1; int itemIdx = -1; double gmp = 0; double freshness = 0; int eventIdx = -1; int maxUserIdx = -1; int maxItemIdx = -1; try { while ((line = br.readLine()) != null) { if (line.isEmpty()) continue; container = line.split("\t"); label = Double.parseDouble(container[0]); userIdx = Integer.parseInt(container[1]); itemIdx = Integer.parseInt(container[2]); // Modified on Oct. 16th, 2014 // { if (maxUserIdx < userIdx) maxUserIdx = userIdx; if (maxItemIdx < itemIdx) maxItemIdx = itemIdx; // } gmp = Double.parseDouble(container[3]); freshness = Double.parseDouble(container[4]); YijList.add(label); userIdxList.add(userIdx); itemIdxList.add(itemIdx); // XijVectorList.add(new DenseVector(new double[]{gmp, freshness})); XijList.add(new double[] { gmp, freshness }); eventIdx += 1; if (TestUser2EventIndexSetMap.containsKey(userIdx)) { TestUser2EventIndexSetMap.get(userIdx).add(eventIdx); } else { LinkedList<Integer> eventSet = new LinkedList<Integer>(); eventSet.add(eventIdx); TestUser2EventIndexSetMap.put(userIdx, eventSet); } } br.close(); } catch (IOException e) { e.printStackTrace(); } int eventCnt = YijList.size(); int[] TestUserIndices = new int[eventCnt]; int cnt = 0; /*cnt = 0; for (double element : YijList) { Yij[cnt++] = element; }*/ cnt = 0; for (int element : userIdxList) { TestUserIndices[cnt++] = element; } return TestUserIndices; } public static void exit(int status) { System.exit(status); } }