Reorder dataset to find Sum of LSE between two data sets

1 visualizzazione (ultimi 30 giorni)
Hi,
Assume I have two datasets, each one containing 5000 samples, and each sample has three dimensions. I am looking for a way to "reorder" the samples in one (or probably both) dataset such that the sum of least square error between these two data sets be minimum.
Please see the attached photo for clarification.
Thanks.

Risposte (1)

Vatsal
Vatsal il 6 Ott 2023
Hi,
I understand that you have two datasets, each consisting of 5000 samples, and each sample has three dimensions. The objective is to rearrange the samples, in order to minimize the sum of the least square errors between the two datasets.
One simple solution to achieve this is by generating all possible permutations of the samples and then determining which ordering results in the minimum sum of least square errors. However, a more efficient approach is to utilize the "matchpairs" function in MATLAB, which is specifically designed to solve the linear assignment problem.
I am also attaching the code below that demonstrates the usage of the "matchpairs" function: -
% Example datasets
dataset1 = rand(5000, 3); % Replace with your dataset
dataset2 = rand(5000, 3); % Replace with your dataset
distances = pdist2(dataset1, dataset2);
costUnmatched = max(distances(:)) + 1;
% Apply matchpairs to find optimal assignment
assignment = matchpairs(distances, costUnmatched);
% Reorder dataset1 based on optimal assignment
reordered_dataset1 = dataset1(assignment(:, 1), :);
You can also refer to the MATLAB documentation for "matchpairs" to obtain more information on its usage and syntax. The link is provided below: -
I hope this helps!

Categorie

Scopri di più su Statistics and Machine Learning Toolbox in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by