mirror of
https://github.com/ruvnet/ruflo.git
synced 2026-11-23 21:59:14 +09:00
Checkpoint: File edits
Automatic checkpoint created by Claude Code - Branch: rebrand/ruvflow-umbrella - Timestamp: 2026-02-08T03:37:10Z - Changes: 1 file(s) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f96065101a
commit
9e4e701725
1 file changed
+19
-1
@@ -264,6 +264,8 @@ export class MemoryGraph extends EventEmitter {
|
||||
|
||||
/**
|
||||
* Compute PageRank scores using the power iteration method.
|
||||
* Handles dangling nodes (no outgoing edges) by redistributing their
|
||||
* rank mass equally across all nodes.
|
||||
* Returns a map of node ID to PageRank score.
|
||||
*/
|
||||
computePageRank(): Map<string, number> {
|
||||
@@ -282,11 +284,26 @@ export class MemoryGraph extends EventEmitter {
|
||||
this.pageRanks.set(nodeId, initialRank);
|
||||
}
|
||||
|
||||
// Identify dangling nodes (no outgoing edges)
|
||||
const danglingNodes: string[] = [];
|
||||
for (const nodeId of this.nodes.keys()) {
|
||||
const outEdges = this.edges.get(nodeId);
|
||||
if (!outEdges || outEdges.length === 0) {
|
||||
danglingNodes.push(nodeId);
|
||||
}
|
||||
}
|
||||
|
||||
let iterations = 0;
|
||||
for (let iter = 0; iter < this.config.pageRankIterations; iter++) {
|
||||
let maxDelta = 0;
|
||||
const newRanks = new Map<string, number>();
|
||||
|
||||
// Compute dangling node rank sum for redistribution
|
||||
let danglingSum = 0;
|
||||
for (const nodeId of danglingNodes) {
|
||||
danglingSum += this.pageRanks.get(nodeId) || 0;
|
||||
}
|
||||
|
||||
for (const nodeId of this.nodes.keys()) {
|
||||
let sum = 0;
|
||||
const incoming = this.reverseEdges.get(nodeId);
|
||||
@@ -297,7 +314,8 @@ export class MemoryGraph extends EventEmitter {
|
||||
}
|
||||
}
|
||||
|
||||
const newRank = (1 - d) / N + d * sum;
|
||||
// Redistribute dangling rank mass equally
|
||||
const newRank = (1 - d) / N + d * (sum + danglingSum / N);
|
||||
newRanks.set(nodeId, newRank);
|
||||
maxDelta = Math.max(maxDelta, Math.abs(newRank - (this.pageRanks.get(nodeId) || 0)));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user