Skip to content

Commit ae5c8f0

Browse files
Merge pull request #227 from AllenNeuralDynamics/seanf
Updated solver comments
2 parents 379a3db + 95bb309 commit ae5c8f0

1 file changed

Lines changed: 11 additions & 29 deletions

File tree

Rhapso/solver/global_optimization.py

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44
"""
55
GlobalOptimization iteratively refines per-tile transforms to achieve sub-pixel alignment
66
using matched point correspondences.
7-
8-
This optimized version keeps the NumPy hot path, but preserves the original global
9-
optimization behavior by syncing source-side world points back into the match graph
10-
and refreshing target-side world points from the live match graph each iteration.
117
"""
128

13-
149
class GlobalOptimization:
1510
def __init__(
1611
self,
@@ -69,13 +64,11 @@ def __init__(
6964

7065
def prepare_tile_arrays(self):
7166
"""
72-
Convert match dictionaries into NumPy arrays once.
73-
74-
The important part:
75-
_p1_l is static local source points.
76-
_p1_w is this tile's current optimized world source points.
77-
_p2_w is only a cache and must be refreshed from live matches.
78-
_weights is static match weights.
67+
Convert match dictionaries into NumPy arrays
68+
_p1_l is static local source points.
69+
_p1_w is this tile's current optimized world source points.
70+
_p2_w is only a cache and must be refreshed from live matches.
71+
_weights is static match weights.
7972
"""
8073
for tile in self.tiles:
8174
matches = tile.get("matches", [])
@@ -111,10 +104,6 @@ def prepare_tile_arrays(self):
111104
def refresh_target_arrays_from_matches(self):
112105
"""
113106
Refresh cached target-side world coordinates from the live match graph.
114-
115-
This is the critical fix. The old optimized version froze _p2_w once.
116-
That changed the global optimization because tiles no longer fit against
117-
currently updated neighbor positions.
118107
"""
119108
for tile in self.tiles:
120109
matches = tile.get("matches", [])
@@ -130,10 +119,6 @@ def refresh_target_arrays_from_matches(self):
130119
def sync_tile_array_to_matches(self, tile):
131120
"""
132121
Sync one tile's optimized source-side world coordinates back into matches.
133-
134-
This preserves the original solver behavior where match["p1"]["w"] is
135-
updated during optimization and can be seen by neighboring tiles through
136-
their match["p2"]["w"] references.
137122
"""
138123
if "_p1_w" not in tile:
139124
return
@@ -266,7 +251,6 @@ def regularize_models(self, affine, rigid):
266251
def update_cost(self, tile):
267252
"""
268253
Computes and stores average distance and weighted cost for one tile.
269-
270254
Assumes _p2_w has already been refreshed from the live match graph.
271255
"""
272256
p1_w = tile["_p1_w"]
@@ -487,14 +471,12 @@ def apply(self):
487471
def optimize_silently(self):
488472
"""
489473
Iteratively refines tile alignments until convergence or max iterations.
490-
491-
The critical global behavior is:
492-
1. refresh target arrays from the live match graph,
493-
2. fit each tile against current target positions,
494-
3. damp source positions,
495-
4. sync source positions back into the live match graph,
496-
5. average current global error,
497-
6. repeat.
474+
1. refresh target arrays from the live match graph,
475+
2. fit each tile against current target positions,
476+
3. damp source positions,
477+
4. sync source positions back into the live match graph,
478+
5. average current global error,
479+
6. repeat.
498480
"""
499481
if not self.tiles:
500482
return

0 commit comments

Comments
 (0)