# Reorder dataset to find Sum of LSE between two data sets

1 visualizzazione (ultimi 30 giorni)
Mostafa Asheghan il 31 Mag 2022
Risposto: Vatsal il 6 Ott 2023
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.
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposte (1)

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!
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Categorie

Scopri di più su Multiobjective Optimization 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