@Override public String toString() { return "ALSSpeedModel[features:" + features + ", X:(" + X.size() + " users), Y:(" + Y.size() + " items)]"; }
public void retainAllUsers(Collection<String> users) { Lock lock = xLock.writeLock(); lock.lock(); try { X.removeAll(new NotContainsPredicate<>(users)); } finally { lock.unlock(); } }
public float[] getItemVector(String item) { Lock lock = yLock.readLock(); lock.lock(); try { return Y.get(item); } finally { lock.unlock(); } }
public float[] getUserVector(String user) { Lock lock = xLock.readLock(); lock.lock(); try { return X.get(user); } finally { lock.unlock(); } }
public void retainAllItems(Collection<String> items) { Lock lock = yLock.writeLock(); lock.lock(); try { Y.removeAll(new NotContainsPredicate<>(items)); } finally { lock.unlock(); } }
public void setItemVector(String item, float[] vector) { Preconditions.checkNotNull(vector); Preconditions.checkArgument(vector.length == features); Lock lock = yLock.writeLock(); lock.lock(); try { Y.put(item, vector); } finally { lock.unlock(); } }
public void setUserVector(String user, float[] vector) { Preconditions.checkNotNull(vector); Preconditions.checkArgument(vector.length == features); Lock lock = xLock.writeLock(); lock.lock(); try { X.put(user, vector); } finally { lock.unlock(); } }
public Solver getYTYSolver() { RealMatrix YTY; Lock lock = yLock.readLock(); lock.lock(); try { YTY = VectorMath.transposeTimesSelf(Y.values()); } finally { lock.unlock(); } return new LinearSystemSolver().getSolver(YTY); }
public Solver getXTXSolver() { RealMatrix XTX; Lock lock = xLock.readLock(); lock.lock(); try { XTX = VectorMath.transposeTimesSelf(X.values()); } finally { lock.unlock(); } return new LinearSystemSolver().getSolver(XTX); }