Search in sources :

Example 1 with NodeBase

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

the class InfomapBase method fineTune.

private void fineTune() {
    if (DEBUG) {
        final String log = String.format("%s.fineTune(%s)\n", getClass().getSimpleName(), getRoot());
        LOGGER.log(Level.INFO, log);
    }
    isCoarseTune = false;
    setActiveNetworkFromLeafs();
    // Init dynamic modules from existing modular structure.
    assert activeNetwork.get(0).getParent().getParent().equals(getRoot());
    int i = 0;
    for (final NodeBase leaf : treeData.getLeaves()) {
        moveTo.set(i, leaf.getParent().getIndex());
        assert moveTo.get(i) < activeNetwork.size();
        i++;
    }
    initModuleOptimization();
    moveNodesToPredefinedModules();
    mergeAndConsolidateRepeatedly();
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)

Example 2 with NodeBase

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

the class InfomapBase method runPartition.

public void runPartition() {
    hierarchicalCodelength = oneLevelCodelength;
    indexCodelength = oneLevelCodelength;
    moduleCodelength = 0;
    if (config.isTwoLevel()) {
        partition();
        hierarchicalCodelength = codelength;
        for (final NodeBase module : getRoot().getChildren()) {
            module.setCodelength(calcCodelengthFromFlowWithinOrExit(module));
        }
        return;
    }
    final PartitionQueue partitionQueue = new PartitionQueue();
    if (config.getFastHierarchicalSolution() != 0) {
        final int numLevelsCreated = findSuperModulesIterativelyFast(partitionQueue);
        // Print current hierarchical solution.
        if (config.getFastHierarchicalSolution() < 3 && hierarchicalCodelength < bestIntermediateCodelength) {
            bestIntermediateCodelength = hierarchicalCodelength;
            bestIntermediateStatistics = new StringBuilder();
            printPerLevelCodelength(bestIntermediateStatistics);
            if (config.getNetworkFile() != null) {
                printNetworkData(new File(config.getNetworkFile()).getName() + "_fast");
            }
        }
        if (config.getFastHierarchicalSolution() == 1) {
            deleteSubLevels();
            queueTopModules(partitionQueue);
        } else {
            resetModuleFlowFromLeafNodes();
            partitionQueue.setLevel(numLevelsCreated);
        }
    } else {
        partitionAndQueueNextLevel(partitionQueue);
    }
    if (config.getFastHierarchicalSolution() > 2 || partitionQueue.size() == 0) {
        return;
    }
    if (config.getVerbosity() == 0) {
        LOGGER.log(Level.INFO, "Recursive sub-structure compression: ");
    } else {
        final String log = String.format("Current codelength: %f + %f = %f%n", indexCodelength, hierarchicalCodelength - indexCodelength, hierarchicalCodelength);
        LOGGER.log(Level.INFO, log);
        LOGGER.log(Level.INFO, "Trying to find deeper structure under current modules recursively...");
    }
    double sumConsolidatedCodelength = hierarchicalCodelength - partitionQueue.getModuleCodelength();
    while (partitionQueue.size() > 0) {
        if (config.getVerbosity() > 0) {
            final String log = String.format("Level %d: %f%% of the flow in %d modules. Partitioning... ", partitionQueue.getLevel(), partitionQueue.getFlow() * 100, partitionQueue.size());
            LOGGER.log(Level.INFO, log);
        }
        final PartitionQueue nextLevelQueue = new PartitionQueue();
        // Partition all modules in the queue and fill up the next level queue.
        processPartitionQueue(partitionQueue, nextLevelQueue);
        final double leftToImprove = partitionQueue.getModuleCodelength();
        sumConsolidatedCodelength += partitionQueue.getIndexCodelength() + partitionQueue.getLeafCodelength();
        final double limitCodelength = sumConsolidatedCodelength + leftToImprove;
        if (config.getVerbosity() == 0) {
            final String formattedString = String.format(FOUR_FORMAT, ((hierarchicalCodelength - limitCodelength) / hierarchicalCodelength) * 100);
            LOGGER.log(Level.INFO, formattedString);
        } else {
            final String log = String.format("done! Codelength: %f + %f (+ %f left to improve) -> limit: %.10f bits.\n", partitionQueue.getIndexCodelength(), partitionQueue.getLeafCodelength(), leftToImprove, limitCodelength);
            LOGGER.log(Level.INFO, log);
        }
        hierarchicalCodelength = limitCodelength;
        partitionQueue.swap(nextLevelQueue);
    }
    if (config.getVerbosity() == 0) {
        LOGGER.log(Level.INFO, "to codelength {0}", hierarchicalCodelength);
    }
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase) PartitionQueue(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.PartitionQueue) File(java.io.File)

Example 3 with NodeBase

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

the class InfomapBase method deleteSubLevels.

