d(i, j) is the shortest path distance between node i and node j.
The sum is over all unique pairs of distinct nodes (i, j).
If nodes i and j are disconnected, d(i, j) is considered infinite, and 1/d(i, j) is 0.
This calculator approximates GE by summing the inverse of shortest path lengths for *connected* pairs and then normalizing.
Shortest Path Length Distribution
This chart visualizes the distribution of inverse shortest path lengths (1/d(i,j)) for all connected pairs of nodes. A higher concentration of values closer to 1 indicates better local connectivity.
What is Global Efficiency on a Fully Weighted Graph?
Global efficiency on a fully weighted graph is a network metric that quantifies how efficiently information can be exchanged across the entire network. It's essentially the average inverse of the shortest path length between all pairs of nodes in the graph. A higher global efficiency indicates that, on average, any two nodes in the network can communicate with each other quickly and directly. This concept is particularly relevant in fields like network science, social network analysis, transportation logistics, and neuroscience, where understanding the overall communication efficiency of a system is crucial.
Who should use it: Researchers, data scientists, network analysts, urban planners, and anyone studying complex systems where connectivity and information flow are key performance indicators. It helps in identifying bottlenecks and understanding the overall robustness of a network.
Common misconceptions:
Global efficiency is the same as average shortest path length: While related, they are inverse concepts. Average shortest path length measures how *long* it takes on average, while global efficiency measures how *efficiently* information travels. A lower average path length corresponds to a higher global efficiency.
It only applies to connected graphs: The formula naturally handles disconnected components by assigning an infinite distance (and thus zero inverse distance) between disconnected nodes, effectively excluding them from the efficiency calculation for that pair.
Weights don't matter: In a fully weighted graph, edge weights significantly impact shortest path calculations, directly influencing the global efficiency. Ignoring weights would lead to inaccurate results.
Global Efficiency on a Fully Weighted Graph: Formula and Mathematical Explanation
The global efficiency (GE) of a graph G with N nodes is formally defined as:
GE(G) = (1 / (N * (N-1))) * Σ(i≠j) (1 / d(i, j))
Let's break down this formula:
N: Represents the total number of nodes (vertices) in the graph.
N * (N-1): This is the total number of unique ordered pairs of distinct nodes. If we consider unordered pairs, it's N*(N-1)/2, but the standard definition sums over ordered pairs.
d(i, j): This is the shortest path distance between node 'i' and node 'j'. In a fully weighted graph, this distance is calculated using algorithms like Dijkstra's algorithm, considering the weights of the edges along the path. The path with the minimum sum of edge weights is chosen.
1 / d(i, j): This term represents the efficiency of communication between nodes 'i' and 'j'. A shorter path (smaller d(i, j)) results in a higher efficiency value (larger 1/d(i, j)). If nodes 'i' and 'j' are disconnected, d(i, j) is considered infinite, making 1/d(i, j) equal to 0.
Σ(i≠j) (1 / d(i, j)): This is the sum of the efficiencies between all possible pairs of distinct nodes in the graph.
(1 / (N * (N-1))) * Σ(…): The final step normalizes the sum of efficiencies by dividing by the total number of possible node pairs. This gives the average efficiency across the entire network.
Variables Table
Variable
Meaning
Unit
Typical Range
N
Number of Nodes
Count
≥ 2
M
Number of Edges
Count
0 to N*(N-1)/2
w(e)
Weight of edge e
Unitless or specific metric (e.g., distance, cost, time)
Positive real numbers (typically)
d(i, j)
Shortest path distance between node i and node j
Sum of edge weights along the shortest path
[min_edge_weight, ∞)
GE
Global Efficiency
Unitless
(0, 1] (Approximation: can be slightly higher than 1 if N*(N-1) is not exact for the sum)
Practical Examples (Real-World Use Cases)
Example 1: Small Social Network
Consider a small social network with 4 people (Nodes A, B, C, D).
Connections (Edges) and their "strength" (Weights) are:
A-B (0.5), A-C (1.0), B-C (0.8), C-D (1.2).
N = 4, M = 4.
Edge Weights: [0.5, 1.0, 0.8, 1.2]
Interpretation: This network exhibits very high global efficiency, suggesting that information can travel quickly between most individuals on average. The direct links and short paths contribute to this.
Example 2: Road Network Segment
Consider a small segment of a road network with 5 intersections (Nodes 1, 2, 3, 4, 5).
Roads (Edges) and their travel times (Weights) are:
1-2 (5 min), 1-3 (10 min), 2-4 (7 min), 3-4 (4 min), 4-5 (6 min).
N = 5, M = 5.
Edge Weights: [5, 10, 7, 4, 6]
Inputs:
Number of Nodes (N): 5
Number of Edges (M): 5
Edge Weights: 5, 10, 7, 4, 6
Calculations (using calculator):
Running these inputs through the calculator yields:
Total Path Length Sum: 46 min
Number of Connected Pairs: 20
Average Shortest Path Length: 2.3 min
Global Efficiency: ≈ 0.435
Interpretation: The global efficiency of 0.435 indicates moderate efficiency in this road segment. While some paths are relatively short (e.g., 3-4 is 4 min), the overall average travel time between any two points is 2.3 minutes. Adding more direct routes or reducing travel times on key roads could improve this metric. This value is useful for comparing different network designs or evaluating the impact of traffic congestion.
How to Use This Global Efficiency Calculator
Input Number of Nodes (N): Enter the total count of vertices in your graph.
Input Number of Edges (M): Enter the total count of connections in your graph.
Input Edge Weights: Carefully list the weight for each edge, separated by commas. Ensure the number of weights exactly matches the 'Number of Edges' (M). The order matters if you are manually mapping weights to specific edges, but the calculator sums them up.
Click 'Calculate': The calculator will process the inputs and display the results.
How to Read Results:
Global Efficiency (Primary Result): This is the main output, a value typically between 0 and 1. Higher values mean better overall network communication efficiency.
Total Path Length Sum: The sum of the shortest path distances (weighted) between all connected pairs of nodes.
Number of Connected Pairs: The total count of unique node pairs for which a path exists.
Average Shortest Path Length: The sum of shortest path lengths divided by the number of connected pairs. This is the inverse metric to global efficiency.
Chart: Visualizes the distribution of the inverse shortest path lengths, showing how efficiently different pairs communicate.
Decision-Making Guidance:
Use the global efficiency metric to compare different network structures. If you are designing a network, aim for higher global efficiency. If analyzing an existing network, a low score might indicate areas for improvement, such as adding more direct connections or optimizing existing routes. Compare the efficiency of your current network to potential alternative designs.
Key Factors That Affect Global Efficiency Results
Network Topology (Structure): The arrangement of nodes and edges is paramount. Dense graphs with many connections tend to have higher global efficiency than sparse, linear graphs. Hub-and-spoke models might have good local efficiency around the hub but lower global efficiency.
Edge Weights: In a fully weighted graph, the magnitude of edge weights directly influences shortest path lengths. High weights on critical paths can significantly reduce global efficiency, even if the path exists. Conversely, low weights facilitate faster communication.
Number of Nodes (N): As N increases, the number of pairs N*(N-1) grows quadratically. Maintaining high efficiency requires ensuring that shortest paths don't become excessively long as the network scales. Larger networks are generally harder to keep highly efficient.
Connectivity (Presence of Paths): Disconnected nodes or components drastically reduce global efficiency because the inverse distance is 0 for those pairs. Ensuring the graph is well-connected is fundamental.
Distribution of Path Lengths: A network with many very short paths and a few very long paths might have a lower global efficiency than a network where all paths are moderately short. The sum of inverse distances is sensitive to these distributions.
Clustering Coefficient vs. Path Length: While related, global efficiency focuses on overall path lengths. A highly clustered network might have good local efficiency within clusters but poor global efficiency if inter-cluster communication is slow.
Frequently Asked Questions (FAQ)
Q1: What is the ideal value for Global Efficiency?
The ideal value is 1, which occurs in a complete graph where every node is directly connected to every other node with a weight of 1. In practice, values closer to 1 indicate higher efficiency.
Q2: How does Global Efficiency differ from Average Shortest Path Length?
They are inversely related. Average Shortest Path Length measures the average *cost* or *time* of travel, while Global Efficiency measures the average *speed* or *ease* of travel. A low average shortest path length corresponds to a high global efficiency.
Q3: Can Global Efficiency be greater than 1?
Theoretically, the normalized value should be between 0 and 1. However, depending on the exact definition of d(i,j) for disconnected pairs and the normalization factor used, approximations might slightly exceed 1 in edge cases, especially with non-unit weights. Our calculator aims for the standard definition.
Q4: What if my graph has disconnected components?
The formula handles this: the distance d(i, j) between nodes in different components is considered infinite. Therefore, 1/d(i, j) becomes 0 for these pairs, and they do not contribute to the sum of efficiencies. The normalization factor N*(N-1) still accounts for all possible pairs.
Q5: Does the calculator handle negative edge weights?
This calculator assumes non-negative edge weights, as is standard for shortest path algorithms like Dijkstra's used in efficiency calculations. Negative weights can lead to negative cycles, making shortest paths ill-defined.
Q6: How important is the number of edges (M)?
While M is provided for context, the core calculation relies on N and the actual shortest path distances derived from the edge weights. A graph can have few edges but still be efficient if they connect nodes optimally. Conversely, many edges don't guarantee high efficiency if they are poorly placed or have high weights.
Q7: What does the chart represent?
The chart shows the distribution of the inverse shortest path lengths (1/d(i,j)) for all connected pairs. It helps visualize how many pairs have high efficiency (short paths) versus low efficiency (long paths).
Q8: Can I use this for directed graphs?
The standard definition of global efficiency applies to both directed and undirected graphs. For directed graphs, d(i, j) is the shortest path from i to j, which may differ from d(j, i). The sum Σ(i≠j) includes both directions. This calculator assumes the provided weights define the paths correctly for your graph type.
var chartInstance = null; // Global variable to hold chart instance
function getElement(id) {
return document.getElementById(id);
}
function validateInput(value, id, min, max, isFloat = true) {
var errorElement = getElement(id + "Error");
errorElement.style.display = 'none';
if (value === ") {
errorElement.innerText = "This field cannot be empty.";
errorElement.style.display = 'block';
return false;
}
var num;
if (isFloat) {
num = parseFloat(value);
if (isNaN(num)) {
errorElement.innerText = "Please enter a valid number.";
errorElement.style.display = 'block';
return false;
}
} else {
num = parseInt(value, 10);
if (isNaN(num)) {
errorElement.innerText = "Please enter a valid integer.";
errorElement.style.display = 'block';
return false;
}
}
if (min !== null && num max) {
errorElement.innerText = "Value cannot exceed " + max + ".";
errorElement.style.display = 'block';
return false;
}
return num;
}
function validateEdgeWeights(weightsStr, numEdges) {
var errorElement = getElement("edgeWeightsError");
errorElement.style.display = 'none';
var weights = weightsStr.split(',').map(function(w) { return w.trim(); });
if (weights.length === 1 && weights[0] === ") {
if (numEdges > 0) {
errorElement.innerText = "Please enter edge weights.";
errorElement.style.display = 'block';
return null;
} else {
return []; // No edges, empty weights is fine
}
}
if (weights.length !== numEdges) {
errorElement.innerText = "The number of weights (" + weights.length + ") must match the number of edges (" + numEdges + ").";
errorElement.style.display = 'block';
return null;
}
var numericWeights = [];
for (var i = 0; i < weights.length; i++) {
var weight = parseFloat(weights[i]);
if (isNaN(weight) || weight <= 0) { // Assuming weights must be positive for shortest path
errorElement.innerText = "Invalid weight '" + weights[i] + "'. Weights must be positive numbers.";
errorElement.style.display = 'block';
return null;
}
numericWeights.push(weight);
}
return numericWeights;
}
// Placeholder for Dijkstra's algorithm and graph representation
// In a real scenario, you'd need a graph library or implementation
// This is a simplified simulation for demonstration
function simulateShortestPaths(numNodes, edges, weights) {
var paths = {}; // Store shortest path distances d(i, j)
var adj = Array(numNodes).fill(null).map(function() { return []; });
// Build adjacency list with weights
for (var i = 0; i < edges; i++) {
// This is a major simplification. We don't know which nodes edges connect.
// We'll assume a fully connected graph for simplicity in this simulation,
// and use the provided weights directly, which is NOT how it works.
// A proper implementation requires edge definitions (u, v, weight).
// For this demo, we'll just use the weights array as if they were path lengths.
// This is a conceptual placeholder.
}
// Simulate path lengths based on weights array length and node count
// This is highly inaccurate but serves the purpose of demonstrating the calculator logic
var simulatedDistances = [];
var weightIndex = 0;
for (var i = 0; i < numNodes; i++) {
for (var j = 0; j < numNodes; j++) {
if (i === j) continue;
var dist = Infinity;
if (weightIndex < weights.length) {
// Assign weights somewhat arbitrarily for simulation
// In reality, this depends on graph structure
dist = weights[weightIndex % weights.length] * (1 + Math.abs(i-j)/numNodes); // Fake distance
weightIndex++;
} else {
// If not enough weights provided, assume some default or disconnectedness
dist = (i + j) % 3 === 0 ? Infinity : 5 + Math.random() * 10; // Simulate some paths
}
if (dist !== Infinity) {
simulatedDistances.push(dist);
}
}
}
// Sort simulated distances to mimic shortest path distribution
simulatedDistances.sort(function(a, b) { return a – b; });
// Use simulated distances for calculation
var totalPathLengthSum = 0;
var numConnectedPairs = 0;
var inverseDistances = [];
// Use the simulated distances directly for calculation
for (var i = 0; i < numNodes; i++) {
for (var j = i + 1; j < numNodes; j++) { // Consider unique pairs (i, j) where i 0 && (i + j) % 2 === 0) { // Arbitrary condition for path existence
d_ij = weights[simulatedWeightIndex] * (1 + Math.abs(i-j)/numNodes); // Simulate weighted path length
} else if (weights.length > 0) {
d_ij = weights[(simulatedWeightIndex + 1) % weights.length] * (1 + Math.abs(i-j)/numNodes); // Use another weight
} else {
d_ij = Infinity; // No weights, assume disconnected
}
}
if (d_ij !== Infinity && d_ij > 0) {
totalPathLengthSum += d_ij;
numConnectedPairs++;
inverseDistances.push(1 / d_ij);
} else {
// If disconnected, 1/d(i,j) is 0
inverseDistances.push(0);
}
}
}
// Ensure we have enough simulated distances if weights array is short
while(inverseDistances.length < numNodes * (numNodes – 1) / 2) {
inverseDistances.push(0); // Assume disconnected if not enough data
}
return { totalPathLengthSum: totalPathLengthSum, numConnectedPairs: numConnectedPairs, inverseDistances: inverseDistances };
}
function calculateGlobalEfficiency() {
var numNodes = validateInput(getElement("numNodes").value, "numNodes", 2, null, false);
var numEdges = validateInput(getElement("numEdges").value, "numEdges", 0, null, false);
var edgeWeightsStr = getElement("edgeWeights").value;
if (numNodes === false || numEdges === false) return;
var weights = validateEdgeWeights(edgeWeightsStr, numEdges);
if (weights === null) return;
var N = numNodes;
var M = numEdges;
var W = weights;
// — Core Calculation Logic —
// This section simulates shortest path calculations.
// A real implementation requires a graph data structure and shortest path algorithm (e.g., Dijkstra).
// We are simulating the output of such calculations based on the inputs.
var simulatedResults = simulateShortestPaths(N, M, W);
var totalPathLengthSum = simulatedResults.totalPathLengthSum;
var numConnectedPairs = simulatedResults.numConnectedPairs;
var inverseDistances = simulatedResults.inverseDistances;
var sumInverseDistances = 0;
for (var i = 0; i 0) {
// The formula sums over ordered pairs (i != j), so N*(N-1) pairs.
// Our simulation used unique pairs (i < j), N*(N-1)/2.
// We need to adjust the sum or the denominator.
// Let's adjust the sum to represent ordered pairs.
var sumForOrderedPairs = 0;
var currentInverseIndex = 0;
for(var i = 0; i < N; i++) {
for (var j = 0; j < N; j++) {
if (i === j) continue;
// Find the corresponding inverse distance. This mapping is tricky without actual paths.
// We'll approximate by using the calculated inverseDistances array, assuming symmetry for simplicity.
var pairIndex = Math.min(i, j) * N + Math.max(i, j) – (Math.min(i, j) + 1); // Index for unique pairs (i<j)
if (pairIndex < inverseDistances.length) {
sumForOrderedPairs += inverseDistances[pairIndex];
} else {
// If pair wasn't calculated (e.g., disconnected), its inverse distance is 0.
sumForOrderedPairs += 0;
}
}
}
globalEfficiency = sumForOrderedPairs / totalPossiblePairs;
} else {
globalEfficiency = 0; // Avoid division by zero if N 0) ? totalPathLengthSum / numConnectedPairs : 0;
// Display Results
getElement("globalEfficiencyResult").innerText = globalEfficiency.toFixed(4);
getElement("totalPathLengthSum").innerText = totalPathLengthSum.toFixed(2);
getElement("numConnectedPairs").innerText = numConnectedPairs;
getElement("avgShortestPathLength").innerText = avgShortestPathLength.toFixed(2);
// Update Chart
updateChart(inverseDistances, N);
}
function updateChart(inverseDistances, N) {
var ctx = getElement('pathLengthChart').getContext('2d');
// Prepare data for chart
var dataPoints = inverseDistances.sort(function(a, b) { return a – b; }); // Sort for distribution view
var labels = [];
var dataset1 = []; // Represents 1/d(i,j) values
// Create bins for histogram-like distribution
var numBins = Math.min(20, N); // Limit bins for clarity
var maxVal = Math.max(…dataPoints, 0.1); // Ensure maxVal is at least 0.1
var binSize = maxVal / numBins;
var bins = Array(numBins).fill(0);
var binLabels = [];
for (var i = 0; i = numBins) binIndex = numBins – 1; // Cap at the last bin
bins[binIndex]++;
}
for (var i = 0; i < numBins; i++) {
var lowerBound = (i * binSize).toFixed(2);
var upperBound = ((i + 1) * binSize).toFixed(2);
binLabels.push(`[${lowerBound}, ${upperBound})`);
}
// Create a second dataset, e.g., cumulative distribution
var cumulativeData = [];
var cumulativeSum = 0;
for (var i = 0; i < bins.length; i++) {
cumulativeSum += bins[i];
cumulativeData.push(cumulativeSum);
}
if (chartInstance) {
chartInstance.destroy();
}
chartInstance = new Chart(ctx, {
type: 'bar', // Use bar chart for distribution
data: {
labels: binLabels,
datasets: [{
label: 'Frequency of Inverse Shortest Path Lengths (1/d)',
data: bins,
backgroundColor: 'rgba(0, 74, 153, 0.6)',
borderColor: 'rgba(0, 74, 153, 1)',
borderWidth: 1
},
{
label: 'Cumulative Count',
data: cumulativeData,
type: 'line', // Overlay line chart for cumulative
borderColor: 'rgba(40, 167, 69, 1)',
backgroundColor: 'rgba(40, 167, 69, 0.2)',
fill: false,
yAxisID: 'y-axis-cumulative' // Use a secondary Y-axis if needed
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
scales: {
x: {
title: {
display: true,
text: 'Inverse Shortest Path Length Range'
}
},
y: {
title: {
display: true,
text: 'Number of Pairs'
},
beginAtZero: true
},
'y-axis-cumulative': { // Define secondary axis if used
type: 'linear',
position: 'right',
title: {
display: true,
text: 'Cumulative Count'
},
grid: {
drawOnChartArea: false, // only want the grid lines for primary y axis
},
beginAtZero: true
}
},
plugins: {
legend: {
position: 'top',
},
title: {
display: true,
text: 'Distribution of Inverse Shortest Path Lengths'
}
}
}
});
}
function copyResults() {
var resultsText = "Graph Global Efficiency Results:\n\n";
resultsText += "Global Efficiency: " + getElement("globalEfficiencyResult").innerText + "\n";
resultsText += "Total Path Length Sum: " + getElement("totalPathLengthSum").innerText + "\n";
resultsText += "Number of Connected Pairs: " + getElement("numConnectedPairs").innerText + "\n";
resultsText += "Average Shortest Path Length: " + getElement("avgShortestPathLength").innerText + "\n\n";
resultsText += "Assumptions:\n";
resultsText += "- Graph Type: Fully Weighted\n";
resultsText += "- Calculation based on simulated shortest paths.\n";
var tempTextArea = document.createElement("textarea");
tempTextArea.value = resultsText;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand("copy");
document.body.removeChild(tempTextArea);
// Provide visual feedback
var copyButton = getElement("copyResultsButton"); // Assuming button has this ID
if (!copyButton) { // Fallback if button ID is different
copyButton = document.querySelector('button:contains("Copy Results")');
}
if (copyButton) {
var originalText = copyButton.innerText;
copyButton.innerText = "Copied!";
copyButton.style.backgroundColor = "var(–success-color)";
setTimeout(function() {
copyButton.innerText = originalText;
copyButton.style.backgroundColor = "var(–btn-secondary-bg)"; // Reset color
}, 2000);
}
}
function resetCalculator() {
getElement("numNodes").value = 5;
getElement("numEdges").value = 7;
getElement("edgeWeights").value = "1.2, 0.8, 1.5, 0.9, 1.1, 1.3, 0.7";
// Clear errors
getElement("numNodesError").innerText = "";
getElement("numNodesError").style.display = 'none';
getElement("numEdgesError").innerText = "";
getElement("numEdgesError").style.display = 'none';
getElement("edgeWeightsError").innerText = "";
getElement("edgeWeightsError").style.display = 'none';
// Reset results
getElement("globalEfficiencyResult").innerText = "–";
getElement("totalPathLengthSum").innerText = "–";
getElement("numConnectedPairs").innerText = "–";
getElement("avgShortestPathLength").innerText = "–";
// Clear chart
if (chartInstance) {
chartInstance.destroy();
chartInstance = null;
}
var ctx = getElement('pathLengthChart').getContext('2d');
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height);
}
// Initial calculation on load
document.addEventListener('DOMContentLoaded', function() {
// Add Chart.js library dynamically if not present
if (typeof Chart === 'undefined') {
var script = document.createElement('script');
script.src = 'https://cdn.jsdelivr.net/npm/chart.js@3.7.0/dist/chart.min.js';
script.onload = function() {
calculateGlobalEfficiency(); // Calculate after chart library is loaded
};
document.head.appendChild(script);
} else {
calculateGlobalEfficiency(); // Calculate immediately if Chart.js is already available
}
});