Search in sources :

Example 21 with NodeBase

use of au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase in project constellation by constellation-app.

the class InfomapBase method printSubInfomapTree.

private void printSubInfomapTree(final PrintWriter out, final TreeData originalData, final String prefix) {
    int moduleIndex = 0;
    for (final NodeBase module : getRoot().getChildren()) {
        final String subPrefix = String.format("%s%d:", prefix, moduleIndex);
        if (module.getSubInfomap() == null) {
            int nodeIndex = 0;
            for (final NodeBase child : module.getChildren()) {
                out.printf("%s%d %s (%d)\n", subPrefix, nodeIndex, originalData.getLeafNode(child.getOriginalIndex()), child.getOriginalIndex());
                nodeIndex++;
            }
        } else {
            module.getSubInfomap().printSubInfomapTree(out, originalData, subPrefix);
        }
        moduleIndex++;
    }
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)

Example 22 with NodeBase

use of au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase in project constellation by constellation-app.

the class InfomapGreedy method calcCodelengthFromFlowWithinOrExit.

@Override
protected double calcCodelengthFromFlowWithinOrExit(final NodeBase parent) {
    final FlowBase parentData = getNode(parent).getData();
    final double parentFlow = parentData.getFlow();
    final double parentExit = parentData.getExitFlow();
    final double totalParentFlow = parentFlow + parentExit;
    if (totalParentFlow < 1e-16) {
        return 0;
    }
    double indexLength = 0;
    // For each child...
    for (final NodeBase node : parent.getChildren()) {
        indexLength -= plogp(getNode(node).getData().getFlow() / totalParentFlow);
    }
    indexLength -= plogp(parentExit / totalParentFlow);
    indexLength *= totalParentFlow;
    return indexLength;
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase) FlowBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.traits.FlowBase)

Example 23 with NodeBase

use of au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase in project constellation by constellation-app.

the class InfomapGreedy method initEnterExitFlow.

@Override
public void initEnterExitFlow() {
    if (DEBUG) {
        LOGGER.log(Level.INFO, "initEnterExitFlow() {0}", getClass().getSimpleName());
    }
    for (final NodeBase node : treeData.getLeaves()) {
        for (final Edge<NodeBase> edge : node.getOutEdges()) {
            // Possible self-links should not add to enter and exit flow in its enclosing module.
            if (!edge.isSelfPointing()) {
                // For undirected links, this automatically adds to both direction (as enterFlow = &exitFlow).
                final double sourceExitFlow = getNode(edge.getSource()).getData().getExitFlow();
                final double targetEnterFlow = getNode(edge.getTarget()).getData().getEnterFlow();
                getNode(edge.getSource()).getData().setExitFlow(sourceExitFlow + edge.getData().flow);
                getNode(edge.getTarget()).getData().setEnterFlow(targetEnterFlow + edge.getData().flow);
            }
        }
    }
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)

Example 24 with NodeBase

use of au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase in project constellation by constellation-app.

the class InfomapGreedy method resetModuleFlowFromLeafNodes.

@Override
protected void resetModuleFlowFromLeafNodes() {
    // Reset from top to bottom.
    resetModuleFlow(getRoot());
    // Aggregate from bottom to top.
    for (NodeBase node : treeData.getLeaves()) {
        final double flow = getNode(node).getData().getFlow();
        while (node.getParent() != null) {
            node = node.getParent();
            final double parentFlow = getNode(node).getData().getFlow();
            getNode(node).getData().setFlow(parentFlow + flow);
        }
    }
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)

Example 25 with NodeBase

use of au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase in project constellation by constellation-app.

the class InfomapGreedy method calculateCodelengthFromActiveNetwork.

protected void calculateCodelengthFromActiveNetwork(final boolean detailedBalance) {
    if (DEBUG) {
        final String log = String.format("%s.calculateCodelengthFromActiveNetwork(%s)%n", getClass().getSimpleName(), detailedBalance);
        LOGGER.log(Level.INFO, log);
    }
    flowLogFlow = 0;
    exitLogExit = 0;
    enterFlow = 0;
    if (detailedBalance) {
        // For each module...
        for (final NodeBase nodeBase : activeNetwork) {
            final Node node = getNode(nodeBase);
            // Own node/module codebook.
            flowLogFlow += plogp(node.getData().getFlow() + node.getData().getExitFlow());
            // Use of index codebook.
            enterFlow += node.getData().getExitFlow();
            exitLogExit += plogp(node.getData().getExitFlow());
        }
        enterFlow += exitNetworkFlow;
        enterFlowLogEnterFlow = plogp(enterFlow);
        indexCodelength = enterFlowLogEnterFlow - exitLogExit - exitNetworkFlowLogExitNetworkFlow;
        moduleCodelength = -exitLogExit + flowLogFlow - nodeFlowLogNodeFlow;
        codelength = indexCodelength + moduleCodelength;
    } else {
        enterLogEnter = 0;
        // For each module...
        for (final NodeBase nodeBase : activeNetwork) {
            final Node node = getNode(nodeBase);
            // Own node/module codebook.
            flowLogFlow += plogp(node.getData().getFlow() + node.getData().getExitFlow());
            // Use of index codebook.
            enterLogEnter += plogp(node.getData().getEnterFlow());
            exitLogExit += plogp(node.getData().getExitFlow());
            enterFlow += node.getData().getEnterFlow();
        }
        enterFlow += exitNetworkFlow;
        enterFlowLogEnterFlow = plogp(enterFlow);
        indexCodelength = enterFlowLogEnterFlow - enterLogEnter - exitNetworkFlowLogExitNetworkFlow;
        moduleCodelength = -exitLogExit + flowLogFlow - nodeFlowLogNodeFlow;
        codelength = indexCodelength + moduleCodelength;
    }
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase) Node(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.Node)

Aggregations

NodeBase (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)30 Node (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.Node)6 PartitionQueue (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.PartitionQueue)2 MultiMap (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.util.MultiMap)2 Map (java.util.Map)2 TreeMap (java.util.TreeMap)2 FlowBase (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.traits.FlowBase)1 TreeData (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.tree.TreeData)1 Tuple (au.gov.asd.tac.constellation.utilities.datastructure.Tuple)1 File (java.io.File)1