protected class NegativeWalkUpdate extends PositiveWalkUpdate {
@Override
public void processWalksAtVertex(WalkArray walkArray, ChiVertex<Integer, Float> vertex, DrunkardContext drunkardContext_, Random randomGenerator) {
int[] walks = ((IntWalkArray)walkArray).getArray();
IntDrunkardContext drunkardContext = (IntDrunkardContext) drunkardContext_;
// Movie vertex - do same as the positive
if (vertex.numInEdges() > 0 || drunkardContext.getIteration() > 0) {
hopToHighRatings(walks, vertex, drunkardContext, randomGenerator);
} else {
// First: if there are already walks in this vertex (due to async nature -- CLARIFY), make a separate
// list of them
ArrayList<Integer> forwardToPositive = new ArrayList<Integer>();
for(int w : walks) {
if (!drunkardContext.isWalkStartedFromVertex(w)) {
forwardToPositive.add(w);
}
}
if (forwardToPositive.size() > 0) {
int[] fwd = new int[forwardToPositive.size()];
for(int i=0; i<fwd.length; i++) fwd[i] = forwardToPositive.get(i);
hopToHighRatings(fwd, vertex, drunkardContext, randomGenerator);
}
/* Then, handle the negative cases */
ArrayList<Integer> badlyRated = new ArrayList<Integer>();
for(int i=0; i<vertex.numOutEdges(); i++) {
if (vertex.getOutEdgeValue(i) < 2) {
badlyRated.add(vertex.getOutEdgeId(i));
}
}
if (badlyRated.size() == 0) {
logger.info("No badly rated movies for user " + drunkardContext.getVertexIdTranslate().backward(vertex.getId()));
// No can do -- so no negative walks from this vertex
return;
}
for(int w : walks) {
if (drunkardContext.isWalkStartedFromVertex(w)) {
int randomBadRating = badlyRated.get(randomGenerator.nextInt(badlyRated.size()));
drunkardContext.forwardWalkTo(w, randomBadRating, true);
if (vertex.getId() == 0) {
for(int i=0; i<vertex.numOutEdges(); i++) {
if (vertex.getOutEdgeId(i) == randomBadRating) {
System.out.println("BAD ====> " + randomBadRating + "; " + vertex.getOutEdgeValue(i));