Matrix dimension problems in Genetic programming. N.B I am not referring to Genetic algorithm

I am implementing the genetic programming toolbox version 2 from https://sites.google.com/site/gptips4matlab/home to generate model structures for a set of data. In the zip folder, I have my dataset and configuration file as well as my function file labelled as Opinionmining_dataset, gpdemo5_config.m and gpdemo5.m . By following the examples specifically demo4. I made my own demo which is the demo5. The problem I have now is when I run the mygpdemo5.m. it runs to a certain point and gives me the error below. I would be glad if anyone could assist. Thank you.
Index exceeds matrix dimensions.
Error in gpmodel2struct>regressmulti_fitfun_full_stats (line 477)
eval(['geneOutputsTest(:,ind)=' evalstr{i} ';']);
Error in gpmodel2struct (line 253)
gpmodel = regressmulti_fitfun_full_stats(gpmodel,evaltreestrs,gp,rtnVals,tbxStats);
Error in gpfinalise (line 63)
gpmodel = gpmodel2struct(gp,i,false,false,false);
Error in rungp (line 148)
gp = gpfinalise(gp);

5 Comments

The code depends heavily on eval(). I recommend throwing it away.
'How do i leave it out.its part of the whole toolbox. But it seems to work on other datasets .I only followed the instruction from here https://sites.google.com/site/gptips4matlab/home .
Mr Walter, Kindly try running the gpdemo4.m It will make my explanations clearer.
I did run the code. It fails on
eval(['geneOutputsTest(:,ind)=' evalstr{i} ';']);
when evalstr{i} is 'minus(minus(gp.userdata.xtest(:,5),exp(gp.userdata.xtest(:,3))),square(square(gp.userdata.xtest(:,4))))' but gp.userdata.xtest is something with only one column instead of 5.
I traced back, and the use of eval() is hard-wired into the way that the code works. It generates random character vectors and does random text replacement on them, and does mutations and cross-overs at the text level. The code would require some concerted effort to be rewritten to avoid using eval().
awwww.I contacted the Developer but I haven't gotten any response yet.I hope to hear from him soon.

Sign in to comment.

 Accepted Answer

You have
gp.userdata.ytest = tstS;
gp.userdata.xtest = tsty;
gp.userdata.xval = ValS;
gp.userdata.yval = Valy;
in the second block of code, the variable ending with 'y' is assigned to a field mentioning 'y', and the variable ending with 'S' is assigned to a field mentioning 'x'. But in the first block of code, the variable ending with 'y' is assigned to a field mentioning 'x', and the variable ending with 'S' is assigned to a field mentioning 'y'. There are no comments that might explain why tstS corresponds to Valy and tsty corresponds to ValS.
The xtest that gets assigned is 2 x 1. The ytest that gets assigned is 2 x 5.
The code that runs errors out when trying to access column 5 of xtest.
We can speculate that you made a mistake related to the data or to this section of the code.

5 Comments

Yes, .it works now. Please, how do I get better at Matlab? I have been using it for like 5months now. Any tips to improve my understanding and identifying bugs will be appreciated. Thank you very much, Walter. Will definitely acknowledge you in any work I do.
Note: further changes are needed for the displaying code to work in R2018a or later. The changes became possible in R2017b and mandatory in R2018a. The changes have to do with converting most calls to sym() into calls to str2sym() . (There are a few places I could not determine whether str2sym() would be needed or if sym() would continue to be appropriate, though.)
I use Matlab2014a and I have the symbolic math toolbox installed. That should suffice for now. The code works with my current version since I don't have the newer versions of Matlab.
Hello Walter, I posted a subquestion on the toolbox here https://www.mathworks.com/matlabcentral/answers/414768-developing-a-fitness-function-for-evolved-models-in-genetic-programming. I would be glad if you could check it out.

Sign in to comment.

More Answers (0)

Products

Release

R2014a

Community Treasure Hunt

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

Start Hunting!