js/motifFinder/broadcastGatherFinder.js
// Finds the best partition of nodes into broadcast motifs
Finds the best partition of nodes into broadcast motifs
Finds the best partition of nodes into broadcast motifs
function findBestGroups(nodes, score) {
        var best = []; 
        var parent = [];
        for (var i = 0; i < nodes.length; i++) {
            var max = -1;
            for (var j = 0; j <= i; j++) {
                var newScore = 0;
                var ownScore = score[j][i];
                if (!!ownScore && ownScore >= context.minBroadcastGather) {
                    newScore += ownScore;
                }
                if (j > 0) {
                    newScore += best[j - 1];
                }
                if (newScore > max) {
                    max = newScore;
                    parent[i] = j - 1;
                }
            }
            best[i] = max;
        }
        var groups = [];
        var loc = nodes.length - 1;
        while (loc != -1) {
            var ploc = parent[loc];
            var groupStart = nodes[ploc + 1];
            var groupEnd = nodes[loc];
            var currScore = score[ploc + 1][loc];
            if (!!currScore && currScore >= context.minBroadcastGather) {
                groups.push([ groupStart, groupEnd ]);
            }
            loc = parent[loc];
        }
        return groups;
    }
function findBestGroups ( nodes , score ) { var best = [ ] ; var parent = [ ] ; for ( var i = 0 ; i < nodes . length ; i ++ ) { var max = - 1 ; for ( var j = 0 ; j <= i ; j ++ ) { var newScore = 0 ; var ownScore = score [ j ] [ i ] ; if ( ! ! ownScore && ownScore >= context . minBroadcastGather ) { newScore += ownScore ; } if ( j > 0 ) { newScore += best [ j - 1 ] ; } if ( newScore > max ) { max = newScore ; parent [ i ] = j - 1 ; } } best [ i ] = max ; } var groups = [ ] ; var loc = nodes . length - 1 ; while ( loc != - 1 ) { var ploc = parent [ loc ] ; var groupStart = nodes [ ploc + 1 ] ; var groupEnd = nodes [ loc ] ; var currScore = score [ ploc + 1 ] [ loc ] ; if ( ! ! currScore && currScore >= context . minBroadcastGather ) { groups . push ( [ groupStart , groupEnd ] ) ; } loc = parent [ loc ] ; } return groups ; }
Finds the best partition of nodes into broadcast motifs
Finds the best partition of nodes into broadcast motifs
// best[i] = max score using nodes 0 to i inclusive // Find max score using O(n^2) dynamic programming // dp recurrence: best[i] = max(best[j-1] + score[j][i]) for all 0<=j<=i // backtrack dp to recover the actual groups of nodes