Do 2 matrices in PSO Cost function must have the same amount of column?

조회 수: 6 (최근 30일)
Nghi
Nghi 2024년 12월 29일
댓글: Star Strider 2024년 12월 29일
I am trying to run a cost function for my PSO, which met the error: "Failure in initial objective function evaluation. PARTICLESWARM cannot continue" and "Error using * .Incorrect dimensions for matrix multiplication. Check that the number of columns in the first matrix matches the number of rows in the second matrix. To operate on each element of the matrix individually, use TIMES (.*) for elementwise multiplication."
I found out this section is causing trouble:
filepath_for_T_matrix = append("C:\Users\Admin\ur3+cobotops\dataset\experimental_setup\IFFCM\IF_FCM_Learning\taus.csv");
taus = readtable(filepath_for_T_matrix); %Weight Matrix
taus = table2array(taus);
[row,col] = find(taus);%Indexes(rows and colums) for non-zeros %line5
candidate_weights = x(1,2:width(x));
W = zeros(height(taus),width(taus)); %line 6
for i=1:height(row)
W(row(i),col(i)) = candidate_weights(1,i);
end
W=transpose(W);%The weight matrix is the transpose of taus %line 11
filepath_for_training_X = append("C:\Users\Admin\ur3+cobotops\dataset\k-fold cross validation datasets\gl\",num2str(fold),"\Training Dataset","\Scaled_X_train_iter_",num2str(fold),".csv");
filepath_for_training_y = append("C:\Users\Admin\ur3+cobotops\dataset\k-fold cross validation datasets\gl\",num2str(fold),"\Training Dataset","\y_train_iter_",num2str(fold),".csv");
X_train = readtable(filepath_for_training_X);
X_train = table2array(X_train);
y_train = readtable(filepath_for_training_y);
y_train = table2array(y_train);
Simulations_for_all_observations = cell(height(X_train),1);
number_of_input_concepts = width(X_train);
number_of_Activation_Decision_Concepts = width(y_train); % After this calculation will start
Taus is a 7x7 matrix so W is a 7x7 zero matrix, but the combined width of X_train and y_train is 20. This is why we have error using *, and leads to PSO can't go on. I know this is the problem because after making W a 20x20 zero matrix no more error occurs, my training is faster but the optimized values stay still. I have just tried 11 iterations as my laptop is weak. I would like to thank you all in advance for clearing my question or giving me advices. The code snippet was taken from Marios Tyrovolas Github: https://github.com/marios-tyrovolas
  댓글 수: 5
Stephen23
Stephen23 2024년 12월 29일
편집: Stephen23 2024년 12월 29일
"I just wanted clarifications that we always need the same matrices column number to do PSO for all applications"
The particleswarm documentation states that "...the objective function to accept a row vector of length nvars and return a scalar value". What matrices your objective function defines inside and how many columns they might have is your business.
The error you get has nothing (directly) to do with the particleswarm function, but is due to an attempt to MTIMES arrays which have incompatible sizes.
Star Strider
Star Strider 2024년 12월 29일
@Nghi — With respect to your earlier Comment, if you are comparing a data matrix (or vector) with a calculated matrix (or vector) in order to compare them (probably subttracting them and then calculating the norm to determine how close they are), those matrices must have the same row and column dimensions.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Particle Swarm에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by