Finding unique rows using "uniquetol" from top

12 ビュー (過去 30 日間)
J AI
J AI 2020 年 7 月 27 日
編集済み: Bruno Luong 2020 年 7 月 27 日
It seems like there is no option for finding unique rows from top using uniquetol unlike unique where there is option for the argument "first". Is there a way to do this
[~,idx] = uniquetol(Q2(:,1:ns),'ByRows',true,'first') % the argument "first" picks unique rows from the top
some other way, since the "first" option is not supported by uniquetol?
Thanks!
  9 件のコメント
Bruno Luong
Bruno Luong 2020 年 7 月 27 日
編集済み: Bruno Luong 2020 年 7 月 27 日
Even smaller (smallest example)
>> A = 1 + [1;0]*2^-40
A =
1.0000
1.0000
>> [Au,matlabidx] = uniquetol(A,1e-6,'byrows',true)
Au =
1
matlabidx =
2
J AI
J AI 2020 年 7 月 27 日
The data I was trying to work on is not random at all, rather it is from a well-known experiment in machine learning called the "Tiger example" often found in POMDP literature. Since several examples already have been provided by Bruno already, I am going to pass.

サインインしてコメントする。

採用された回答

Bruno Luong
Bruno Luong 2020 年 7 月 27 日
編集済み: Bruno Luong 2020 年 7 月 27 日
I suppose you can do something like this. I'm affraid the way UNIQUETOL and ISMEMBERTOL consider the TOL internally, and in some cases the result is not coherently match when the frontier is fuzzy. You might set 'DataScale' to 1 and control TOL to have more robust match.
Fake data
A = ceil(3*rand(1000,2));
A = A + rand(size(A))*1e-10;
Engine
[Au,idx] = uniquetol(A,1e-6,'DataScale',1,'byrows',true);
[tf,I] = ismembertol(A,Au,1e-6,'DataScale',1,'byrows',true);
if ~all(tf)
error('incompatible tolerance');
end
firstidx = accumarray(I,(1:size(A,1))',[],@min)
if ~all(firstidx) || size(firstidx,1)~=size(Au,1)
error('incompatible tolerance');
end
Check
A(idx,:)
A(firstidx,:)
If those matching error checking bother you, here is a way to ignore with the risk that the result might be different than UNIQUETOL alone
Au = uniquetol(A,1e-6,'DataScale',1,'byrows',true);
[tf,I] = ismembertol(A,Au,1e-6,'DataScale',1,'byrows',true);
firstidx = accumarray(I(tf),find(tf),[],@min)
Au = A(firstidx,:);
  2 件のコメント
J AI
J AI 2020 年 7 月 27 日
Thanks a lot!
Bruno Luong
Bruno Luong 2020 年 7 月 27 日
編集済み: Bruno Luong 2020 年 7 月 27 日
Actually I was stupid; you can use the third output of UNIQUETOL, no need fot ISMEMBERTOL
[Au,matlabidx,I] = uniquetol(A, 1e-6, 'byrows', true);
firstidx = accumarray(I, (1:size(A,1))', [], @min)
% Check
norm(A(matlabidx,:)-A(firstidx,:),Inf)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by