|
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | +<head> |
| 4 | + <meta charset="UTF-8"> |
| 5 | + <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| 6 | + <title>Graph Compressor — GraphVisual</title> |
| 7 | + <link rel="stylesheet" href="styles.css"> |
| 8 | +</head> |
| 9 | +<body> |
| 10 | + |
| 11 | +<nav class="sidebar"> |
| 12 | + <a href="index.html" class="sidebar-logo"> |
| 13 | + <span>📊</span> |
| 14 | + <div> |
| 15 | + <h2>GraphVisual</h2> |
| 16 | + <small>Documentation</small> |
| 17 | + </div> |
| 18 | + </a> |
| 19 | + <div class="sidebar-section"> |
| 20 | + <div class="sidebar-section-title">Getting Started</div> |
| 21 | + <a href="index.html" class="sidebar-link"><span class="icon">🏠</span>Overview</a> |
| 22 | + <a href="guide.html" class="sidebar-link"><span class="icon">🚀</span>Setup Guide</a> |
| 23 | + </div> |
| 24 | + <div class="sidebar-section"> |
| 25 | + <div class="sidebar-section-title">Analysis</div> |
| 26 | + <a href="network-profiler.html" class="sidebar-link"><span class="icon">🔬</span>Network Profiler</a> |
| 27 | + <a href="chordal.html" class="sidebar-link"><span class="icon">🔺</span>Chordal Analysis</a> |
| 28 | + <a href="signed-graph.html" class="sidebar-link"><span class="icon">±</span>Signed Graphs</a> |
| 29 | + <a href="graph-compressor.html" class="sidebar-link active"><span class="icon">🗜️</span>Graph Compressor</a> |
| 30 | + <a href="role-classifier.html" class="sidebar-link"><span class="icon">🎭</span>Role Classifier</a> |
| 31 | + </div> |
| 32 | + <div class="sidebar-section"> |
| 33 | + <div class="sidebar-section-title">Reference</div> |
| 34 | + <a href="api.html" class="sidebar-link"><span class="icon">📖</span>API Reference</a> |
| 35 | + <a href="cookbook.html" class="sidebar-link"><span class="icon">🍳</span>Cookbook</a> |
| 36 | + </div> |
| 37 | +</nav> |
| 38 | + |
| 39 | +<div class="main"> |
| 40 | +<div class="content"> |
| 41 | + |
| 42 | +<h1>🗜️ Graph Compressor |
| 43 | + <span class="subtitle">Quotient graphs via structural equivalence, similarity, degree, attributes, and k-hop locality</span> |
| 44 | +</h1> |
| 45 | + |
| 46 | +<p><code>GraphCompressor</code> reduces a graph by merging groups of nodes into <strong>supernodes</strong>, producing a smaller <strong>quotient graph</strong> that preserves the macro-structure of the original network. Useful for visualization of large graphs, summarization, and multi-scale analysis.</p> |
| 47 | + |
| 48 | +<h2>Compression Strategies</h2> |
| 49 | + |
| 50 | +<div class="card-grid"> |
| 51 | + <div class="card"> |
| 52 | + <div class="icon">🔗</div> |
| 53 | + <h4>Structural Equivalence</h4> |
| 54 | + <p>Merges nodes with identical neighbor sets. Two nodes are structurally equivalent if they connect to exactly the same set of other nodes.</p> |
| 55 | + </div> |
| 56 | + <div class="card"> |
| 57 | + <div class="icon">📏</div> |
| 58 | + <h4>Neighborhood Similarity</h4> |
| 59 | + <p>Relaxed equivalence — merges nodes whose neighbor sets have Jaccard similarity above a threshold. Tunable from strict (1.0) to aggressive (0.3).</p> |
| 60 | + </div> |
| 61 | + <div class="card"> |
| 62 | + <div class="icon">📊</div> |
| 63 | + <h4>Degree-Based</h4> |
| 64 | + <p>Groups nodes by degree (exact or binned ranges). Useful for degree-preserving summaries.</p> |
| 65 | + </div> |
| 66 | + <div class="card"> |
| 67 | + <div class="icon">🏷️</div> |
| 68 | + <h4>Attribute-Based</h4> |
| 69 | + <p>Groups nodes by any user-supplied function — community label, node type, geographic region, etc.</p> |
| 70 | + </div> |
| 71 | + <div class="card"> |
| 72 | + <div class="icon">🎯</div> |
| 73 | + <h4>K-Hop Locality</h4> |
| 74 | + <p>Each seed node absorbs its k-hop neighborhood into a supernode. Creates region-based summaries centered on key vertices.</p> |
| 75 | + </div> |
| 76 | +</div> |
| 77 | + |
| 78 | +<h2>Quick Start</h2> |
| 79 | + |
| 80 | +<pre><code>GraphCompressor compressor = new GraphCompressor(graph); |
| 81 | + |
| 82 | +// Structural equivalence |
| 83 | +CompressionResult result = compressor.byStructuralEquivalence(); |
| 84 | +System.out.println(result.getSummary()); |
| 85 | + |
| 86 | +// Neighborhood similarity (50% overlap) |
| 87 | +CompressionResult sim = compressor.byNeighborhoodSimilarity(0.5); |
| 88 | + |
| 89 | +// Degree-based with bin size 5 |
| 90 | +CompressionResult deg = compressor.byDegree(5); |
| 91 | + |
| 92 | +// Attribute-based (e.g., by community label) |
| 93 | +Map<String, String> communities = Map.of("A", "comm1", "B", "comm1", "C", "comm2"); |
| 94 | +CompressionResult attr = compressor.byAttribute(communities::get); |
| 95 | + |
| 96 | +// K-hop locality (2 hops around seed nodes) |
| 97 | +CompressionResult khop = compressor.byKHopLocality(List.of("hub1", "hub2"), 2); |
| 98 | + |
| 99 | +// Access the compressed graph |
| 100 | +Graph<String, Edge> quotient = result.getCompressedGraph();</code></pre> |
| 101 | + |
| 102 | +<h2>Compression Result</h2> |
| 103 | + |
| 104 | +<p>Every strategy returns a <code>CompressionResult</code> with rich statistics and bidirectional mappings:</p> |
| 105 | + |
| 106 | +<pre><code>=== Graph Compression Result === |
| 107 | +Strategy: structural_equivalence |
| 108 | +Original: 500 nodes, 2340 edges |
| 109 | +Compressed: 42 nodes, 186 edges |
| 110 | +Node reduction: 91.6% |
| 111 | +Edge reduction: 92.1% |
| 112 | +Compression ratio: 0.084 |
| 113 | +Merged groups: 38 |
| 114 | +Largest supernode: 24 members |
| 115 | +Avg supernode size: 11.9</code></pre> |
| 116 | + |
| 117 | +<table> |
| 118 | + <thead> |
| 119 | + <tr><th>Method</th><th>Description</th></tr> |
| 120 | + </thead> |
| 121 | + <tbody> |
| 122 | + <tr><td><code>getCompressedGraph()</code></td><td>The quotient JUNG graph</td></tr> |
| 123 | + <tr><td><code>getSupernodeMembers()</code></td><td>Map: supernode → list of original nodes</td></tr> |
| 124 | + <tr><td><code>getNodeToSupernode()</code></td><td>Map: original node → its supernode</td></tr> |
| 125 | + <tr><td><code>getCompressionRatio()</code></td><td>Compressed/original node ratio (lower = more compression)</td></tr> |
| 126 | + <tr><td><code>getNodeReductionPercent()</code></td><td>Percentage of nodes eliminated</td></tr> |
| 127 | + <tr><td><code>getEdgeReductionPercent()</code></td><td>Percentage of edges eliminated</td></tr> |
| 128 | + <tr><td><code>getLargestSupernodeSize()</code></td><td>Number of nodes in the biggest supernode</td></tr> |
| 129 | + <tr><td><code>getMembersOf(supernodeId)</code></td><td>Look up members of a specific supernode</td></tr> |
| 130 | + <tr><td><code>getSupernodeOf(nodeId)</code></td><td>Find which supernode an original node belongs to</td></tr> |
| 131 | + <tr><td><code>toCSV()</code></td><td>Export mapping as CSV (original_node, supernode, group_size)</td></tr> |
| 132 | + <tr><td><code>getSummary()</code></td><td>Human-readable compression summary</td></tr> |
| 133 | + </tbody> |
| 134 | +</table> |
| 135 | + |
| 136 | +<h2>Compressibility Report</h2> |
| 137 | + |
| 138 | +<p>Compare all strategies at once to find the best compression approach:</p> |
| 139 | + |
| 140 | +<pre><code>String report = compressor.compressibilityReport(); |
| 141 | +System.out.println(report);</code></pre> |
| 142 | + |
| 143 | +<pre><code>=== Graph Compressibility Report === |
| 144 | +Original: 500 nodes, 2340 edges |
| 145 | + |
| 146 | + Structural Equivalence → 42 supernodes, 186 edges (91.6% node reduction, 92.1% edge reduction) |
| 147 | + Neighborhood Sim (t=0.9) → 68 supernodes, 312 edges (86.4% node reduction, 86.7% edge reduction) |
| 148 | + Neighborhood Sim (t=0.7) → 35 supernodes, 148 edges (93.0% node reduction, 93.7% edge reduction) |
| 149 | + Neighborhood Sim (t=0.5) → 21 supernodes, 89 edges (95.8% node reduction, 96.2% edge reduction) |
| 150 | + Neighborhood Sim (t=0.3) → 12 supernodes, 41 edges (97.6% node reduction, 98.2% edge reduction) |
| 151 | + Exact Degree → 28 supernodes, 1102 edges (94.4% node reduction, 52.9% edge reduction) |
| 152 | + Degree (bin=2) → 14 supernodes, 572 edges (97.2% node reduction, 75.6% edge reduction) |
| 153 | + Degree (bin=5) → 8 supernodes, 234 edges (98.4% node reduction, 90.0% edge reduction) |
| 154 | + Degree (bin=10) → 5 supernodes, 112 edges (99.0% node reduction, 95.2% edge reduction)</code></pre> |
| 155 | + |
| 156 | +<h2>Performance Notes</h2> |
| 157 | + |
| 158 | +<ul> |
| 159 | + <li><strong>Neighborhood similarity</strong> uses degree-sorted vertex ordering + upper-bound pruning: if min(|A|,|B|)/max(|A|,|B|) < threshold, the inner loop breaks early (no vertex with higher degree can match).</li> |
| 160 | + <li><strong>Jaccard computation</strong> avoids HashSet allocation — iterates the smaller set and checks membership in the larger set directly.</li> |
| 161 | + <li><strong>Superedge aggregation</strong> tracks edge count and total weight per supernode pair.</li> |
| 162 | +</ul> |
| 163 | + |
| 164 | +</div> |
| 165 | +</div> |
| 166 | + |
| 167 | +</body> |
| 168 | +</html> |
0 commit comments