Simulated annealing on a 3D matrix data set instead of a mathematical function?

2 visualizzazioni (ultimi 30 giorni)
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!

Risposte (3)

Alan Weiss
Alan Weiss il 20 Lug 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 Commenti
Kota
Kota il 28 Lug 2017
Modificato: Kota il 28 Lug 2017
Hi, thank you for your answer!
I might have been not clear with my question so please let me clarify what I want to do.
I am a chemist who is new to matlab. I have an experimentally measured composition Z (let's say it's 72% iron oxide). I am running a software that simulates chemical reactions (not MATLAB). This simulation has tunable parameters X and Y (let's say 0≤X≤100 and 0≤Y≤100). With the correct X and Y parameters, the simulation will give me the correct composition Z of 72%.
Now, trying every single combinations of X and Y is not possible because of time constraint. Hence, I want to use machine learning (let's say bayesopt as you suggested) to find the best combination of X and Y that gives me the correct Z. In other words, I want to find the combination of X and Y that will give me the minimum % error in the predicted Z without calculating all the possible combinations of X and Y.
I looked into the bayesopt function but the problem I have is the objective function. My objective function is not a simple mathematical function f(X,Y). It is the % error in the predicted Z value (that needs to be calculated using another software and later read by MATLAB). So the initial Z array is empty.
Is the a way to define the objective function in such a way?
Thanks.
Walter Roberson
Walter Roberson il 28 Lug 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?

Accedi per commentare.


Steven Lord
Steven Lord il 20 Lug 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
Don Mathis il 28 Lug 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

Community Treasure Hunt

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

Start Hunting!

Translated by