Is it possible to create an optimizableVariable of integer type as an array with step different from 1?

Technical Source
2 min readApr 13, 2021

--

Hello everyone!

I’m trying to perform a Bayesian optimization to find the best hyperparameters for a deep neural network and I want the variable MiniBatchSize to just have, in this case, three possible values: 8, 10, 12. I thought I could declare optVar as if it was an array

interval = 8:2:12;
optVar = optimizableVariable('MiniBatchSize', interval, 'Type', 'integer');

This code raises the following error:

Error using optimizableVariable/checkRange

‘Range’ value must be a string array, a cell array of character vectors, or a numeric vector of length 2.

Am I missing something? Is there another way to perform this?

ANSWER

Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.

Suppose X is an integer variable, that takes on only the values 1:5.

But what you want are non-integer levels of some parameter. For example, perhaps you want levels at [1.5, 3.5, 5.5, 7.5, 9.5]?

Inside your code, just write

Xhat = 2*X - 0.5;

Do you agree that Xhat takes on the desired levels?

They need not even be at all regular. Suppose you want levels at [2 3 5 7 11]? Inside your code, you might do this:

SEE COMPLETE ANSWER CLICK THE LINK

--

--

Technical Source
Technical Source

Written by Technical Source

Simple! That is me, a simple person. I am passionate about knowledge and reading. That’s why I have decided to write and share a bit of my life and thoughts to.

No responses yet