Skip to content
This repository was archived by the owner on Jun 18, 2026. It is now read-only.

Commit c42945e

Browse files
fix: correct square participation counts in MotifAnalyzer (#33)
Two bugs fixed: 1. Only non-adjacent pair endpoints (u, w) received participation credit — now all four vertices of each square are tracked. 2. Participation counts were 2x too high because they weren't halved alongside squareCount. Closes #33
1 parent 8df4b07 commit c42945e

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

Gvisual/src/gvisual/MotifAnalyzer.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,22 @@ private void countSquares(List<String> vertices) {
196196
int cycles = common * (common - 1) / 2;
197197
squareCount += cycles;
198198

199-
// Participation: all 4 vertices participate
200-
addParticipation(u, "square", cycles);
201-
addParticipation(w, "square", cycles);
199+
// Track participation for all 4 vertices of each square.
200+
// For each common-neighbor pair (n1, n2) with n1 < n2,
201+
// the square is u - n1 - w - n2. All four get credit.
202+
// (#33: previously only u and w were tracked.)
203+
List<String> commonNeighbors = new ArrayList<>();
204+
for (String n : uN) {
205+
if (wN.contains(n)) commonNeighbors.add(n);
206+
}
207+
for (int a = 0; a < commonNeighbors.size(); a++) {
208+
for (int b = a + 1; b < commonNeighbors.size(); b++) {
209+
addParticipation(u, "square", 1);
210+
addParticipation(w, "square", 1);
211+
addParticipation(commonNeighbors.get(a), "square", 1);
212+
addParticipation(commonNeighbors.get(b), "square", 1);
213+
}
214+
}
202215
}
203216
}
204217
}
@@ -218,6 +231,16 @@ private void countSquares(List<String> vertices) {
218231
// Actually let's just not fix participation from the non-adjacent
219232
// pair loop — recalculate from the final count
220233
squareCount /= 2;
234+
235+
// Halve square participation counts to match corrected squareCount (#33).
236+
// Each square was found from both non-adjacent pairs, so participation
237+
// values are also 2x the true values.
238+
for (Map<String, Integer> m : vertexParticipation.values()) {
239+
Integer sq = m.get("square");
240+
if (sq != null && sq > 0) {
241+
m.put("square", sq / 2);
242+
}
243+
}
221244
}
222245

223246
// ── Star Counting ───────────────────────────────────────────────

0 commit comments

Comments
 (0)