private int deleteSubLevels() {
    NodeBase node = treeData.getFirstLeaf();
    int numLevels = 0;
    while (node.getParent() != null) {
        node = node.getParent();
        ++numLevels;
    }
    if (numLevels <= 1) {
        return 0;
    }
    if (subLevel == 0 && config.getVerbosity() > 0) {
        LOGGER.log(Level.INFO, "Clearing {0} levels of sub-modules", numLevels - 1);
    }
    // Clear all sub-modules.
    for (final NodeBase module : getRoot().getChildren()) {
        for (int i = numLevels - 1; i != 0; --i) {
            module.replaceChildrenWithGrandChildren();
        }
    }
    // Reset to leaf-level codelength terms.
    setActiveNetworkFromLeafs();
    initConstantInfomapTerms();
    resetModuleFlowFromLeafNodes();
    double sumModuleLength = 0;
    for (final NodeBase module : getRoot().getChildren()) {
        module.setCodelength(calcCodelengthFromFlowWithinOrExit(module));
        sumModuleLength += module.getCodelength();
    }
    moduleCodelength = sumModuleLength;
    hierarchicalCodelength = codelength = indexCodelength + moduleCodelength;
    if (subLevel == 0) {
        if (config.getVerbosity() == 0) {
            LOGGER.log(Level.INFO, "Clearing {0} of codelength", codelength);
        } else {
            final String formattedString = String.format("done! Two-level codelength %f + %f = %f in %d modules.\n", indexCodelength, moduleCodelength, codelength, getNumTopModules());
            LOGGER.log(Level.INFO, formattedString);
        }
    }
    return numLevels - 1;
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)

Example 4 with NodeBase

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

the class InfomapBase method mergeAndConsolidateRepeatedly.

private void mergeAndConsolidateRepeatedly(final boolean forceConsolidation, final boolean fast) {
    if (DEBUG) {
        final String log = String.format("%s.mergeAndConsolidateRepeatedly(%s,%s)%n", getClass().getSimpleName(), forceConsolidation, fast);
        LOGGER.log(Level.INFO, log);
    }
    iterationCount++;
    final boolean verbose = (subLevel == 0 && config.getVerbosity() != 0) || (isSuperLevelOnTopLevel() && config.getVerbosity() >= 3);
    // Merge and collapse repeatedly until no code improvement or only one big cluster left.
    if (verbose) {
        final String log = String.format("Iteration %d, moving %d*", iterationCount, activeNetwork.size());
        LOGGER.log(Level.INFO, log);
    }
    // Core loop, merging modules.
    int numOptimizationLoops = optimizeModules();
    if (verbose) {
        LOGGER.log(Level.INFO, "{0}", numOptimizationLoops);
    }
    // Force create modules even if worse (don't mix modules and leaf nodes under the same parent).
    consolidateModules();
    int numLevelsConsolidated = 1;
    // Reapply core algorithm on modular network, replacing modules with super modules.
    while (getNumTopModules() > 1 && numLevelsConsolidated != config.getLevelAggregationLimit()) {
        double consolidatedCodelength = codelength;
        double consolidatedIndexLength = indexCodelength;
        double consolidatedModuleLength = moduleCodelength;
        if (verbose) {
            LOGGER.log(Level.INFO, "{0}", getNumTopModules());
        }
        setActiveNetworkFromChildrenOfRoot();
        initModuleOptimization();
        numOptimizationLoops = optimizeModules();
        if (verbose) {
            LOGGER.log(Level.INFO, "{0}", numOptimizationLoops);
        }
        // If no improvement, revert codelength terms to the actual structure.
        if (codelength >= consolidatedCodelength - config.getMinimumCodelengthImprovement()) {
            indexCodelength = consolidatedIndexLength;
            moduleCodelength = consolidatedModuleLength;
            codelength = consolidatedCodelength;
            break;
        }
        consolidateModules();
        ++numLevelsConsolidated;
    }
    if (verbose) {
        final String log = String.format("%s*loops to codelength %.6f in %d modules. (%d non-trivial modules)%n", isCoarseTune ? MODULES_LABEL : "nodes", codelength, getNumTopModules(), numNonTrivialTopModules);
        LOGGER.log(Level.INFO, log);
    }
    // Set module indices from a zero-based contiguous set.
    int packedModuleIndex = 0;
    for (final NodeBase module : getRoot().getChildren()) {
        module.setOriginalIndex(packedModuleIndex++);
        module.setIndex(module.getOriginalIndex());
    }
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)

Example 5 with NodeBase

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

the class InfomapBase method printClusterVector.

private void printClusterVector(final PrintWriter out) {
    out.printf("*Vertices %d\n", treeData.getNumLeafNodes());
    int i = 0;
    for (final NodeBase node : treeData.getLeaves()) {
        final int index = node.getParent().getIndex();
        out.printf("%d %d %d\n", i++, node.getOriginalIndex(), index + 1);
    }
}
Also used : NodeBase(au.gov.asd.tac.constellation.plugins.algorithms.clustering.infomap.NodeBase)

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