2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% GTSAM Copyright 2010, Georgia Tech Research Corporation,
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% Atlanta, Georgia 30332-0415
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% All Rights Reserved
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% Authors: Frank Dellaert, et al. (see THANKS for the full author list)
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% See LICENSE for the license information
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% @brief Plot visualizations of residuals, residual derivatives, and weights for the various mEstimators.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% @author Varun Agrawal
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								% import gtsam.*
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-19 08:08:10 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								close all;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								x = linspace(-10, 10, 1000);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%% Define all the mEstimator models and plot them
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								c = 1.3998;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								fairNoiseModel = gtsam.noiseModel.mEstimator.Fair(c);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								plot_m_estimator(x, fairNoiseModel, 'Fair', 1, 'fair.png')
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								c = 1.345;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								huberNoiseModel = gtsam.noiseModel.mEstimator.Huber(c);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								plot_m_estimator(x, huberNoiseModel, 'Huber', 2, 'huber.png')
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								c = 0.1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								cauchyNoiseModel = gtsam.noiseModel.mEstimator.Cauchy(c);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								plot_m_estimator(x, cauchyNoiseModel, 'Cauchy', 3, 'cauchy.png')
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								c = 1.0;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								gemanmcclureNoiseModel = gtsam.noiseModel.mEstimator.GemanMcClure(c);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								plot_m_estimator(x, gemanmcclureNoiseModel, 'Geman-McClure', 4, 'gemanmcclure.png')
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								c = 2.9846;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								welschNoiseModel = gtsam.noiseModel.mEstimator.Welsch(c);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								plot_m_estimator(x, welschNoiseModel, 'Welsch', 5, 'welsch.png')
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								c = 4.6851;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								tukeyNoiseModel = gtsam.noiseModel.mEstimator.Tukey(c);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								plot_m_estimator(x, tukeyNoiseModel, 'Tukey', 6, 'tukey.png')
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								%% Plot rho, psi and weights of the mEstimator.
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								function plot_m_estimator(x, model, plot_title, fig_id, filename)
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-19 08:08:10 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    w = zeros(size(x));
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-10 03:48:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    rho = zeros(size(x));
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-19 08:08:10 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    for i = 1:size(x, 2)
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        w(i) = model.weight(x(i));
							 | 
						
					
						
							
								
									
										
										
										
											2020-08-18 02:37:12 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								        rho(i) = model.loss(x(i));
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-19 08:08:10 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    end
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    psi = w .* x;
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    figure(fig_id);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    subplot(3, 1, 1);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-08 11:43:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    plot(x, rho, 'LineWidth',2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    title('rho function');
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    xlim([-5, 5]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    subplot(3, 1, 2);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-08 11:43:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    plot(x, psi, 'LineWidth',2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    title('influence function');
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    xlim([-5, 5]);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    subplot(3, 1, 3);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-08 11:43:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    plot(x, w, 'LineWidth',2);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    title('weight function');
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    xlim([-5, 5]);
							 | 
						
					
						
							
								
									
										
										
										
											2019-10-08 11:43:01 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								    sgtitle(plot_title, 'FontSize', 26);
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-25 00:48:38 +08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								    saveas(figure(fig_id), filename);
							 | 
						
					
						
							
								
									
										
										
										
											2019-09-19 08:08:10 +08:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								end
							 |