Package edu.cmu.graphchi.walks

Examples of edu.cmu.graphchi.walks.IntDrunkardContext


    public void processWalksAtVertex(WalkArray walkArray,
                                     ChiVertex<EmptyType, EmptyType> vertex,
                                     DrunkardContext drunkardContext_,
                                     Random randomGenerator) {
        int[] walks = ((IntWalkArray)walkArray).getArray();
        IntDrunkardContext drunkardContext = (IntDrunkardContext) drunkardContext_;
        int numWalks = walks.length;
        int numOutEdges = vertex.numOutEdges();

        // Advance each walk to a random out-edge (if any)
        if (numOutEdges > 0) {
            for(int i=0; i < numWalks; i++) {
                int walk = walks[i];

                // Reset?
                if (randomGenerator.nextDouble() < RESET_PROBABILITY) {
                    drunkardContext.resetWalk(walk, false);
                } else {
                    int nextHop  = vertex.getOutEdgeId(randomGenerator.nextInt(numOutEdges));

                    // Optimization to tell the manager that walks that have just been started
                    // need not to be tracked.
                    boolean shouldTrack = !drunkardContext.isWalkStartedFromVertex(walk);
                    drunkardContext.forwardWalkTo(walk, nextHop, shouldTrack);
                }
            }

        } else {
            // Reset all walks -- no where to go from here
            for(int i=0; i < numWalks; i++) {
                drunkardContext.resetWalk(walks[i], false);
            }
        }
    }
View Full Code Here


    public void processWalksAtVertex(WalkArray walkArray,
                                     ChiVertex<EmptyType, EmptyType> vertex,
                                     DrunkardContext drunkardContext_,
                                     Random randomGenerator) {
        int[] walks = ((IntWalkArray)walkArray).getArray();
        IntDrunkardContext drunkardContext = (IntDrunkardContext) drunkardContext_;
        int numWalks = walks.length;
        int numOutEdges = vertex.numOutEdges();

        // Advance each walk to a random out-edge (if any)
        if (numOutEdges > 0) {
            for(int i=0; i < numWalks; i++) {
                int walk = walks[i];

                // Reset?
                if (randomGenerator.nextDouble() < RESET_PROBABILITY) {
                    drunkardContext.resetWalk(walk, false);
                } else {
                    int nextHop  = vertex.getOutEdgeId(randomGenerator.nextInt(numOutEdges));

                    // Optimization to tell the manager that walks that have just been started
                    // need not to be tracked.
                    boolean shouldTrack = !drunkardContext.isWalkStartedFromVertex(walk);
                    drunkardContext.forwardWalkTo(walk, nextHop, shouldTrack);
                }
            }

        } else {
            // Reset all walks -- no where to go from here
            for(int i=0; i < numWalks; i++) {
                drunkardContext.resetWalk(walks[i], false);
            }
        }
    }
View Full Code Here

    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));
View Full Code Here

TOP

Related Classes of edu.cmu.graphchi.walks.IntDrunkardContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.