Azzera filtri
Azzera filtri

pso algorithm

3 visualizzazioni (ultimi 30 giorni)
vydyam
vydyam il 22 Nov 2011
I have tried writing PSo for eld problem with valve point effects using PSO of the file here but with new function
%function with valve point effects
function [y Pl]=f8(in)
global data B Pd;
c=data(:,1);
b=data(:,2);
a=data(:,3);
e=data(:,4);
f=data(:,5);
pmin=data(:,6);
y1=in.*in*diag(a)+in*diag(b)+(abs(diag(e)*sin(diag(f)*(pmin-in'))))';
Pl1=(in*B).*in;
Pl=sum(Pl1');
lam=abs(Pd+Pl-sum(in'))';
y=(sum(y1')+sum(c))'+100*lam;
when i tried to run it with PSo i am getting errors as
??? Error using ==> minus
Matrix dimensions must agree.
Error in ==> f8 at 9
y1=in.*in*diag(a)+in*diag(b)+(abs(diag(e)*sin(diag(f)*(pmin-in'))))';
Error in ==> pso_Trelea_vectorized at 266
out = feval(functname,pos); % returns column of cost values (1 for each particle)
Error in ==> Untitled2 at 22
[OUT]=pso_Trelea_vectorized('f8',n,1,ran,0,Pdef);
please help me solving this and guide me why i should not use minus there as the function of valve point effects is with -sign
thanking you
my data matrix and the calling program are as follows
clear
clc;
format long;
global data B B0 B00 Pd
data=[561 7.92 0.001562 300 0.0315 100 600
310 7.85 0.001940 200 0.0420 100 400
78 7.97 0.004820 150 0.0630 50 200];
B=.01*[.0218 .0093 .0028;.0093 .0228 .0017;.0028 .0017 .0179];
B0=0*[.0003 .0031 .0015];
B00=100*.00030523;
Pd=850;
Pd=Pd+B00;
l=data(:,6)';
u=data(:,7)';
ran=[l' u'];
n=length(data(:,1));
Pdef = [100 10000 50 2.05 2.05 0.9 0.4 1500 1e-6 5000 NaN 2 0];
[OUT]=pso_Trelea_vectorized('f8',n,1,ran,0,Pdef);
out=abs(OUT)
P=out(1:n)
[F Pl]=f8(P')
this is my calling program and it was done for this program

Risposta accettata

Walter Roberson
Walter Roberson il 22 Nov 2011
According to the pso_Trelea_vectorized source the value that is passed to the function will be an array of positions that is ps by D, where ps is the number of particle swarms and D is the dimension. The number of particle swarms, ps, is whatever is stored in your Pdef(3) in your call. The dimension, D, is whatever n is in your call.
At the line that triggers the error, you have the expression pmin-in' . When we look at the line above, we see that pmin=data(:,6) so pmin is a column vector. "in" is whatever was passed as input to your f8 function. The "'" operator after "in" transposes "in" (conjugate transpose, actually -- probably the ".'" operator should have been used for a plain transpose) so the expression becomes "a column vector minus transpose of input".
Under what circumstances can "a column vector minus transpose of input" be valid?
  1. if "in" was an empty matrix, then the subtraction would be allowed (I think) but would result in the empty matrix. This would require that least one of Pdef(3) or "n" have been 0, which seems implausible.
  2. if "in" was a scalar, then its transpose would be a scalar, and the subtraction would be valid. This would require that both Pdef(3) and "n" have been 1, which seems implausible to me.
  3. if "in" was a row vector with the same number of elements as pmin, then the transpose would be a column vector the same length as pmin, and the subtraction would be valid. As "in" is ps by D, ps (number of particle swarms, Pdef(3)), would have to have been 1 for "in" to be a row vector, and D (the "n" in your call) would have to have been the same as the number of rows in your global "data" matrix. It seems unlikely that you would have deliberately programmed in only 1 particle swarm. We do not have enough information at present to assess whether the number of rows in "data" might be the same as "n" in your call.
  4. in all other cases, the subtraction would be invalid. This includes all cases where the number of particle swarms was greater than 1 (except if "n" was 0), which I would judge to be fairly likely. It also includes all cases where "n" was not the same as the number of rows in "data", which is an easy sort of mistake to make.
We are not given any information about what your "data" matrix represents, so we cannot make any firm recommendations as to what you need to change.
The code change that would seem most probable for the purpose of moving onward would be to change
(pmin - in')
to
(repmat(pmin,1,size(in,2)) - in.')
I cannot tell if that makes any sense within the desired meaning of your computation, but it would be most likely to allow the dimensions to match so that the subtraction could take place.
  1 Commento
Walter Roberson
Walter Roberson il 22 Nov 2011
With the addition of your code, we can see that I was correct: your ps (particle swarms) is 50, your n is 3, so the matrix that pso_Trelea_vectorized would pass in to f8 would be 50 x 3 . You transpose that, so you would be subtracting a 3 x 50 array from your 3 by 1 column array pmin. You cannot subtract an array from a vector. You *can* replicate the array to be the same size as the vector and do the subtraction then: my answer earlier showed the code for that.

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 22 Nov 2011
Please do not post duplicate questions: it just ends up wasting time all around.
It frustrates me to have spent a long time in the middle of the night analyzing an unknown source, and writing a detailed analysis of all the ways it could have gone wrong, and then to have my analysis ignored with the author reposting exactly the same problem. :(
  1 Commento
vydyam
vydyam il 18 Dic 2011
sorry for posting the above as i am in requirement of it i had to post it but also i worked with the algoritm ,it is giving correct answers for some data only and some other it is not giving the correct answer, i mailed the author and there is no reply from him
Thank you for your above correction but once again i am sorry to post the above.

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by