use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedUserAnalyzer method checkFriendSize.
public void checkFriendSize() {
int train = 0, test = 0;
for (_User u : m_users) {
if (u.getFriendSize() != 0)
train++;
if (u.getTestFriendSize() != 0)
test++;
}
System.out.format("[Check]%d users have train friends, %d users have test friends.\n", train, test);
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedUserAnalyzer method loadTestUserDir.
// Load users' test reviews.
public void loadTestUserDir(String folder) {
// construct the training user map first
for (_User u : m_users) {
if (!m_userMap.containsKey(u.getUserID()))
m_userMap.put(u.getUserID(), u);
else
System.err.println("[error] The user already exists in map!!");
}
if (folder == null || folder.isEmpty())
return;
File dir = new File(folder);
final File[] files = dir.listFiles();
ArrayList<Thread> threads = new ArrayList<Thread>();
for (int i = 0; i < m_numberOfCores; ++i) {
threads.add((new Thread() {
int core;
@Override
public void run() {
try {
for (int j = 0; j + core < files.length; j += m_numberOfCores) {
File f = files[j + core];
// && f.getAbsolutePath().endsWith("txt")
if (f.isFile()) {
// load the user
loadTestUserReview(f.getAbsolutePath(), core);
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
private Thread initialize(int core) {
this.core = core;
return this;
}
}).initialize(i));
threads.get(i).start();
}
for (int i = 0; i < m_numberOfCores; ++i) {
try {
threads.get(i).join();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
// process sub-directories
int count = 0;
for (File f : files) if (f.isDirectory())
loadUserDir(f.getAbsolutePath());
else
count++;
System.out.format("%d users are loaded from %s...\n", count, folder);
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedLinkPredAnalyzer method buildNonFriendship.
public void buildNonFriendship(String filename) {
System.out.println("[Info]Non-friendship file is loaded from " + filename);
HashMap<String, String[]> nonFriendMap = new HashMap<String, String[]>();
try {
File file = new File(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
analyzerOneLineNetwork(nonFriendMap, line);
}
reader.close();
System.out.format("%d users have non-friends!\n", nonFriendMap.size());
// map friends to users.
int count = 0;
for (_User u : m_users) {
if (nonFriendMap.containsKey(u.getUserID())) {
count++;
u.setNonFriends(nonFriendMap.get(u.getUserID()));
}
}
System.out.format("%d users' non-friends are set!\n", count);
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedLinkPredAnalyzer method filterFriends.
// filter the friends who are not in the list and return a neat hashmap
public HashMap<String, ArrayList<String>> filterFriends(HashMap<String, String[]> neighborsMap) {
double sum = 0;
HashMap<String, _User> userMap = new HashMap<String, _User>();
for (_User u : m_users) {
userMap.put(u.getUserID(), u);
}
HashMap<String, ArrayList<String>> frdMap = new HashMap<String, ArrayList<String>>();
for (String uid : neighborsMap.keySet()) {
if (!userMap.containsKey(uid)) {
System.out.println("The user does not exist in user set!");
continue;
}
ArrayList<String> frds = new ArrayList<>();
for (String frd : neighborsMap.get(uid)) {
if (!neighborsMap.containsKey(frd))
continue;
if (contains(neighborsMap.get(frd), uid)) {
frds.add(frd);
} else {
System.out.println("asymmetric");
}
}
if (frds.size() > 0) {
frdMap.put(uid, frds);
sum += frds.size();
}
}
System.out.format("%d users' friends are recorded, avg friends: %.2f.\n", frdMap.size(), sum / frdMap.size());
return frdMap;
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class CLinAdaptWithMMB method loadUsers.
@Override
public void loadUsers(ArrayList<_User> userList) {
m_userList = new ArrayList<_AdaptStruct>();
// Init each user.
for (_User user : userList) {
m_userList.add(new _MMBAdaptStruct(user, m_dim));
}
m_pWeights = new double[m_gWeights.length];
m_indicator = new _HDPThetaStar[m_userList.size()][m_userList.size()];
}
Aggregations