cambiare i prodotti scalari in prodotti vettoriali

1 次查看(过去 30 天)
Avendo come input una matrice X di 32 canali x 30000 samples, voglio modificare i prodotti sottolineati da scalari a vettoriali.
-Xw = X0' * V * D;
-yi = Xw * W(i, :)';
-deltaWi = (Xw' * G1(yi)) / m - (g1(yi) / n) * W(i, :);
qui come sistemo la divisione con n?? (n=32)
- deltaWi = deltaWi - (W(1:i-1, :) * deltaWi')' * W(1:i-1, :);
% Rimozione della media
X0 = X - mean(X, 2);
% Analisi delle componenti principali (PCA)
covMatrix = X0 * X0' / size(X0, 2);
[V, eigVals] = eig(covMatrix);
% Calcola D^(-0.5)
D = diag(sqrt(1 ./ diag(eigVals)));
% Pre-elaborazione: PCA e decorrelazione
Xw = X0' * V * D;
% Funzioni di contrasto G1 e G2
a1 = 1.0;
G1 = @(u) (1/a1) * log(cosh(a1 * u));
G2 = @(u) -exp(-u.^2 / 2);
g1 = @(u) tanh(a1 * u);
g2 = @(u) u .* exp(-u.^2 / 2);
% Inizializza i pesi in modo casuale
[m, n] = size(Xw);
W = zeros(n, n);
% Normalizza i pesi iniziali
% for i = 1:n
% W(i, :) = W(i, :) / norm(W(i, :));
% end
% Ciclo for
for iteration = 1:maxiterations
WP = W;
% Aggiornamento dei pesi per ogni componente indipendente
for i = 1:n
% Calcola y_i
yi = cross(Xw, W(i, :)');
% Calcola la parte principale dell'aggiornamento dei pesi
deltaWi = (Xw' * G1(yi)) / m - (g1(yi) / n) * W(i, :);
% Aggiornamento completo dei pesi
deltaWi = deltaWi - (W(1:i-1, :) * deltaWi')' * W(1:i-1, :);
% Normalizza il peso
W(i, :) = W(i, :) / norm(W(i, :));
end
% Verifica della convergenza
error = max(max(abs(W - WP)));
if error < tolerance
break;
end
end
% Calcola la matrice dei segnali indipendenti
A = Xw * W';
end

回答(1 个)

Yash
Yash 2023-10-3
Risponderò in inglese
I understand that you are trying to implement Independent Component Analysis (ICA) and are facing a problem with the mismatching dimensions of the matrices in the algorithm. Consider the following to solve the problem at hand:
  • The "cross" function requires both inputs to have the same size if they are matrices or multidimensional arrays. However, the “Xw" and “W(i,:)'” matrices in the given code have different sizes. Refer to this link for more information on using this function: https://www.mathworks.com/help/matlab/ref/cross.html
  • Refer to following links for more information on implementing Fast ICA and Reconstruction Independent Component Analysis (RICA):
  • Refer to these for implementing ICA from scratch:
I hope this helps!

标签

Community Treasure Hunt

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

Start Hunting!