Bug in bayesopt() function? Initial evaluation points table being incorrectly evaluated?

Hi, I'm using the bayesopt() function in the Global Optimization Toolbox for a problem with integer variables. I'm providing my own initial points in the solution space for the algorithm to start from. I'm doing this in the way described in the documentation, i.e:
x1=optimizableVariable('x1',[0 3],'Type', 'integer');
x2=optimizableVariable('x2',[0 3],'Type', 'integer');
InitialX= table([int8(0),int8(1)],[int8(0),int8(1)]);
result = bayesopt(fun,[x1,x2],.....'InitialX',InitialX);
As you can see I have stated x1 and x2 to be optimizableVariables of type 'integer'. I have been careful to cast my values in InitialX as integers also. However when I run my code I get the following error message:
"Error using bayesoptim.BayesoptOptions/checkInitialX (line 413) Column 1 of InitialX is declared to be integer in the VariableDescriptions argument but contains some non-integer data."
When I investigated the code in bayesoptim.BayesoptOptions/checkInitialX I found that the error is being thrown because the function bayesoptim.isInteger() is evaluating the first column of my IntialX table to contain non-integers. When I checked this against the isinteger() function (in the same workspace) it found the same argument to be only integers. The screenshot shows this more clearly.
I'm surprised by this. I cant get a look at whats going on int bayesoptim.isInteger() so can't explain why it is evaluating differently to isinteger(), but surely this is wrong? Can anyone help me with fixing my problem so that I can use my InitialX table? Thanks

 Respuesta aceptada

Hi Bob, You're running into a bug in bayesoptim.isInteger. You should be able to view that code by typing
edit bayesoptim.isInteger
It should look like this:
function tf = isInteger(x)
% Copyright 2016 The MathWorks, Inc.
tf = isscalar(x) && isnumeric(x) && isreal(x) && x==floor(x);
end
Change line 5 to this, and then save the file:
tf = isnumeric(x) & isreal(x) & x==floor(x);
After that, pass your InitialX as doubles, as Alan suggested, not as actual integer datatypes.
And please let us know how it goes.

5 comentarios

Hi Don, thanks for getting back to me. I made the change you suggested but when I tried to save the file a pop-up from MATLAB Editor appeared saying that there was an "Error writing isInteger.m", it then gave the path to the file and said "Access is denied". Is there a way around this?
You'll need to make the file writeable. What is your platform: Windows, Mac, or Linux?
Windows. Are you able to give me some instruction of how to make it writeable?
Ok, I think modifying permissions is going to depend on Windows versions and other settings, so I have a different suggestion.
You can override the bayesoptim.isInteger function by putting a replacement into a new folder that you will call +bayesoptim, and putting its enclosing folder on your MATLAB path.
The file should be named "isInteger.m" and contain this:
function tf = isInteger(x)
tf = isnumeric(x) & isreal(x) & x==floor(x);
end
Place that file in a new folder called +bayesoptim. That will define the function bayesoptim.isInteger for you. The directory into which you put this new folder must be on your MATLAB path. You could add it explicitly, or you could just put +bayesoptim in your current directory, because that is automatically on your path.
For example, suppose you want to run your MATLAB program from a folder called "MyProgram\". Put your new +bayesoptim folder into MyProgram\, navigate to MyProgram\ in MATLAB and run your program.
Does that make sense?
That does make sense and appears to have worked! Thanks :)

Iniciar sesión para comentar.

Más respuestas (1)

Your InitialX is a 1-by-2 table with contents
x1 = [0 1]
x2 = [0 1]
This is not what bayesopt expects. According to the documentation, InitialX should be an N-by-D table, where D = 2 in your case. Something like (for N = 2)
initable = table([0;1],[0;1],'VariableNames',{'x1','x2'});
Alan Weiss
MATLAB mathematical toolbox documentation

4 comentarios

Thanks for your quick response Alan. However, this does not seem to be resolving my problem. I agree that the table I posted is formatted incorrectly (not N by D, doh!) but I don't see why this would cause the integer check to fail? In any case, I have now changed the table format to N by D using the template you suggested (actual code below) but am still getting the same error message.
a0=int8(0);
a1=int8(1);
InitialX=table([a0;a1],[a0;a1],'VariableNames',{'x1','x2'});
If you look in the screenshot below, X is now a vertical vector rather than horizontal, but is still failing the bayesoptim.isInteger(X) test.
Any other ideas? Thanks for your help!
Oh, sorry, I thought that would work.
Well, the only other idea I have is to try some plain double-precision numbers instead of int8:
a0 = 0;
a1 = 1;
InitialX=table([a0;a1],[a0;a1],'VariableNames',{'x1','x2'});
If that works, I will ask the development staff whether there are restrictions that I didn't know about for passing points to bayesopt. If so, these restrictions should be documented.
Alan Weiss
MATLAB mathematical toolbox documentation
Bob Hickish
Bob Hickish el 29 de Sept. de 2017
Editada: Bob Hickish el 29 de Sept. de 2017
Thanks for the further suggestion. I have tried using double numbers and I have also tried using all the versions of int casting (int8, uint8, int16, uint16....uint64), but none have worked.
Looking at the code in bayesoptim and the error message that has been thrown it appears likely that integer values in InitialX should be fine. I believe there is an issue with the bayesoptim.isInteger() function. Is there anyway I can view this code? If not, please could you let me know the outcome of your discussion with the development staff? Do you have an idea about when that might be?
This is a bug. We'll get you a workaround today. Sorry for the hassle.

Iniciar sesión para comentar.

Categorías

Preguntada:

el 28 de Sept. de 2017

Comentada:

el 29 de Sept. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by