public UserSnapshot get() {
Long2ObjectMap<MutableSparseVector> vectors = new Long2ObjectOpenHashMap<MutableSparseVector>();
Cursor<? extends UserHistory<? extends Event>> users = userEventDAO.streamEventsByUser(summarizer.eventTypeWanted());
try {
for (UserHistory<? extends Event> user: users) {
MutableSparseVector uvec = summarizer.summarize(user).mutableCopy();
vectors.put(user.getUserId(), uvec);
}
} finally {
users.close();
}
Long2ObjectMap<LongList> itemUserLists = new Long2ObjectOpenHashMap<LongList>();
LongKeyDomain domain = LongKeyDomain.fromCollection(vectors.keySet()).compactCopy(true);
assert domain.size() == domain.domainSize();
ImmutableList.Builder<ImmutableSparseVector> vecs = ImmutableList.builder();
ImmutableList.Builder<ImmutableSparseVector> nvecs = ImmutableList.builder();
for (LongIterator uiter = domain.activeSetView().iterator(); uiter.hasNext();) {
final long user = uiter.nextLong();
MutableSparseVector vec = vectors.get(user);
// save user's original vector
ImmutableSparseVector userVector = vec.immutable();
vecs.add(userVector);
// normalize user vector
normalizer.normalize(user, userVector, vec);
// and save normalized vector
nvecs.add(vec.immutable());
for (LongIterator iiter = userVector.keySet().iterator(); iiter.hasNext();) {
final long item = iiter.nextLong();
LongList itemUsers = itemUserLists.get(item);
if (itemUsers == null) {
itemUsers = new LongArrayList();