use of au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.tree.TreeData in project constellation by constellation-app.
the class InfomapBase method tryIndexingIteratively.
private void tryIndexingIteratively() {
if (DEBUG) {
final String log = String.format("%s.tryIndexingIteratively%n", getClass().getSimpleName());
LOGGER.log(Level.INFO, log);
}
final boolean verbose = subLevel == 0;
if (verbose) {
LOGGER.log(Level.INFO, "Finding");
}
double minHierarchicalCodelength = hierarchicalCodelength;
// Add index codebooks as long as the code gets shorter (and collapse each iteration).
boolean tryIndexing = true;
final boolean replaceExistingModules = config.getFastHierarchicalSolution() == 0;
while (tryIndexing) {
if (verbose && config.getVerbosity() > 0) {
LOGGER.log(Level.INFO, "Trying to find super modules... ");
}
final InfomapBase superInfomap = getNewInfomapInstance(config, rg);
superInfomap.reseed(NodeBase.uid());
superInfomap.subLevel = subLevel + TOP_LEVEL_ADDITION;
superInfomap.initSuperNetwork(getRoot());
superInfomap.partition();
// Break if trivial super structure.
if (superInfomap.numNonTrivialTopModules == 1 || superInfomap.getNumTopModules() == getNumTopModules()) {
if (verbose && config.getVerbosity() > 0) {
LOGGER.log(Level.INFO, "failed to find non-trivial super modules.");
}
break;
} else if (superInfomap.codelength > indexCodelength - config.getMinimumCodelengthImprovement()) {
if (verbose && config.getVerbosity() > 0) {
LOGGER.log(Level.INFO, "two-level index codebook not improved over one-level.");
}
break;
} else {
// Do nothing
}
minHierarchicalCodelength += superInfomap.codelength - indexCodelength;
if (verbose) {
if (config.getVerbosity() == 0) {
LOGGER.log(Level.INFO, "{0}", superInfomap.getNumTopModules());
} else {
final String log = String.format("succeeded. Found %d super modules with estimated hierarchical codelength %f.%n", superInfomap.getNumTopModules(), minHierarchicalCodelength);
LOGGER.log(Level.INFO, log);
}
}
// Replace current module structure with the super structure.
setActiveNetworkFromLeafs();
initModuleOptimization();
int i = 0;
for (final NodeBase node : treeData.getLeaves()) {
node.setIndex(i++);
}
// Collect the super module indices on the leaf nodes.
final TreeData superTree = superInfomap.treeData;
final Iterator<NodeBase> superLeafIt = superTree.getLeaves().iterator();
for (final NodeBase module : getRoot().getChildren()) {
final int superModuleIndex = superLeafIt.next().getParent().getIndex();
for (final NodeBase node : module.getChildren()) {
moveTo.set(node.getIndex(), superModuleIndex);
}
}
// Move the leaf nodes to the modules collected above.
moveNodesToPredefinedModules();
// Replace the old modular structure with the super structure generated above.
consolidateModules(replaceExistingModules);
tryIndexing = numNonTrivialTopModules > 1 && getNumTopModules() != getNumLeafNodes();
}
if (verbose && config.getVerbosity() == 0) {
LOGGER.log(Level.INFO, "Super modules with estimated codelength {0}", minHierarchicalCodelength);
}
hierarchicalCodelength = replaceExistingModules ? codelength : minHierarchicalCodelength;
}
use of au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.tree.TreeData in project constellation by constellation-app.
the class InfoMapMainNGTest method runInfoMap.
private static void runInfoMap(final Config config, final GraphReadMethods rg) throws FileNotFoundException {
final InfoMapContext context = new InfoMapContext(config, rg);
context.getInfoMap().run();
final InfomapBase infomap = context.getInfoMap();
final TreeData treeData = infomap.getTreeData();
System.out.printf("*Vertices %d\n", treeData.getNumLeafNodes());
for (final NodeBase node : treeData.getLeaves()) {
final int index = node.getParent().getIndex();
System.out.printf("position=%d vxId=%d cluster=%d\n", node.getOriginalIndex(), rg.getVertex(node.getOriginalIndex()), index + 1);
}
}
use of au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.tree.TreeData in project constellation by constellation-app.
the class InfoMapPlugin method edit.
@Override
protected void edit(final GraphWriteMethods wg, final PluginInteraction interaction, final PluginParameters parameters) throws InterruptedException, PluginException {
if (wg.getVertexCount() <= 0) {
interaction.notify(PluginNotificationLevel.ERROR, "The graph must have at least one vertex to run clustering on");
LOGGER.log(Level.WARNING, "{0} run on Empty Graph", Bundle.InfoMapPlugin());
return;
}
final Config config = (Config) parameters.getParameters().get(CONFIG_PARAMETER_ID).getObjectValue();
final InfoMapContext context = new InfoMapContext(config, wg);
context.getInfoMap().run();
final int clusterAttrId = ClusteringConcept.VertexAttribute.INFOMAP_CLUSTER.ensure(wg);
final InfomapBase infomap = context.getInfoMap();
final TreeData treeData = infomap.getTreeData();
LOGGER.log(Level.INFO, "Vertices {0}", treeData.getNumLeafNodes());
for (final NodeBase node : treeData.getLeaves()) {
final int index = node.getParent().getIndex();
wg.setIntValue(clusterAttrId, wg.getVertex(node.getOriginalIndex()), index + 1);
}
}
Aggregations