Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/trackOSPAMetric for my data

trackOSPAMetric for my data

PuTI / 2025-01-13
trackOSPAMetric for my data
Matlab News

Hello. I want to use trackOSPAMetric to evaluate tracking result with artificial data. but it does not match my data. I attached the code and the error. any ideas? thank you very much for your time and attention.
clc; clear; close;
% 2DPF+3DOSPA
% Parameters
num_trajectories = 4;
num_paths = 2;
points_per_trajectory = 100;
num_clusters = 60;

% Define base paths as nearly horizontal lines
base_paths = { [linspace(0, 10, points_per_trajectory)’, 2 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 4 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 6 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 8 * ones(points_per_trajectory, 1)] };

% Initialize trajectories
trajectories = cell(1, num_trajectories);

% Generate trajectories with random deviations from base paths
for ii = 1:num_trajectories
path = base_paths{mod(ii, num_paths) + 1};
deviation = [0.01 * randn(points_per_trajectory, 1), …
0.01 * randn(points_per_trajectory, 1)];
trajectories{ii} = path + deviation;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Select trajectory for tracking
selected_traj = trajectories{1};

numParticles = 1000;
stateDimension = 4;
init_state = [selected_traj(1, 1); 0;…
selected_traj(1, 2); 0];
pf = trackingPF(@constvel, @cvmeas, init_state, …
‘StateCovariance’, 0.5 * eye(stateDimension), …
‘NumParticles’, numParticles, …
‘HasAdditiveProcessNoise’, true);

% Particle filter tracking
estimated_positions_pf = …
zeros(size(selected_traj, 1), stateDimension);
pf_tot = cell(size(selected_traj, 1),1);

