@@ -202,8 +202,9 @@ def update_linear(
202202 lambda_multimeas ,
203203 )
204204
205- if linalg .cond (sigma_s ) > 1e10 :
206- sigma_s = sigma_s + 1e-5 * eye (sigma_s .shape [0 ])
205+ # Add jitter to sigma_s for numerical stability
206+ jitter = 1e-6 * eye (sigma_s .shape [0 ])
207+ sigma_s = sigma_s + jitter
207208
208209 x_posterior = self .x + sigma_xs @ linalg .solve (sigma_s , pseudo_meas - mu_s )
209210 self .C = self .C - sigma_xs @ linalg .solve (sigma_s , sigma_xs .T )
@@ -236,9 +237,8 @@ def calc_pseudo_meas(testPoints, measurements, kernel_width):
236237 for i in range (nTestPoints ):
237238 a_i = testPoints [:, i ]
238239 for j in range (nMeas ):
239- pseudoMeas [i ] += random .multivariate_normal .pdf (
240- a_i , mean = measurements [:, j ], cov = kernel_width * eye (measDim )
241- )
240+ gaussian_curr = GaussianDistribution (measurements [:, j ], kernel_width * eye (measDim ))
241+ pseudoMeas [i ] += gaussian_curr .pdf (a_i )
242242 return pseudoMeas
243243
244244 # pylint: disable=too-many-arguments,too-many-locals,too-many-positional-arguments,too-many-statements,too-many-branches
@@ -313,19 +313,15 @@ def calc_moments(
313313 for i in range (n_testpoints ):
314314 z = testPoints [:, i ]
315315 for k in range (n_targets ):
316- P_target [i , k ] = random .multivariate_normal .pdf (
317- z , mean = meas_means [k ], cov = meas_cov_kernel [k ]
318- )
316+ gd_curr = GaussianDistribution (meas_means [k ], meas_cov_kernel [k ])
317+ P_target [i , k ] = gd_curr .pdf (z )
319318
320319 # Clutter pdf at testpoints: N(a_i; 0, clutterCov + Gamma I)
321320 clutter_cov_kernel = clutterCov + kernel_width * I_meas
322321 clutter_pdf = empty (n_testpoints )
322+ gd_clutter = GaussianDistribution (zeros (meas_dim ), clutter_cov_kernel )
323323 for i in range (n_testpoints ):
324- clutter_pdf [i ] = random .multivariate_normal .pdf (
325- testPoints [:, i ],
326- mean = zeros (meas_dim ),
327- cov = clutter_cov_kernel ,
328- )
324+ clutter_pdf [i ] = gd_clutter .pdf (testPoints [:, i ])
329325
330326 # Mean of pseudo-measurements:
331327 # mu_s[i] = sum_l lambda_l P_l^Gamma(a_i) + lambda_c * clutter_pdf[i]
@@ -335,14 +331,11 @@ def calc_moments(
335331 # Pij[i, j, k] = P_l^{Gamma/2}((a_i + a_j)/2)
336332 Pij = zeros ((n_testpoints , n_testpoints , n_targets ))
337333 for k in range (n_targets ):
334+ gd_curr = GaussianDistribution (meas_means [k ], meas_cov_half_kernel [k ])
338335 for i in range (n_testpoints ):
339336 for j in range (n_testpoints ):
340337 midpoint = 0.5 * (testPoints [:, i ] + testPoints [:, j ])
341- Pij [i , j , k ] = random .multivariate_normal .pdf (
342- midpoint ,
343- mean = meas_means [k ],
344- cov = meas_cov_half_kernel [k ],
345- )
338+ Pij [i , j , k ] = gd_curr .pdf (midpoint )
346339
347340 # Covariance of pseudo-measurements Sigma_s
348341 sigma_s = zeros ((n_testpoints , n_testpoints ))
@@ -359,11 +352,10 @@ def calc_moments(
359352 )
360353
361354 # Gaussian kernel between test points: N(a_i; a_j, 2 Gamma I)
362- kernel_between = random .multivariate_normal .pdf (
363- testPoints [:, i ],
364- mean = testPoints [:, j ],
365- cov = 2.0 * kernel_width * I_meas ,
355+ gd_curr = GaussianDistribution (
356+ testPoints [:, j ], 2.0 * kernel_width * I_meas
366357 )
358+ kernel_between = gd_curr .pdf (testPoints [:, i ])
367359
368360 # --- term 2: kernel_between * sum_l (lambda_l^2 P_l^{Gamma/2}(midpoint)) ---
369361 term2 = kernel_between * sum (
@@ -374,11 +366,10 @@ def calc_moments(
374366 clutter_i = clutter_pdf [i ]
375367 clutter_j = clutter_pdf [j ]
376368 midpoint = 0.5 * (testPoints [:, i ] + testPoints [:, j ])
377- clutter_mid_pdf = random .multivariate_normal .pdf (
378- midpoint ,
379- mean = zeros (meas_dim ),
380- cov = clutter_cov_kernel ,
369+ gd_clutter = GaussianDistribution (
370+ zeros (meas_dim ), clutter_cov_kernel
381371 )
372+ clutter_mid_pdf = gd_clutter .pdf (midpoint )
382373
383374 term3 = (lam_c ** 2 ) * clutter_i * clutter_j
384375 term4 = mu_s [i ] * lam_c * clutter_j
0 commit comments