use of structures._User in project IR_Base by Linda-sunshine.
the class MultiThreadedUserAnalyzer method loadUser.
// Load one file as a user here.
private void loadUser(String filename, int core) {
try {
File file = new File(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line;
// UserId is contained in the filename.
String userID = extractUserID(file.getName());
// Skip the first line since it is user name.
reader.readLine();
String productID, source, category = "";
ArrayList<_Review> reviews = new ArrayList<_Review>();
_Review review;
int ylabel;
long timestamp = 0;
while ((line = reader.readLine()) != null) {
productID = line;
synchronized (m_allocReviewLock) {
if (map.containsKey(productID))
map.put(productID, map.get(productID) + 1);
else
map.put(productID, 1);
}
// review content
source = reader.readLine();
// review category
category = reader.readLine();
ylabel = Integer.valueOf(reader.readLine());
timestamp = Long.valueOf(reader.readLine());
// Construct the new review.
if (ylabel != 3) {
ylabel = (ylabel >= 4) ? 1 : 0;
review = new _Review(m_corpus.getCollection().size(), source, ylabel, userID, productID, category, timestamp);
if (AnalyzeDoc(review, core)) {
// Create the sparse vector for the review.
reviews.add(review);
}
}
}
if (reviews.size() > 1) {
// at least one for adaptation and one for testing
synchronized (m_allocReviewLock) {
allocateReviews(reviews);
// create new user from the file.
m_users.add(new _User(userID, m_classNo, reviews));
}
} else if (reviews.size() == 1) {
// added by Lin, for those users with fewer than 2 reviews, ignore them.
review = reviews.get(0);
synchronized (m_rollbackLock) {
rollBack(Utils.revertSpVct(review.getSparse()), review.getYLabel());
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
use of structures._User in project IR_Base by Linda-sunshine.
the class UserAnalyzer method loadSVDFile.
// Added by Lin: Load the svd file to get the low dim representation of users.
public void loadSVDFile(String filename) {
try {
// Construct the <userID, user> map first.
int count = 0;
HashMap<String, double[]> IDLowDimMap = new HashMap<String, double[]>();
int skip = 3;
File file = new File(filename);
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"));
String line, userID;
String[] strs;
double[] lowDims;
// Skip the first three lines.
while (skip-- > 0) reader.readLine();
while ((line = reader.readLine()) != null) {
strs = line.split("\\s+");
userID = strs[0];
lowDims = new double[strs.length - 1];
for (int i = 1; i < strs.length; i++) lowDims[i - 1] = Double.valueOf(strs[i]);
IDLowDimMap.put(userID, lowDims);
count++;
}
// Currently, there are missing low dimension representation of users.
for (_User u : m_users) {
if (IDLowDimMap.containsKey(u.getUserID()))
u.setLowDimProfile(IDLowDimMap.get(u.getUserID()));
else {
System.out.println("[Warning]" + u.getUserID() + " : low dim profile missing.");
u.setLowDimProfile(new double[11]);
}
}
reader.close();
System.out.format("Ther are %d users and %d users' low dimension profile are loaded.\n", m_users.size(), count);
} catch (IOException e) {
e.printStackTrace();
}
}
use of structures._User in project IR_Base by Linda-sunshine.
the class IndividualSVM method loadSuperUsers.
public void loadSuperUsers(ArrayList<_User> userList) {
m_supUserList = new ArrayList<_AdaptStruct>();
for (_User user : userList) m_supUserList.add(new _AdaptStruct(user));
m_pWeights = new double[m_featureSize + 1];
}
use of structures._User in project IR_Base by Linda-sunshine.
the class CoLinAdaptWithDiffFeatureGroups method constructUserList.
@Override
void constructUserList(ArrayList<_User> userList) {
int ASize = 2 * m_dimA;
int BSize = 2 * m_dimB;
// step 1: create space
m_userList = new ArrayList<_AdaptStruct>();
for (int i = 0; i < userList.size(); i++) {
_User user = userList.get(i);
m_userList.add(new _CoLinAdaptDiffFvGroupsStruct(user, m_dimA, i, m_topK, m_dimB));
}
m_pWeights = new double[m_gWeights.length];
// huge space consumption
_CoLinAdaptDiffFvGroupsStruct.sharedA = new double[getASize()];
_CoLinAdaptDiffFvGroupsStruct.sharedB = new double[getBSize()];
// step 2: copy each user's A and B to shared A and B in _CoLinAdaptStruct
_CoLinAdaptDiffFvGroupsStruct user;
for (int i = 0; i < m_userList.size(); i++) {
user = (_CoLinAdaptDiffFvGroupsStruct) m_userList.get(i);
System.arraycopy(user.m_A, 0, _CoLinAdaptDiffFvGroupsStruct.sharedA, ASize * i, ASize);
System.arraycopy(user.m_B, 0, _CoLinAdaptDiffFvGroupsStruct.sharedB, BSize * i, BSize);
}
}
use of structures._User in project IR_Base by Linda-sunshine.
the class LinAdapt method loadUsers.
// Initialize the weights of the transformation matrix.
@Override
public void loadUsers(ArrayList<_User> userList) {
m_userList = new ArrayList<_AdaptStruct>();
for (_User user : userList) m_userList.add(new _LinAdaptStruct(user, m_dim));
m_pWeights = new double[m_gWeights.length];
}
Aggregations