estimated_positions_pf(1, 🙂 = init_state’;

pf_no_km = clone(pf);

for t = 2:size(selected_traj, 1)

[xPred_pf, PPred_pf] = predict(pf_no_km, 1);

observation = …
[selected_traj(t, 1); selected_traj(t, 2); 0];
[xCorr_km, Pcorr_km] = correct(pf, observation);
[xCorr_pf, Pcorr_pf] = correct(pf_no_km, observation);

estimated_positions_pf(t, 🙂 = xCorr_pf;
pf_tot{t} = Pcorr_pf;
end

% Plot tracking results
figure (101);
plot(selected_traj(:, 1), selected_traj(:, 2), ‘g’, …
‘DisplayName’, ‘True Trajectory’);
hold on;

plot(estimated_positions_pf(:, 1), …
estimated_positions_pf(:, 3), ‘bo-.’, …
‘DisplayName’, ‘Estimated (No KM)’);
title(‘Tracking Map’);
legend;
xlabel(‘X’);
ylabel(‘Y’);
hold off;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% OSPA metric computation
truths_mine = …
[selected_traj zeros(size(selected_traj,1),1)];

%%
% Construct the truth and tracks structs
num_timesteps = size(selected_traj, 1);
truths_cell = cell(1,num_timesteps);
tracks_PF_cell = cell(1,num_timesteps);

% Compute velocities for truth data
velocities_truth = diff(truths_mine); % Approximate velocity (forward difference)
velocities_truth = [0 0 0;velocities_truth];
for t = 1:num_timesteps

% Truth struct
truth_struct = struct();
truth_struct.PlatformID = 1;
truth_struct.Time = t; % Time step
truth_struct.Position = …
[selected_traj(t, 1); selected_traj(t, 2);0]’; % Position [x; y]
% if t < num_timesteps
truth_struct.Velocity = velocities_truth(t, :); % Velocity [vx; vy]

truths_cell{t} = truth_struct;

% Tracks struct
tracks_struct_PF = struct();
tracks_struct_PF.UpdateTime = t; % Time step
tracks_struct_PF.State = …
[estimated_positions_pf(t, :),0,0]’;%; estimated_positions_pf(t, 3);0]; % Estimated position [x; y]
tracks_struct_PF.TrackID = 1;
if t==1
tracks_struct_PF.StateCovariance = [1 0 0 0 0 0; 0 1 0 0 0 0; 0 0 1 0 0 0; 0 0 0 1 0 0; 0 0 0 0 0 0 ; 0 0 0 0 0 0 ];

else
pf_cov = [pf_tot{t};zeros(2,4)];
pf_cov2 = [pf_cov, zeros(6,2)];
tracks_struct_KM.StateCovariance = pf_cov2;
end

tracks_PF_cell{t} = tracks_struct_PF;
end

%%

tom = trackOSPAMetric;
ospa = zeros(numel(tracks_PF_cell),1);
cardOspa = zeros(numel(tracks_PF_cell),1);
locOspa = zeros(numel(tracks_PF_cell),1);

for ik = 1:numel(tracks_PF_cell)
ik
tracks_mi = tracks_PF_cell{ik}
truths_mi = truths_cell{ik}
[ospa(ik), locOspa(ik), cardOspa(ik)] = tom(tracks_mi, truths_mi);
end

%%

% Compute square error between truth and track locations

error_pf = (selected_traj(:, 1) – estimated_positions_pf(:, 1)).^2 + …
(selected_traj(:, 2) – estimated_positions_pf(:, 3)).^2;

Here is the error:
Error using assignjv
Expected COSTMATRIX to be non-NaN.

Error in fusion.internal.assignment.lapCheckCostMatrix (line 10)
validateattributes(costMatrix, {‘single’,’double’}, …

Error in assignjv (line 110)
fusion.internal.assignment.lapCheckCostMatrix(costMatrix, mfilename);

Error in fusion.internal.metrics.OSPABase/stepImpl (line 219)
optimalAssignment = assignjv(dMatrix, 2*cN);

Error in trackOSPAMetric/stepImpl (line 305)
[locOspa, cardOspa, optimalAssignment] = stepImpl@fusion.internal.metrics.OSPABase(obj, tracks, truths);

Error in OnlyPF (line 139)
[ospa(ik), locOspa(ik), cardOspa(ik)] = tom(tracks_mi, truths_mi);

>>Hello. I want to use trackOSPAMetric to evaluate tracking result with artificial data. but it does not match my data. I attached the code and the error. any ideas? thank you very much for your time and attention.
clc; clear; close;
% 2DPF+3DOSPA
% Parameters
num_trajectories = 4;
num_paths = 2;
points_per_trajectory = 100;
num_clusters = 60;

% Define base paths as nearly horizontal lines
base_paths = { [linspace(0, 10, points_per_trajectory)’, 2 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 4 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 6 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 8 * ones(points_per_trajectory, 1)] };

% Initialize trajectories
trajectories = cell(1, num_trajectories);

% Generate trajectories with random deviations from base paths
for ii = 1:num_trajectories
path = base_paths{mod(ii, num_paths) + 1};
deviation = [0.01 * randn(points_per_trajectory, 1), …
0.01 * randn(points_per_trajectory, 1)];
trajectories{ii} = path + deviation;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Select trajectory for tracking
selected_traj = trajectories{1};

numParticles = 1000;
stateDimension = 4;
init_state = [selected_traj(1, 1); 0;…
selected_traj(1, 2); 0];
pf = trackingPF(@constvel, @cvmeas, init_state, …
‘StateCovariance’, 0.5 * eye(stateDimension), …
‘NumParticles’, numParticles, …
‘HasAdditiveProcessNoise’, true);

% Particle filter tracking
estimated_positions_pf = …
zeros(size(selected_traj, 1), stateDimension);
pf_tot = cell(size(selected_traj, 1),1);

estimated_positions_pf(1, 🙂 = init_state’;

pf_no_km = clone(pf);

for t = 2:size(selected_traj, 1)

[xPred_pf, PPred_pf] = predict(pf_no_km, 1);

observation = …
[selected_traj(t, 1); selected_traj(t, 2); 0];
[xCorr_km, Pcorr_km] = correct(pf, observation);
[xCorr_pf, Pcorr_pf] = correct(pf_no_km, observation);

estimated_positions_pf(t, 🙂 = xCorr_pf;
pf_tot{t} = Pcorr_pf;
end

% Plot tracking results
figure (101);
plot(selected_traj(:, 1), selected_traj(:, 2), ‘g’, …
‘DisplayName’, ‘True Trajectory’);
hold on;

plot(estimated_positions_pf(:, 1), …
estimated_positions_pf(:, 3), ‘bo-.’, …
‘DisplayName’, ‘Estimated (No KM)’);
title(‘Tracking Map’);
legend;
xlabel(‘X’);
ylabel(‘Y’);
hold off;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% OSPA metric computation
truths_mine = …
[selected_traj zeros(size(selected_traj,1),1)];

%%
% Construct the truth and tracks structs
num_timesteps = size(selected_traj, 1);
truths_cell = cell(1,num_timesteps);
tracks_PF_cell = cell(1,num_timesteps);

% Compute velocities for truth data
velocities_truth = diff(truths_mine); % Approximate velocity (forward difference)
velocities_truth = [0 0 0;velocities_truth];
for t = 1:num_timesteps

% Truth struct
truth_struct = struct();
truth_struct.PlatformID = 1;
truth_struct.Time = t; % Time step
truth_struct.Position = …
[selected_traj(t, 1); selected_traj(t, 2);0]’; % Position [x; y]
% if t < num_timesteps
truth_struct.Velocity = velocities_truth(t, :); % Velocity [vx; vy]

truths_cell{t} = truth_struct;

% Tracks struct
tracks_struct_PF = struct();
tracks_struct_PF.UpdateTime = t; % Time step
tracks_struct_PF.State = …
[estimated_positions_pf(t, :),0,0]’;%; estimated_positions_pf(t, 3);0]; % Estimated position [x; y]
tracks_struct_PF.TrackID = 1;
if t==1
tracks_struct_PF.StateCovariance = [1 0 0 0 0 0; 0 1 0 0 0 0; 0 0 1 0 0 0; 0 0 0 1 0 0; 0 0 0 0 0 0 ; 0 0 0 0 0 0 ];

else
pf_cov = [pf_tot{t};zeros(2,4)];
pf_cov2 = [pf_cov, zeros(6,2)];
tracks_struct_KM.StateCovariance = pf_cov2;
end

tracks_PF_cell{t} = tracks_struct_PF;
end

%%

tom = trackOSPAMetric;
ospa = zeros(numel(tracks_PF_cell),1);
cardOspa = zeros(numel(tracks_PF_cell),1);
locOspa = zeros(numel(tracks_PF_cell),1);

for ik = 1:numel(tracks_PF_cell)
ik
tracks_mi = tracks_PF_cell{ik}
truths_mi = truths_cell{ik}
[ospa(ik), locOspa(ik), cardOspa(ik)] = tom(tracks_mi, truths_mi);
end

%%

% Compute square error between truth and track locations

error_pf = (selected_traj(:, 1) – estimated_positions_pf(:, 1)).^2 + …
(selected_traj(:, 2) – estimated_positions_pf(:, 3)).^2;

Here is the error:
Error using assignjv
Expected COSTMATRIX to be non-NaN.

Error in fusion.internal.assignment.lapCheckCostMatrix (line 10)
validateattributes(costMatrix, {‘single’,’double’}, …

Error in assignjv (line 110)
fusion.internal.assignment.lapCheckCostMatrix(costMatrix, mfilename);

Error in fusion.internal.metrics.OSPABase/stepImpl (line 219)
optimalAssignment = assignjv(dMatrix, 2*cN);

Error in trackOSPAMetric/stepImpl (line 305)
[locOspa, cardOspa, optimalAssignment] = stepImpl@fusion.internal.metrics.OSPABase(obj, tracks, truths);

Error in OnlyPF (line 139)
[ospa(ik), locOspa(ik), cardOspa(ik)] = tom(tracks_mi, truths_mi);

>> Hello. I want to use trackOSPAMetric to evaluate tracking result with artificial data. but it does not match my data. I attached the code and the error. any ideas? thank you very much for your time and attention.
clc; clear; close;
% 2DPF+3DOSPA
% Parameters
num_trajectories = 4;
num_paths = 2;
points_per_trajectory = 100;
num_clusters = 60;

% Define base paths as nearly horizontal lines
base_paths = { [linspace(0, 10, points_per_trajectory)’, 2 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 4 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 6 * ones(points_per_trajectory, 1)];
[linspace(0, 10, points_per_trajectory)’, 8 * ones(points_per_trajectory, 1)] };

% Initialize trajectories
trajectories = cell(1, num_trajectories);

% Generate trajectories with random deviations from base paths
for ii = 1:num_trajectories
path = base_paths{mod(ii, num_paths) + 1};
deviation = [0.01 * randn(points_per_trajectory, 1), …
0.01 * randn(points_per_trajectory, 1)];
trajectories{ii} = path + deviation;
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Select trajectory for tracking
selected_traj = trajectories{1};

numParticles = 1000;
stateDimension = 4;
init_state = [selected_traj(1, 1); 0;…
selected_traj(1, 2); 0];
pf = trackingPF(@constvel, @cvmeas, init_state, …
‘StateCovariance’, 0.5 * eye(stateDimension), …
‘NumParticles’, numParticles, …
‘HasAdditiveProcessNoise’, true);

% Particle filter tracking
estimated_positions_pf = …
zeros(size(selected_traj, 1), stateDimension);
pf_tot = cell(size(selected_traj, 1),1);

estimated_positions_pf(1, 🙂 = init_state’;

pf_no_km = clone(pf);

for t = 2:size(selected_traj, 1)

[xPred_pf, PPred_pf] = predict(pf_no_km, 1);

observation = …
[selected_traj(t, 1); selected_traj(t, 2); 0];
[xCorr_km, Pcorr_km] = correct(pf, observation);
[xCorr_pf, Pcorr_pf] = correct(pf_no_km, observation);

estimated_positions_pf(t, 🙂 = xCorr_pf;
pf_tot{t} = Pcorr_pf;
end

% Plot tracking results
figure (101);
plot(selected_traj(:, 1), selected_traj(:, 2), ‘g’, …
‘DisplayName’, ‘True Trajectory’);
hold on;

plot(estimated_positions_pf(:, 1), …
estimated_positions_pf(:, 3), ‘bo-.’, …
‘DisplayName’, ‘Estimated (No KM)’);
title(‘Tracking Map’);
legend;
xlabel(‘X’);
ylabel(‘Y’);
hold off;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% OSPA metric computation
truths_mine = …
[selected_traj zeros(size(selected_traj,1),1)];

%%
% Construct the truth and tracks structs
num_timesteps = size(selected_traj, 1);
truths_cell = cell(1,num_timesteps);
tracks_PF_cell = cell(1,num_timesteps);

% Compute velocities for truth data
velocities_truth = diff(truths_mine); % Approximate velocity (forward difference)
velocities_truth = [0 0 0;velocities_truth];
for t = 1:num_timesteps

% Truth struct
truth_struct = struct();
truth_struct.PlatformID = 1;
truth_struct.Time = t; % Time step
truth_struct.Position = …
[selected_traj(t, 1); selected_traj(t, 2);0]’; % Position [x; y]
% if t < num_timesteps
truth_struct.Velocity = velocities_truth(t, :); % Velocity [vx; vy]

truths_cell{t} = truth_struct;

% Tracks struct
tracks_struct_PF = struct();
tracks_struct_PF.UpdateTime = t; % Time step
tracks_struct_PF.State = …
[estimated_positions_pf(t, :),0,0]’;%; estimated_positions_pf(t, 3);0]; % Estimated position [x; y]
tracks_struct_PF.TrackID = 1;
if t==1
tracks_struct_PF.StateCovariance = [1 0 0 0 0 0; 0 1 0 0 0 0; 0 0 1 0 0 0; 0 0 0 1 0 0; 0 0 0 0 0 0 ; 0 0 0 0 0 0 ];

else
pf_cov = [pf_tot{t};zeros(2,4)];
pf_cov2 = [pf_cov, zeros(6,2)];
tracks_struct_KM.StateCovariance = pf_cov2;
end

tracks_PF_cell{t} = tracks_struct_PF;
end

%%

tom = trackOSPAMetric;
ospa = zeros(numel(tracks_PF_cell),1);
cardOspa = zeros(numel(tracks_PF_cell),1);
locOspa = zeros(numel(tracks_PF_cell),1);

for ik = 1:numel(tracks_PF_cell)
ik
tracks_mi = tracks_PF_cell{ik}
truths_mi = truths_cell{ik}
[ospa(ik), locOspa(ik), cardOspa(ik)] = tom(tracks_mi, truths_mi);
end

%%

% Compute square error between truth and track locations

error_pf = (selected_traj(:, 1) – estimated_positions_pf(:, 1)).^2 + …
(selected_traj(:, 2) – estimated_positions_pf(:, 3)).^2;

Here is the error:
Error using assignjv
Expected COSTMATRIX to be non-NaN.

Error in fusion.internal.assignment.lapCheckCostMatrix (line 10)
validateattributes(costMatrix, {‘single’,’double’}, …

Error in assignjv (line 110)
fusion.internal.assignment.lapCheckCostMatrix(costMatrix, mfilename);

Error in fusion.internal.metrics.OSPABase/stepImpl (line 219)
optimalAssignment = assignjv(dMatrix, 2*cN);

Error in trackOSPAMetric/stepImpl (line 305)
[locOspa, cardOspa, optimalAssignment] = stepImpl@fusion.internal.metrics.OSPABase(obj, tracks, truths);

Error in OnlyPF (line 139)
[ospa(ik), locOspa(ik), cardOspa(ik)] = tom(tracks_mi, truths_mi);

>> ospa, tracking, particle filter, sensor fusion and tracking toolbox MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

How to debug C# .NET assembly called from MATLAB?
2025-05-15

How to debug C# .NET assembly called from MATLAB?

How do I set the size of a tile from tiledlayout?
2025-05-15

How do I set the size of a tile from tiledlayout?

Communicate with worker through client
2025-05-15

Communicate with worker through client

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss