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++;
}
}
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;
}
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);
}
}
}
}
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);
}
}
}
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;
}
}
Aggregations