Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update niching_func.m #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Update niching_func.m #4

wants to merge 2 commits into from

Conversation

Daizy97
Copy link

@Daizy97 Daizy97 commented Mar 5, 2020

Modify "global initial_flag" to ensure that when running different functions or running the same function with different dimensions of x, the program will reload the optima matrix. If not, when running next function with different dimensions of x, there will be an error about dimension mismatch between the optima matrix and the individual to be evaluated.

Daizy97 added 2 commits March 5, 2020 17:34
Modify "global initial_flag" to ensure that when running different function or running the same function with different dimensions of x, the program will reload the optima matrix. If not, there will be an error about dimension mismatch between the optima matrix and the individual to be evaluated.
@mikeagn
Copy link
Owner

mikeagn commented Jun 22, 2020

Can you please elaborate on the suggested fix? it would be great to provide a code snippet that exhibits the problem.

@Daizy97
Copy link
Author

Daizy97 commented Sep 4, 2020

Let's take the code of Composition Function 3 as an example, which has F13, F14, F16, F18 with different dimensions. This is the original code:

global initial_flag
persistent func_num func o sigma lambda bias M

[ps,D] = size(x);
func_num = 6;
lb = -5; ub = 5;
if initial_flag==0 % then load optima.mat and generate the composition function
...
end

We just want to only load optima.mat for the first time and directly use the persistent variables func_num, func, o, sigma ,lambda, bias, M in the next calls. This works fine during running F13 (2D). But when changing to F14 (3D), the dimension of input x changed. So there will be a mismatch of the dimension of the persistent variable o .

To address this issue, I add two persistent variables initial_flag and dim and delete the global variable initial_flag. In this way, at every call we not only judge if the initial_flag==0, but also judge if the dimension of the input x has changed. Therefore, when F13 (2D) changes to F14 (3D), we will reload optima.mat and generate the new compositional function.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants