use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedLMAnalyzer method findtrainFriends.
public void findtrainFriends(String filename) {
_User ui, uj;
// Detect all co-purchase.
for (int i = 0; i < m_users.size(); i++) {
ui = m_users.get(i);
for (int j = i + 1; j < m_users.size(); j++) {
uj = m_users.get(j);
if (hasCoPurchase(ui, uj)) {
ui.addAmazonFriend(uj.getUserID());
uj.addAmazonFriend(ui.getUserID());
}
}
}
try {
double avg = 0, count = 0;
PrintWriter writer = new PrintWriter(new File(filename));
for (_User u : m_users) {
if (u.getAmazonFriends().size() == 0)
continue;
m_validUserMap.put(u.getUserID(), m_validUserMap.size());
count++;
avg += u.getAmazonFriends().size();
writer.write(u.getUserID() + "\t");
for (String frd : u.getAmazonFriends()) writer.write(frd + "\t");
writer.write("\n");
}
System.out.format("[Info]%.1f users have friends and avg friend size: %.2f\n", count, avg / count);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedLMAnalyzer method findTestFriends.
public void findTestFriends(String filename) {
_User ui, uj;
// Detect all co-purchase.
for (int i = 0; i < m_users.size(); i++) {
ui = m_users.get(i);
if (!m_validUserMap.containsKey(ui.getUserID()))
continue;
for (int j = i + 1; j < m_users.size(); j++) {
uj = m_users.get(j);
if (!m_validUserMap.containsKey(uj.getUserID()))
continue;
if (hasCoPurchaseInTest(ui, uj)) {
ui.addAmazonTestFriend(uj.getUserID());
uj.addAmazonTestFriend(ui.getUserID());
}
}
}
try {
double avg = 0, count = 0;
PrintWriter writer = new PrintWriter(new File(filename));
for (_User u : m_users) {
if (u.getAmazonTestFriends().size() == 0)
continue;
count++;
avg += u.getAmazonFriends().size();
writer.write(u.getUserID() + "\t");
for (String frd : u.getAmazonFriends()) writer.write(frd + "\t");
writer.write("\n");
}
System.out.format("[Info]%.1f users have friends in test set and avg test friend size: %.2f\n", count, avg / count);
writer.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedNetworkAnalyzer method calcEdgeStat4LightMediumHeavy.
public void calcEdgeStat4LightMediumHeavy(int k1, int k2) {
int light = 0, medium = 0, heavy = 0, max = 0;
for (_User user : m_users) {
if (user.getFriends() == null)
continue;
int frdSize = user.getFriends().length;
max = Math.max(frdSize, max);
if (frdSize > k2) {
heavy++;
} else if (frdSize > k1) {
medium++;
} else
light++;
}
System.out.format("[Stat]Edges-Light: %d, Medium: %d, Heavy: %d, max: %d.\n", light, medium, heavy, max);
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedNetworkAnalyzer method saveCVIndex4TADW.
// shuffle the document index based on each user
public void saveCVIndex4TADW(String filename) {
int[] stat = new int[5];
try {
PrintWriter writer = new PrintWriter(new File(filename));
for (_User u : m_users) {
for (_Review r : u.getReviews()) {
writer.write(String.format("%s,%s,%d\n", r.getUserID(), r.getItemID(), r.getMask4CV()));
stat[r.getMask4CV()]++;
}
}
writer.close();
System.out.println("[Info]Finish writing cv index for TADW! Stat as follow:");
for (int s : stat) System.out.print(s + "\t");
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.haiku.haikudepotserver.dataobjects.auto._User in project IR_Base by Linda-sunshine.
the class MultiThreadedNetworkAnalyzer method sampleNonInteractions4OneGroup.
public void sampleNonInteractions4OneGroup(String filename, HashSet<String> uids, int time) {
ArrayList<Integer> interactions = new ArrayList<Integer>();
ArrayList<Integer> nonInteractions = new ArrayList<Integer>();
HashMap<String, HashSet<Integer>> userNonInteractionMap = new HashMap<>();
for (String uid : uids) {
int i = m_userIDIndex.get(uid);
_User ui = m_users.get(i);
interactions.clear();
nonInteractions.clear();
for (String frd : ui.getFriends()) {
interactions.add(m_userIDIndex.get(frd));
}
for (int j = 0; j < m_users.size(); j++) {
if (i == j)
continue;
if (interactions.contains(j))
continue;
nonInteractions.add(j);
}
int number = time * interactions.size();
userNonInteractionMap.put(uid, sampleNonInteractions(nonInteractions, number));
}
try {
PrintWriter writer = new PrintWriter(new File(filename));
for (String uid : userNonInteractionMap.keySet()) {
writer.write(uid + "\t");
for (int nonIdx : userNonInteractionMap.get(uid)) {
String nonId = m_users.get(nonIdx).getUserID();
writer.write(nonId + "\t");
}
writer.write("\n");
}
writer.close();
System.out.format("[Stat]%d users' non-interactions are written in %s.\n", uids.size(), filename);
} catch (IOException e) {
e.printStackTrace();
}
}
Aggregations