Faster and More Efficient `squareform()`

7 ビュー (過去 30 日間)
Royi Avital
Royi Avital 2019 年 10 月 2 日
編集済み: Royi Avital 2019 年 10 月 15 日
I'm using squareform(pdist(mX)) fairly often.
The problem is squareform() is so slow it makes use of pdist2(mX, mX) faster.
This is basically what squareform() does in the case above:
function [ mY ] = MySquareForm( vX )
numElements = numel(vX);
numDist = (1 + sqrt(1 + (8 * numElements))) / 2;
mY = zeros(numDist, numDist, class(vX));
mY(tril(true(numDist, numDist), -1)) = vX;
mY = mY + mY.';
end
Basically, imagine you have a symmetric matrix mX then the vector vx above is it lower tringular matrix vectorized.
Something like:
mX = randn(100, 100);
mX = mX + mX.';
mL = tril(mX, -1);
vX = mL(mL ~= 0);
If the diagonal of is zerod then one could reproduce mX from vX using MySquareForm().
Any ideas how to do the same more efficiently and faster?
  1 件のコメント
Royi Avital
Royi Avital 2019 年 10 月 15 日
Anyone?

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeGaussian Process Regression についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by