How can I assign a point from a matrix to a group in another matrix

4 views (last 30 days)
I have two matrixes, randMatrix and matrix1.
matrix1 is 150x5.
randMatrix consist of matrix1 values shuffled, they're the same numbers in different order.
In column 5 of matrix1 theres 50: 1s, 50: 2, and 50: 3s. Those numbers are in group 1 the first 50 numbers in matrix1, group 2 is the next 50 numbers and group 3 the remaining 50 numbers.
Each number in randMatrix is a point.
How can I know which corresponds to which number in randMatrix corresponds to group1, group2 and group3?
Heres matrix1
https://pastebin.com/a8N0x1ym
  2 Comments
DGM
DGM on 2 May 2021
Edited: DGM on 2 May 2021
When you say the values are shuffled, is randMatrix a random permutation of matrix1's elements, or is it a random permutation of matrix1's row vectors?
When you say "Each number in randMatrix is a point" do you mean each individual element, or each row vector?
If it's a fully elementwise random permutation, I don't see how a unique mapping can be recovered unless you were in control of the process which randomized it. If it's a row-wise permutation, then it should be possible to figure out a mapping, provided the rows are unique.
Whale Chicken
Whale Chicken on 2 May 2021
When I say shuffled I mean that it’s a random permutation of matrix1 elements on both row and columns. It’s the same elements, just shuffled around. Each number in randMatrix is a point, meaning each individual element.

Sign in to comment.

Accepted Answer

DGM
DGM on 3 May 2021
Edited: DGM on 3 May 2021
The short answer is that you can't. If it's elementwise, I don't see that there is enough uniqueness between sets to determine any practial amount of mapping.
% I renamed the matrix M
% let's ignore col 5 since it's not unique anyway
A = M(1:50,1:4);
B = M(51:100,1:4);
C = M(101:150,1:4);
% these are values which are unique within each set
% i.e. after removing repeated values, this is how many would be left
% this already tells us that the intersectons are significant
um = unique(M); % 74/600 (12%) unique
ua = unique(A); % 45/200 (22.5%) unique (contains 1,3)
ub = unique(B); % 58/200 (29%) unique (contains 1,2,3)
uc = unique(C); % 53/200 (26.5%) unique (contains 2,3)
% this is how many of those values are a member of only one set
uniquetoa = numel(setdiff(setdiff(ua,ub),uc)) % 6/45 (13%)
uniquetob = numel(setdiff(setdiff(ub,ua),uc)) % 1/58 (1.7%)
uniquetoc = numel(setdiff(setdiff(uc,ub),ua)) % 8/53 (15%)
There is simply too much intersection between the sets. There are nearly two dozen unique numbers which are a member of all three sets. For instance, if you had a 1.5 in the permuted array, there would be no way to tell which set it originally came from. This intersection of sets A, B, and C constitutes a full 43% of M.
iabc = intersect(intersect(ua,ub),uc); % 23 values
miabc = ismember(M,iabc);
sum(miabc(:)) % 323/750 (43%)
If you can accept some lost information and want to recover as much of a mapping as you can, then you can probably see how far you can get:
% let's take a random permutation
Mp = M(randperm(numel(M)));
% look for membership
ia = ismember(Mp,ua);
ib = ismember(Mp,ub);
ic = ismember(Mp,uc);
% remove values which are ambiguous
% these are now maps identifying which elements
% unambiguously belong to which set
iau = ia & ~(ib | ic);
ibu = ib & ~(ia | ic);
icu = ic & ~(ib | ia);
sum(iau(:)) % 50 elements mapped
sum(ibu(:)) % 1 element mapped
sum(icu(:)) % 18 elements mapped
(50 + 1 + 18)/numel(Mp) % 9.2% mapped
<10% recovery doesn't seem very good to me.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!