Given that we have:
- x is 2d matrix with size [numSamples x numFeatures]
- A is 2d square matrix with size [numFeatures x numFeatures]
- B is a 1d vector with size [1 x numFeatures]
I would like to evaluate the following code without a loop: (or in a way faster way)
out = zeros(1,numSamples);
for i = 1:numSamples
res = sum(repmat(B - x(i,:), numSamples, 1)*A.*(x - repmat(x(i,:), numSamples, 1)), 2).^2;
out(i) = var(res);
end
If you have other suggestions on a faster improvement of the above, it is also more than welcome.