Skip to content

Commit 77e44f2

Browse files
author
Alex J Lennon
committed
Fix average error calculation - was incorrectly using squared errors
- Replace incorrect error calculation that used squared errors and divided by half node count - Calculate true average linear error across all edges - Add min/max error and edge count to diagnostic logging Issue: - Old calculation: sum of squared errors / (node count * 0.5) - This gave massively inflated error values (~36km) - Was using mean squared error instead of mean error Solution: - Calculate actual error (not squared) for each edge - Sum all errors and divide by total edge count - This gives true average error in meters Results: - Error dropped from ~36,000m to ~63m - Much more realistic error reporting - Added diagnostic info: min/max error and edge count
1 parent b1d650e commit 77e44f2

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/UWB2GPSConverter.cs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,32 @@ public static void ConvertUWBToPositions(Network network, bool refine, Algorithm
354354
}
355355
}
356356

357+
// Calculate average error across all edges
357358
float totalError = 0;
358-
float total = 0;
359+
int totalEdges = 0;
360+
float maxError = 0;
361+
float minError = float.MaxValue;
362+
359363
foreach (UWB node in network.uwbs)
360364
{
361-
totalError += NodeError(node, network, nodeMap);
362-
total++;
365+
foreach (Edge edge in node.edges)
366+
{
367+
if (TryGetEndFromEdge(edge, node.id, nodeMap, out UWB? end) && end != null)
368+
{
369+
float currentDist = Vector3Extensions.Distance(node.position, end.position);
370+
float error = Math.Abs(currentDist - edge.distance);
371+
totalError += error;
372+
totalEdges++;
373+
if (error > maxError) maxError = error;
374+
if (error < minError) minError = error;
375+
}
376+
}
363377
}
364-
total *= 0.5f;
365378

366-
_logger?.LogInformation("UWB to GPS conversion completed. Updated {Updated}/{Total} positions. Average error: {Error:F2}m.",
367-
totalNodesUpdated, totalNodes, totalError / total);
379+
float averageError = totalEdges > 0 ? totalError / totalEdges : 0;
380+
381+
_logger?.LogInformation("UWB to GPS conversion completed. Updated {Updated}/{Total} positions. Average error: {Error:F2}m (min: {Min:F2}m, max: {Max:F2}m, edges: {Edges}).",
382+
totalNodesUpdated, totalNodes, averageError, minError == float.MaxValue ? 0 : minError, maxError, totalEdges);
368383
if (totalNodesUpdated + 3 < totalNodes)
369384
{
370385
var untriangulatedNodes = new List<string>();

0 commit comments

Comments
 (0)