Simulated annealing on a 3D matrix data set instead of a mathematical function?
1 view (last 30 days)
Show older comments
I want to find the best combinations of (x) and (y) values that gives the lowest (z) value, where 0≤x≤100 and 0≤y≤100. So the optimizing parameter (x,y) is a [10000,2] matrix that contains all the possible combinations of (x) and (y), and the objective (z) is an initially empty [10000,1] array.
The problem is that the (z) is not a simple function of (x) and (y). The (z) values are calculated using an external software and each calculation takes around 10 hours. So, instead of calculating all the 10000 (z) values for the whole range of 0≤(x)≤100 and 0≤(y)≤100, which would take 100000 hours in total, I want to use simulated annealing (or other optimization tools) to estimate the best combinations of (x) and (y) values that would give the minimum (z).
I know MATLAB can do simulated annealing on functions, but what about cases like mine where I don't have a function but an array of data (z) which is initially empty (as in the values need to be filled every time by an external software)? I have been stuck on this for months :/
Thank you very much in advance!
0 Comments
Answers (3)
Alan Weiss
on 20 Jul 2017
I don't know why you think that simulated annealing is the way to solve your problem, because I think that it is a slow, inefficient algorithm. I would either use bayesopt or patternsearch to try to locate a minimum. For patternsearch, start on integer coordinates, set the ScaleMesh option to false, and MeshTolerance to something less than 1, such as 0.75.
Good luck,
Alan Weiss
MATLAB mathematical toolbox documentation
2 Comments
Walter Roberson
on 28 Jul 2017
I am unclear here. Your external software appears to calculate z. How do you know what the error in the calculation is? Do you have a reference value?
Steven Lord
on 20 Jul 2017
To compute the minimum of an array, just use the min function. If I've misunderstood what you're trying to do, please explain in more detail what exactly your 3-D array represents.
Don Mathis
on 28 Jul 2017
Here's an illustration of how to do it with bayesopt. You would have your objective function call your external function (somehow) and read the result. Copy this code into a file and run it. It's a script with functions defined at the end. I told it to run forever and save results along the way, so just Control-C when you've run it long enough and you will have a variable 'BayesopResults' in your workspace, and a file 'BayesoptResults.mat' in the directory you ran it in:
Vars = [optimizableVariable('X', [0 100]);
optimizableVariable('Y', [0 100])];
Result = bayesopt(@myObjFcn, Vars, ...
'MaxObjectiveEvaluations', Inf,...
'OutputFcn', {@assignInBase, @saveToFile})
function Err = myObjFcn(Tbl)
PercentIronOxide = 72;
Z = callExternalFunctionAndReadResult(Tbl.X, Tbl.Y);
Err = abs(Z - PercentIronOxide);
end
function Z = callExternalFunctionAndReadResult(X, Y)
% Somehow call your external function and return the result.
Z = X + Y;
end
If you can't find a way to call your external function from matlab, maybe you could just have your objective function tell the user what values to try and have them enter the result manually, like this:
Vars = [optimizableVariable('X', [0 100]);
optimizableVariable('Y', [0 100])];
Result = bayesopt(@myObjFcn, Vars, ...
'MaxObjectiveEvaluations', Inf,...
'OutputFcn', {@assignInBase, @saveToFile})
function Err = myObjFcn(Tbl)
PercentIronOxide = 72;
Z = callExternalFunctionAndReadResult_Prompt(Tbl.X, Tbl.Y);
Err = abs(Z - PercentIronOxide);
end
function Z = callExternalFunctionAndReadResult_Prompt(X, Y)
% Somehow call your external function and return the result. This version
% just asks the user to do it.
Z = input(sprintf('Please run your external software on the point [X,Y] = [%f, %f].\nThen enter the Z value and press Enter.\nZ = ', ...
X, Y));
end
0 Comments
See Also
Categories
Find more on Simulated Annealing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!