how to find inputs based on desired outputs?
24 views (last 30 days)
Show older comments
I am trying to optimize my inputs for a function that takes 15 inputs (lets call them "A") and generates 17 (lets call them "B") outputs. I also have 17 (lest call them "D") values that I want to match my function's outputs ("B") to these values. First, I have a pretty good starting points for the "A" input values that gives me a good output "B" that is pretty close to "D" values, but not close enough, and I need to tune my input to get a better match.
My question is that what is the best method to optimize the "A" values, and change them in a way that matches my desired output "D" values?
Thank you.
0 Comments
Accepted Answer
Alan Weiss
on 12 Mar 2015
If you have Optimization Toolbox, then use the lsqnonlin solver. Your objective function is
fun = @(x)Bfunction(x)-D
where Bfunction is your function that accepts a 15-dimensional argument x and returns a 17-dimensional return B that should be as close as possible to D. lsqnonlin tries to vary x so that the sum of squares norm(B-d)^2 is minimized.
If you just have base MATLAB, then you can try to use fminsearch with the objective function
fun = @(x)sum((Bfunction(x)-D).^2)
but this will probably be slower and less accurate than using lsqnonlin.
Alan Weiss
MATLAB mathematical toolbox documentation
More Answers (1)
John D'Errico
on 12 Mar 2015
There is NO best method. There are many good methods. Good or best are measures that depend strongly on your problem, depending on how fast it is to evaluate, if it is smooth, if there are constraints, how accurate an answer you need, if there are discrete parameters (integer valued), etc.
You have more outputs than inputs, so this is in general a nonlinear least squares problem, since it will generally be impossible to solve for an exact solution. Depending on the issues I mention above, tools you might use would be one of lsqnonlin, fmincon, a genetic optimizer, simulated annealing, or a particle swarm tool of some ilk. There are many variety of particle swarm tools of course to be found on the File Exchange.
If you use one of the general nonlinear minimizers, then you will need to provide a sum of squares of the errors relative to your goal output. If you use lsqnonlin, then it will form that sum of squares, so all you need do is supply the residuals.
See Also
Categories
Find more on Genetic Algorithm in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!