Search in sources :

Example 1 with TreeData

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;
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase) TreeData(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.tree.TreeData)

Example 2 with TreeData

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);
    }
}
Also used : TreeData(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.tree.TreeData) InfomapBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.infomap.InfomapBase)

Example 3 with TreeData

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);
    }
}
Also used : Config(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.io.Config) TreeData(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.tree.TreeData) InfomapBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.infomap.InfomapBase)

Aggregations

TreeData (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.tree.TreeData)3 InfomapBase (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.infomap.InfomapBase)2 NodeBase (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)1 Config (au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.io.Config)1