이 시도 :
이
Difference = zeros(NObjects,NClusters);
costsTmp = zeros(NObjects,NClusters);
lambda = zeros(NObjects,NClusters);
for clustclust = 1:NClusters
repeated_curCenter = repmat(curCenter(clustclust,:), NObjects, 1);
% ^^ This creates a repeated matrix of 1 cluster center but with NObject
% rows. Now, dimensions of repeated_curCenter equals that of curPartData
Difference(:,clustclust) = repeated_curCenter - curPartData;
costsTmp(:,clustclust) = sqrt(sum(abs(costsTmp(:,clustclust)).^2, 1)); %Euclidean norm
end
접근을 시도하고 동일한 크기의 행렬을 만드는 것입니다. 다음과 같이 2 개의 3D 배열을 만들어이 개념을 확장하여 present for 루프를 제거 할 수도 있습니다.
costsTmp = 0 (NObjects, NClusters); 람다 = 0 (NObjects, NClusters);
%Assume that number of dimensions for data = n
%curCenter's dimensions = NClusters x n
repeated_curCenter = repmat(curCenter, 1, 1, NObjects);
%repeated_curCenter's dimensions = NClusters x n x NObjects
%curPartData's dimensions = NObject x n
repeated_curPartData = repmat(curPartData, 1, 1, NClusters);
%repeated_curPartData's dimensions = NObjects x n x NClusters
%Alligning the matrices along similar dimensions. After this, both matrices
%have dimensions of NObjects x n x NClusters
new_repeated_curCenter = permute(repeated_curCenter, [3, 2, 1]);
Difference = new_repeated_curCenter - repeated_curPartData;
Norm = sqrt(sum(abs(Difference)).^2, 2); %sums along the 2nd dimensions i.e. n
%Norm's dimensions are now NObjects x 1 x NClusters.
Norm = permute(Norm, [1, 3, 2]);
여기에서 Norm은 추가 치수만으로 비용 Tmp와 비슷합니다. 나는 lambda에 대한 코드를 제공하지 않았다. 나는 람다가 질문의 코드에도 무엇인지 모른다.
[1 2 3] 또는 [3 1 2]의 의미는 무엇입니까? 내 데이터 세트 도메인이 2D 또는 3D 공간에 없습니다. 내가 테스트했듯이 정규 표준은 ('이리저리'없이) 항상 필요한 정확한 값을 반환하지 않습니다! – remo
@remo 여러분의 코드에서 'curCenters'는 D 차원의 CxD : C 중심 크기의 2D 배열 인 것처럼 보일 것입니다. 'curPartData'는 D 차원의 PxD : P 점 크기의 2D 배열로 보입니다. 위의 코드는 모든 CxP 차이를 계산하기 위해 두 개의 2D 행렬을 싱글 튼 차원의 Cx1xD 및 1xPxD 3D 행렬로 바꿉니다. 'bsxfun'은이 싱글 톤 차원을 이용하고 차이점의 CxPxD 배열을 계산합니다. 이 3D 결과는'costsTemp'에 저장됩니다. 이를 제곱하고 3 차원을 합하면 원하는 결과를 얻습니다. – Shai
@remo이 해결책이 당신에게 좋은가요? 당신이 그것을 받아들이지 않는 이유가 있습니까? – Shai