need help with this problem

2 vues (au cours des 30 derniers jours)
Abdelmalek Benaimeur
Abdelmalek Benaimeur le 3 Avr 2019
hello I'm interesting on linkage methods on hierarchical clustering
i extracted this function from another function in Matlab library (please see the attached file)
i searched on it for median linkage and i found this
case 'me' % median linkage
Y(I) = (Y(I) + Y(J))/2 - v /4;
my question is What does v equal to.?
because the code says
if any(strcmp(method,{'ce' 'me' 'wa'}))
Y = Y .* Y;
end
if strcmp(method,'av')
p = (m-1):-1:2;
I = zeros(m*(m-1)/2,1);
I(cumsum([1 p])) = 1;
I = cumsum(I);
J = ones(m*(m-1)/2,1);
J(cumsum(p)+1) = 2-p;
J(1)=2;
J = cumsum(J);
W = N(R(I)).*N(R(J));
[v, k] = min(Y./W);
else
[v, k] = min(Y);
end
so i put
Y = Y .* Y;
[v, k] = min(Y);
and when i execute my function i get this error
Unable to perform assignment because the left and right sides have a different number of elements.
Error in Hierarchical_clustering>Linkage (line 226)
Y(I) = (Y(I) + Y(J))/2 - v /4;

Réponse acceptée

Walter Roberson
Walter Roberson le 3 Avr 2019
I = zeros(m*(m-1)/2,1);
I(cumsum([1 p])) = 1;
I = cumsum(I);
Each of those three lines treates I as a vector, not as a scalar.
J = ones(m*(m-1)/2,1);
J(cumsum(p)+1) = 2-p;
J(1)=2;
J = cumsum(J);
Likewise, J is a vector, not a scalar.
W = N(R(I)).*N(R(J));
We do not know if R is a function or an array being indexed. If it is a variable being indexed, then R(I) and R(J) are going to be vectors, and if R is a function we can guess that when it is passed a vector that it returns something no scalar. Thus we can predict that W is pretty likely to be a non-scalar.
[v, k] = min(Y./W);
Y appears to be a vector. W is likely a vector. But we do not know that Y and W have the same orientation.
... And when we look into the code, we see Y was initialized as a column vector but N and R are initialized as row vectors, so Y and W do not have the same orientation. In R2016a or earlier you would have received an error message when doing the Y./W . In R2016b and later, the operation is equivalent to bsxfun(@rdivide, Y, W) which is going to produce a 2D array, each element of Y divided by each element of W in all combinations.
When you take the min() of a 2D array, the values, v, that return are going to be a vector.
Y(I) = (Y(I) + Y(J))/2 - v /4;
I and J are non-scalars, but they are a different size than the vector v is. v will be a row vector the same width as Y, but I and J are being used to select portions of Y, probably not the same width. And you get questions about orientation again, so if the subtraction happens to work the result is not likely to be the same size as I is...

Plus de réponses (1)

Abdelmalek Benaimeur
Abdelmalek Benaimeur le 3 Avr 2019
Please tape this in command windows open linkage You will get the main function from where i extracted the attached function And then see if you can figure out the solution of what does equal v in Y(I) = (Y(I) + Y(J))/2 - v /4;

Community Treasure Hunt

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

Start Hunting!

Translated by