def GNN_LG_models_2_obj_1D(): arr = lambda scalar: np.array([[scalar]]) # Prior x_prior = arr(2.5) P_prior = arr(0.36) p_prior = GaussianMixture( [Gaussian(-x_prior, P_prior), Gaussian(x_prior, P_prior)]) n = 2 # g_mix = GaussianMixture([Gaussian(-3, 0.2), Gaussian(3, 0.2)]) # p_prior = MultiGaussianMixture(g_mix) # Models # - Motion Q = arr(0.25) F = arr(1) # - Measurement R = arr(0.2) H = arr(1) PD = 0.85 # - Clutter lamb = 0.3 # Measurements Z = [-3.2, -2.4, 1.9, 2.2, 2.7, 2.9] Z = [arr(val) for val in Z] p, p_pred, theta_star = GNN_LG(p_prior, Z, n, PD, lamb, F, Q, H, R) # Plot ax = plt.subplot() res = 100 marker_size = 100 x_lim = [-4, 4] colors = ['orange', 'purple'] ax.axhline(0, color='gray', linewidth=0.5) # - Measurements plot_1D_measurements(ax, Z, color='b', marker='*', s=marker_size, zorder=3) # - Object densities plts = [] for i in range(n): # - Prior density plt1 = plot_gaussian_pdf(ax, p_prior.components[i], x_lim, res=res, color='g', zorder=1) # - Predicted density plt2 = plot_gaussian_pdf(ax, p_pred.components[i], x_lim, res=res, color='r', linestyle='--', zorder=0) # - Posterior density plt3 = plot_gaussian_pdf(ax, p.components[i], x_lim, res=res, color=colors[i], linestyle='--', zorder=2) # - Association if theta_star[i] >= len(Z): ax.scatter(p_pred.components[i].x, 0, color=colors[i], marker='o', s=marker_size, zorder=3) else: ax.scatter(Z[theta_star[i]], 0, color=colors[i], marker='*', s=marker_size, zorder=3) [plts.append(plt) for plt in [plt1, plt2, plt3]] # - Final details # ax.set_xlim(x_lim) ax.set_ylim([-0.05, 1.5]) ax.legend( plts, ('o1_prior', 'o1_pred', 'o1_GNN', 'o2_prior', 'o2_pred', 'o2_GNN')) plt.pause(0.0001)
def PDA_linear_gaussian_models_simple_scenario(): arr = lambda scalar: np.array([[scalar]]) # Prior x_prior = arr(0.5) P_prior = arr(0.2) p_prior_exact = Gaussian(x_prior, P_prior, weight=1) p_prior_PDA = Gaussian(x_prior, P_prior) # Models # - Motion Q = arr(0.35) F = arr(1) # - Measurement R = arr(0.2) H = arr(1) PD = 0.9 # - Clutter lamb = 0.4 # Sensor space = Space1D(-4, 4) # Create measurement vector Z1 = [-1.3, 1.7] Z2 = [1.3] Z3 = [-0.3, 2.3] Z4 = [-2, 3] Z5 = [2.6] Z6 = [-3.5, 2.8] Zs = [Z1, Z2, Z3, Z4, Z5, Z6] # Plot settings ax = plt.subplot() res = 100 x_lim = [space.min, space.max] # Compute exact posterior for k, Z in enumerate(Zs, start=1): print(f'Measurements: {Z}') # Compute posterior p_exact, p_pred_exact = exact_posterior_LG(p_prior_exact, Z, PD, lamb, F, Q, H, R) p_PDA, p_pred_PDA = PDA_LG(p_prior_PDA, Z, PD, lamb, F, Q, H, R) # Number of hypotesis print(f'number of hypotesis: {p_exact.n_components}') # Plot ax.clear() ax.set(title=f'k = {k}', xlabel='x') ax.axhline(0, color='gray', linewidth=0.5) # - Predicted density according to PDA plt1 = plot_gaussian_pdf(ax, p_pred_PDA, x_lim, res=res, color='r', linestyle='--', zorder=0) # - Exact posterior density plt2 = plot_gaussian_mixture_pdf(ax, p_exact, x_lim, res=res, color='k', zorder=1) # - Posterior density according to PDA plt3 = plot_gaussian_pdf(ax, p_PDA, x_lim, res=res, color='g', marker='s', zorder=2) # - Hypotesis from PDA marker_size = 100 ax.scatter(p_pred_PDA.x, 0, color='b', marker='o', s=marker_size, zorder=3) x_axis = np.zeros(len(Z)) ax.scatter(Z, x_axis, color='b', marker='*', s=marker_size, zorder=3) ax.set_xlim(x_lim) ax.set_ylim([-0.05, 1.2]) ax.legend((plt1, plt2, plt3), ('pred', 'exact', 'PDA')) p_prior_exact = p_exact p_prior_PDA = p_PDA plt.pause(0.0001) input('Press to continue')