Skip to content

Commit

Permalink
[PYTHON][EXAMPLE] Vectorized computation of mean and residual
Browse files Browse the repository at this point in the history
  • Loading branch information
rlagneau committed May 29, 2024
1 parent d1140dc commit 1f05e09
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions modules/python/examples/ukf-nonlinear-complex-example.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def measurement_mean(measurements: List[ColVector], wm: List[float]) -> ColVecto
sumCos[j] += np.cos(measurements[i][(2*j)+1]) * wm[i]
sumSin[j] += np.sin(measurements[i][(2*j)+1]) * wm[i]

for j in range(nbLandmarks):
mean[(2*j)+1] = np.arctan2(sumSin[j], sumCos[j])
orientations = np.arctan2(sumSin, sumCos)
mean[1::2] = orientations[0::1]
return ColVector(mean)

def measurement_residual(meas: ColVector, toSubstract: ColVector) -> ColVector:
Expand All @@ -132,12 +132,8 @@ def measurement_residual(meas: ColVector, toSubstract: ColVector) -> ColVector:
@return ColVector \b meas - \b toSubstract .
"""
nbMeasures = meas.size()
nbPoints = int(nbMeasures / 2)
res = np.zeros(nbMeasures)
for i in range(nbPoints):
res[2*i] = meas[2*i] - toSubstract[2*i]
res[2*i+1] = normalize_angle(meas[2*i + 1] - toSubstract[2*i + 1])
res = meas.numpy() - toSubstract.numpy()
res[1::2] = [normalize_angle(angle) for angle in res[1::2]]
return ColVector(res)

def state_add_vectors(a: ColVector, b: ColVector) -> ColVector:
Expand Down

0 comments on commit 1f05e09

Please sign in to comment.