BIMK / PlatEMO

Evolutionary multi-objective optimization platform
1.63k stars 468 forks source link

CSEA "Array indices must be positive integers or logical values." #129

Open electronsandstuff opened 1 year ago

electronsandstuff commented 1 year ago

Hey folks, I am running into some errors evaluating CSEA on ZDT2. Here are the specific settings:

CSEA
k: 6
gmax: 3000
ZDT2
N: 20
M: 2
D: 10
maxFE: 300

Probably one out of every ten runs I get the error:

Error in RefSelect>LastSelection (line 48)
    CrowdG(temp(:,1)) = temp(:,2);

Error in RefSelect (line 26)
    Choose = LastSelection(PopObj(Next,:),ismember(Next,find(FrontNO<MaxFNO)),ceil(sqrt(k)),k);

Error in CSEA/main (line 41)
                Ref    = RefSelect(Population,k);

Error in ALGORITHM/Solve (line 77)
                tic; obj.main(obj.pro);

Error in module_exp/cb_start (line 289)
                                    ALG(a).Solve(PRO(p));

Error in module_exp>@(varargin)obj.cb_start(varargin{:}) (line 88)
            obj.app.buttonC(1) = GUI.APP(3,2,uibutton(obj.app.grid(3),'push','Text','Start','FontSize',16,'ButtonpushedFcn',@obj.cb_start));

Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback
Error while evaluating Button PrivateButtonPushedFcn.

Error using parallel.FevalFuture/fetchNext
The function evaluation completed with an error.

Error in module_exp/cb_start (line 319)
                                    [r,result,metric] = fetchNext(Future,0.01);

Error in module_exp>@(varargin)obj.cb_start(varargin{:}) (line 88)
            obj.app.buttonC(1) = GUI.APP(3,2,uibutton(obj.app.grid(3),'push','Text','Start','FontSize',16,'ButtonpushedFcn',@obj.cb_start));

Caused by:
    Error using RefSelect>LastSelection
    Array indices must be positive integers or logical values.

I was able to print the indices in temp and the result was access at index zero:

temp =   0     5   100
electronsandstuff commented 1 year ago

Another note on the issue: I also get a similar problem when evaluating REMO on ZDT2 with the same settings. It looks like it uses the same function LastSelection.

electronsandstuff commented 1 year ago

Just a quick update on this problem.

I was able to track it down to the following lines of code in CSEA/RadarGrid.m.

[N,M] = size(P);

%% Calculate the radar coordinate of each solution
theta     = 0 : 2*pi/M : 2*pi/M*(M-1);
RLoc(:,1) = sum(P.*repmat(cos(theta),N,1),2)./sum(P,2);
RLoc(:,2) = sum(P.*repmat(sin(theta),N,1),2)./sum(P,2);  % Note: Should be zero for two objective problem.

RLoc      = (RLoc+1)/2;
YL        = min(RLoc,[],1);                             % Lower bounary of the transferred points
YU        = max(RLoc,[],1);                             % Upper bounary of the transferred points  
NRLoc     = (RLoc-repmat(YL,N,1))./repmat(YU-YL,N,1);   % Normalized points

For a two objective problem, the values of theta are 0 and pi. This makes the value of RLoc(:,2) 0.5 for the whole population. Then, when RLoc is normalized by its minimum and maximum values you get a divide by zero on the last line. This propagates through the algorithm and results in the indexing issue later. It looks like the reason it wasn't failing on other two objective problems was only because of numerical error in calculating RLoc. The same problem exists in REMO/RefSelect.m.

I don't know if anyone can offer advice on solving the issue. I could add some some small value to the normalization code to prevent it from dividing by zero (ie (RLoc-repmat(YL,N,1))./repmat(YU-YL+epsilon,N,1)), however I am not sure if that changes the function of the code or not.