| 
									
										
										
										
											2014-04-05 05:00:20 +08:00
										 |  |  | import gtsam.*; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | % Test GTSAM covariances on a factor graph with: | 
					
						
							|  |  |  | % Between Factors | 
					
						
							|  |  |  | % IMU factors | 
					
						
							|  |  |  | % Projection factors | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | % Authors: Luca Carlone, David Jensen | 
					
						
							|  |  |  | % Date: 2014/4/6 | 
					
						
							| 
									
										
										
										
											2014-04-03 23:34:26 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | clc | 
					
						
							|  |  |  | clear all | 
					
						
							|  |  |  | close all | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-08 11:12:31 +08:00
										 |  |  | %% Configuration | 
					
						
							| 
									
										
										
										
											2014-04-17 04:20:10 +08:00
										 |  |  | options.useRealData = 1;           % controls whether or not to use the real data (if available) as the ground truth traj | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | options.includeBetweenFactors = 1; % if true, BetweenFactors will be added between consecutive poses | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | options.includeIMUFactors = 1;     % if true, IMU factors will be added between consecutive states (biases, poses, velocities) | 
					
						
							| 
									
										
										
										
											2014-04-17 22:09:53 +08:00
										 |  |  | options.imuFactorType = 1;         % Set to 1 or 2 to use IMU type 1 or type 2 factors (will default to type 1) | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  | options.includeCameraFactors = 0;  % not fully implemented yet | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | numberOfLandmarks = 10;            % Total number of visual landmarks, used for camera factors | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 22:09:53 +08:00
										 |  |  | options.trajectoryLength = 209;    % length of the ground truth trajectory | 
					
						
							|  |  |  | options.subsampleStep = 20;        % number of poses to skip when using real data (to reduce computation on long trajectories) | 
					
						
							| 
									
										
										
										
											2014-04-15 02:38:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 22:09:53 +08:00
										 |  |  | numMonteCarloRuns = 2;             % number of Monte Carlo runs to perform | 
					
						
							| 
									
										
										
										
											2014-04-15 02:38:20 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | %% Camera metadata | 
					
						
							|  |  |  | K = Cal3_S2(500,500,0,640/2,480/2); % Camera calibration | 
					
						
							|  |  |  | cameraMeasurementNoiseSigma = 1.0; | 
					
						
							|  |  |  | cameraMeasurementNoise = noiseModel.Isotropic.Sigma(2,cameraMeasurementNoiseSigma); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % Create landmarks | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  | if options.includeCameraFactors == 1 | 
					
						
							| 
									
										
										
										
											2014-04-15 02:38:20 +08:00
										 |  |  |   for i = 1:numberOfLandmarks | 
					
						
							|  |  |  |     gtLandmarkPoints(i) = Point3( ... | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  |       ... % uniformly distributed in the x axis along 120% of the trajectory length, starting after 15 poses | 
					
						
							|  |  |  |       [rand()*20*(options.trajectoryLength*1.2) + 15*20; ...   | 
					
						
							| 
									
										
										
										
											2014-04-16 00:12:39 +08:00
										 |  |  |       randn()*20; ...   % normally distributed in the y axis with a sigma of 20 | 
					
						
							|  |  |  |       randn()*20]);     % normally distributed in the z axis with a sigma of 20 | 
					
						
							| 
									
										
										
										
											2014-04-15 02:38:20 +08:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2014-04-11 01:26:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  | %% Imu metadata | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  | metadata.imu.epsBias = 1e-10; % was 1e-7 | 
					
						
							|  |  |  | metadata.imu.zeroBias = imuBias.ConstantBias(zeros(3,1), zeros(3,1)); | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | metadata.imu.AccelerometerSigma = 1e-3; | 
					
						
							|  |  |  | metadata.imu.GyroscopeSigma = 1e-5; | 
					
						
							|  |  |  | metadata.imu.IntegrationSigma = 1e-5; | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  | metadata.imu.BiasAccelerometerSigma = metadata.imu.epsBias; | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | metadata.imu.BiasGyroscopeSigma = metadata.imu.epsBias;   | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  | metadata.imu.BiasAccOmegaInit = metadata.imu.epsBias; | 
					
						
							|  |  |  | metadata.imu.g = [0;0;0]; | 
					
						
							|  |  |  | metadata.imu.omegaCoriolis = [0;0;0]; | 
					
						
							| 
									
										
										
										
											2014-04-16 00:12:39 +08:00
										 |  |  | noiseVel =  noiseModel.Isotropic.Sigma(3, 1e-2); % was 0.1 | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | noiseBias = noiseModel.Isotropic.Sigma(6, metadata.imu.epsBias); % between on biases | 
					
						
							|  |  |  | noisePriorBias = noiseModel.Isotropic.Sigma(6, 1e-6); | 
					
						
							| 
									
										
										
										
											2014-04-08 11:12:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 04:20:10 +08:00
										 |  |  | sigma_accel = metadata.imu.AccelerometerSigma; | 
					
						
							|  |  |  | sigma_gyro = metadata.imu.GyroscopeSigma; | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | noiseVectorAccel = sigma_accel * ones(3,1); | 
					
						
							|  |  |  | noiseVectorGyro =  sigma_gyro  * ones(3,1); | 
					
						
							| 
									
										
										
										
											2014-04-17 04:20:10 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  | %% Between metadata | 
					
						
							| 
									
										
										
										
											2014-04-18 02:11:18 +08:00
										 |  |  | sigma_ang = 1e-2;  sigma_cart = 1e-1; | 
					
						
							|  |  |  | noiseVectorPose = [sigma_ang * ones(3,1); sigma_cart * ones(3,1)]; | 
					
						
							| 
									
										
										
										
											2014-04-11 01:26:10 +08:00
										 |  |  | noisePose = noiseModel.Diagonal.Sigmas(noiseVectorPose); | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-16 00:12:39 +08:00
										 |  |  | %% Set log files | 
					
						
							|  |  |  | testName = sprintf('sa-%1.2g-sc-%1.2g',sigma_ang,sigma_cart) | 
					
						
							|  |  |  | folderName = 'results/' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  | %% Create ground truth trajectory and measurements | 
					
						
							|  |  |  | [gtValues, gtMeasurements] = imuSimulator.covarianceAnalysisCreateTrajectory(options, metadata); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% Create ground truth graph | 
					
						
							|  |  |  | % Set up noise models | 
					
						
							|  |  |  | gtNoiseModels.noisePose = noisePose; | 
					
						
							|  |  |  | gtNoiseModels.noiseVel = noiseVel; | 
					
						
							|  |  |  | gtNoiseModels.noiseBias = noiseBias; | 
					
						
							|  |  |  | gtNoiseModels.noisePriorPose = noisePose; | 
					
						
							|  |  |  | gtNoiseModels.noisePriorBias = noisePriorBias; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % Set measurement noise to 0, because this is ground truth | 
					
						
							| 
									
										
										
										
											2014-04-17 04:20:10 +08:00
										 |  |  | gtMeasurementNoise.poseNoiseVector = [0; 0; 0; 0; 0; 0;]; | 
					
						
							|  |  |  | gtMeasurementNoise.imu.accelNoiseVector = [0; 0; 0]; | 
					
						
							|  |  |  | gtMeasurementNoise.imu.gyroNoiseVector = [0; 0; 0]; | 
					
						
							|  |  |  | gtMeasurementNoise.cameraPixelNoiseVector = [0; 0]; | 
					
						
							| 
									
										
										
										
											2014-04-16 00:12:39 +08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2014-04-17 03:25:05 +08:00
										 |  |  | gtGraph = imuSimulator.covarianceAnalysisCreateFactorGraph( ... | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  |     gtMeasurements, ...     % ground truth measurements | 
					
						
							|  |  |  |     gtValues, ...           % ground truth Values | 
					
						
							|  |  |  |     gtNoiseModels, ...      % noise models to use in this graph | 
					
						
							|  |  |  |     gtMeasurementNoise, ... % noise to apply to measurements | 
					
						
							|  |  |  |     options, ...            % options for the graph (e.g. which factors to include) | 
					
						
							|  |  |  |     metadata);              % misc data necessary for factor creation | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | %% Display, printing, and plotting of ground truth | 
					
						
							| 
									
										
										
										
											2014-04-17 04:20:10 +08:00
										 |  |  | %gtGraph.print(sprintf('\nGround Truth Factor graph:\n')); | 
					
						
							|  |  |  | %gtValues.print(sprintf('\nGround Truth Values:\n  ')); | 
					
						
							| 
									
										
										
										
											2014-04-15 23:05:43 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | figure(1) | 
					
						
							|  |  |  | hold on; | 
					
						
							| 
									
										
										
										
											2014-04-15 02:38:20 +08:00
										 |  |  | plot3DPoints(gtValues); | 
					
						
							| 
									
										
										
										
											2014-04-11 10:00:07 +08:00
										 |  |  | plot3DTrajectory(gtValues, '-r', [], 1, Marginals(gtGraph, gtValues)); | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | axis equal | 
					
						
							| 
									
										
										
										
											2014-04-05 05:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 10:56:46 +08:00
										 |  |  | disp('Plotted ground truth') | 
					
						
							| 
									
										
										
										
											2014-04-11 10:00:07 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 03:01:12 +08:00
										 |  |  | %% Monte Carlo Runs | 
					
						
							| 
									
										
										
										
											2014-04-17 04:20:10 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | % Set up noise models | 
					
						
							|  |  |  | monteCarloNoiseModels.noisePose = noisePose; | 
					
						
							|  |  |  | monteCarloNoiseModels.noiseVel = noiseVel; | 
					
						
							|  |  |  | monteCarloNoiseModels.noiseBias = noiseBias; | 
					
						
							|  |  |  | monteCarloNoiseModels.noisePriorPose = noisePose; | 
					
						
							|  |  |  | monteCarloNoiseModels.noisePriorBias = noisePriorBias; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | % Set measurement noise for monte carlo runs | 
					
						
							|  |  |  | monteCarloMeasurementNoise.poseNoiseVector = noiseVectorPose; | 
					
						
							|  |  |  | monteCarloMeasurementNoise.imu.accelNoiseVector = noiseVectorAccel; | 
					
						
							|  |  |  | monteCarloMeasurementNoise.imu.gyroNoiseVector = noiseVectorGyro; | 
					
						
							|  |  |  | monteCarloMeasurementNoise.cameraPixelNoiseVector = [0; 0]; | 
					
						
							|  |  |  |    | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | for k=1:numMonteCarloRuns | 
					
						
							| 
									
										
										
										
											2014-04-08 11:12:31 +08:00
										 |  |  |   fprintf('Monte Carlo Run %d.\n', k'); | 
					
						
							| 
									
										
										
										
											2014-04-17 03:25:05 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-17 04:20:10 +08:00
										 |  |  |   % Create a new graph using noisy measurements | 
					
						
							|  |  |  |   graph = imuSimulator.covarianceAnalysisCreateFactorGraph( ... | 
					
						
							|  |  |  |     gtMeasurements, ...     % ground truth measurements | 
					
						
							|  |  |  |     gtValues, ...           % ground truth Values | 
					
						
							|  |  |  |     monteCarloNoiseModels, ...      % noise models to use in this graph | 
					
						
							|  |  |  |     monteCarloMeasurementNoise, ... % noise to apply to measurements | 
					
						
							|  |  |  |     options, ...            % options for the graph (e.g. which factors to include) | 
					
						
							|  |  |  |     metadata);              % misc data necessary for factor creation | 
					
						
							| 
									
										
										
										
											2014-04-17 03:25:05 +08:00
										 |  |  |        | 
					
						
							|  |  |  |   %graph.print('graph') | 
					
						
							| 
									
										
										
										
											2014-04-16 00:12:39 +08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  |   % optimize | 
					
						
							|  |  |  |   optimizer = GaussNewtonOptimizer(graph, gtValues); | 
					
						
							|  |  |  |   estimate = optimizer.optimize(); | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  |   figure(1) | 
					
						
							|  |  |  |   plot3DTrajectory(estimate, '-b'); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   marginals = Marginals(graph, estimate); | 
					
						
							|  |  |  |    | 
					
						
							|  |  |  |   % for each pose in the trajectory | 
					
						
							| 
									
										
										
										
											2014-04-18 03:23:01 +08:00
										 |  |  |   for i=0:options.trajectoryLength | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  |     % compute estimation errors | 
					
						
							| 
									
										
										
										
											2014-04-18 03:23:01 +08:00
										 |  |  |     currentPoseKey = symbol('x', i); | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  |     gtPosition  = gtValues.at(currentPoseKey).translation.vector; | 
					
						
							|  |  |  |     estPosition = estimate.at(currentPoseKey).translation.vector; | 
					
						
							| 
									
										
										
										
											2014-04-07 23:56:22 +08:00
										 |  |  |     estR = estimate.at(currentPoseKey).rotation.matrix; | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  |     errPosition = estPosition - gtPosition; | 
					
						
							|  |  |  |      | 
					
						
							|  |  |  |     % compute covariances: | 
					
						
							|  |  |  |     cov = marginals.marginalCovariance(currentPoseKey); | 
					
						
							| 
									
										
										
										
											2014-04-07 23:56:22 +08:00
										 |  |  |     covPosition = estR * cov(4:6,4:6) * estR'; | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  |      | 
					
						
							|  |  |  |     % compute NEES using (estimationError = estimatedValues - gtValues) and estimated covariances | 
					
						
							| 
									
										
										
										
											2014-04-18 03:23:01 +08:00
										 |  |  |     NEES(k,i+1) = errPosition' * inv(covPosition) * errPosition; % distributed according to a Chi square with n = 3 dof | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  |    | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  |   figure(2) | 
					
						
							|  |  |  |   hold on | 
					
						
							|  |  |  |   plot(NEES(k,:),'-b','LineWidth',1.5) | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2014-04-07 09:43:53 +08:00
										 |  |  | %% | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | ANEES = mean(NEES); | 
					
						
							|  |  |  | plot(ANEES,'-r','LineWidth',2) | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  | plot(3*ones(size(ANEES,2),1),'k--'); % Expectation(ANEES) = number of dof | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | box on | 
					
						
							|  |  |  | set(gca,'Fontsize',16) | 
					
						
							|  |  |  | title('NEES and ANEES'); | 
					
						
							| 
									
										
										
										
											2014-04-11 10:56:46 +08:00
										 |  |  | %print('-djpeg', horzcat('runs-',testName)); | 
					
						
							|  |  |  | saveas(gcf,horzcat(folderName,'runs-',testName,'.fig'),'fig'); | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 09:43:53 +08:00
										 |  |  | %% | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | figure(1) | 
					
						
							|  |  |  | box on | 
					
						
							|  |  |  | set(gca,'Fontsize',16) | 
					
						
							| 
									
										
										
										
											2014-04-07 09:43:53 +08:00
										 |  |  | title('Ground truth and estimates for each MC runs'); | 
					
						
							| 
									
										
										
										
											2014-04-11 10:56:46 +08:00
										 |  |  | %print('-djpeg', horzcat('gt-',testName)); | 
					
						
							|  |  |  | saveas(gcf,horzcat(folderName,'gt-',testName,'.fig'),'fig'); | 
					
						
							| 
									
										
										
										
											2014-04-05 05:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | %% Let us compute statistics on the overall NEES | 
					
						
							|  |  |  | n = 3; % position vector dimension | 
					
						
							|  |  |  | N = numMonteCarloRuns; % number of runs | 
					
						
							|  |  |  | alpha = 0.01; % confidence level | 
					
						
							| 
									
										
										
										
											2014-04-03 23:34:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  | % mean_value = n*N; % mean value of the Chi-square distribution | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | % (we divide by n * N and for this reason we expect ANEES around 1) | 
					
						
							|  |  |  | r1 = chi2inv(alpha, n * N)  / (n * N); | 
					
						
							|  |  |  | r2 = chi2inv(1-alpha, n * N)  / (n * N); | 
					
						
							| 
									
										
										
										
											2014-04-03 23:34:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | % output here | 
					
						
							|  |  |  | fprintf(1, 'r1 = %g\n', r1); | 
					
						
							|  |  |  | fprintf(1, 'r2 = %g\n', r2); | 
					
						
							| 
									
										
										
										
											2014-04-03 23:34:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | figure(3) | 
					
						
							|  |  |  | hold on | 
					
						
							|  |  |  | plot(ANEES/n,'-b','LineWidth',2) | 
					
						
							|  |  |  | plot(ones(size(ANEES,2),1),'r-'); | 
					
						
							|  |  |  | plot(r1*ones(size(ANEES,2),1),'k-.'); | 
					
						
							|  |  |  | plot(r2*ones(size(ANEES,2),1),'k-.'); | 
					
						
							|  |  |  | box on | 
					
						
							|  |  |  | set(gca,'Fontsize',16) | 
					
						
							| 
									
										
										
										
											2014-04-07 09:43:53 +08:00
										 |  |  | title('NEES normalized by dof VS bounds'); | 
					
						
							| 
									
										
										
										
											2014-04-11 10:56:46 +08:00
										 |  |  | %print('-djpeg', horzcat('ANEES-',testName)); | 
					
						
							|  |  |  | saveas(gcf,horzcat(folderName,'ANEES-',testName,'.fig'),'fig'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | logFile = horzcat(folderName,'log-',testName); | 
					
						
							| 
									
										
										
										
											2014-04-18 03:23:01 +08:00
										 |  |  | %save(logFile) | 
					
						
							| 
									
										
										
										
											2014-04-03 23:34:26 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | %% NEES COMPUTATION (Bar-Shalom 2001, Section 5.4) | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  | % the nees for a single experiment (i) is defined as | 
					
						
							|  |  |  | %               NEES_i = xtilda' * inv(P) * xtilda, | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | % where xtilda in R^n is the estimation | 
					
						
							|  |  |  | % error, and P is the covariance estimated by the approach we want to test | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  | % | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | % Average NEES. Given N Monte Carlo simulations, i=1,...,N, the average | 
					
						
							|  |  |  | % NEES is: | 
					
						
							|  |  |  | %                   ANEES = sum(NEES_i)/N | 
					
						
							|  |  |  | % The quantity N*ANEES is distributed according to a Chi-square | 
					
						
							|  |  |  | % distribution with N*n degrees of freedom. | 
					
						
							|  |  |  | % | 
					
						
							| 
									
										
										
										
											2014-04-11 07:26:53 +08:00
										 |  |  | % For the single run case, N=1, therefore NEES = ANEES is distributed | 
					
						
							|  |  |  | % according to a chi-square distribution with n degrees of freedom (e.g. n=3 | 
					
						
							| 
									
										
										
										
											2014-04-07 09:05:13 +08:00
										 |  |  | % if we are testing a position estimate) | 
					
						
							|  |  |  | % Therefore its mean should be n (difficult to see from a single run) | 
					
						
							|  |  |  | % and, with probability alpha, it should hold: | 
					
						
							|  |  |  | % | 
					
						
							|  |  |  | % NEES in [r1, r2] | 
					
						
							|  |  |  | % | 
					
						
							|  |  |  | % where r1 and r2 are built from the Chi-square distribution | 
					
						
							| 
									
										
										
										
											2014-04-03 23:34:26 +08:00
										 |  |  | 
 |