discrete optimization for minimizing the distance between vectors
7 views (last 30 days)
Show older comments
Hello,
I have a row of values for the parameter A and a row of values for the parameter B. For each combination of the parameters A and B I perform a simulation resulting in a vector. All vectors have the same length. I want to compare each vector to the reference vector, obtained for the reference parameters A and B (that I don't know). Which optimizer can I use to find a vector with the least distance from the reference vector (and therefore determine the reference A and B)?
2 Comments
Accepted Answer
Matt J
on 4 Nov 2013
Edited: Matt J
on 4 Nov 2013
[minval,minIndex] = min( interdists(reference_vector, other_vectors));
other_vectors(:,minIndex),
where
function Graph=interdists(A,B)
%Finds the graph of distances between point coordinates
%
% (1) Graph=interdists(A,B)
%
% in:
%
% A: matrix whose columns are coordinates of points, for example
% [[x1;y1;z1], [x2;y2;z2] ,..., [xM;yM;zM]]
% but the columns may be points in a space of any dimension, not just 3D.
%
% B: A second matrix whose columns are coordinates of points in the same
% Euclidean space. Default B=A.
%
%
% out:
%
% Graph: The MxN matrix of separation distances in l2 norm between the coordinates.
% Namely, Graph(i,j) will be the distance between A(:,i) and B(:,j).
%
%
% (2) interdists(A,'noself') is the same as interdists(A), except the output
% diagonals will be NaN instead of zero. Hence, for example, operations
% like min(interdists(A,'noself')) will ignore self-distances.
%
% See also getgraph
noself=false;
if nargin<2
B=A;
elseif ischar(B)&&strcmpi(B,'noself')
noself=true;
B=A;
end
[N,M]=size(A);
B=reshape(B,N,1,[]);
Graph=l2norm(bsxfun(@minus, A, B),1);
Graph=reshape(Graph,M,[]);
if noself
n=length(Graph);
Graph(linspace(1,n^2,n))=nan;
7 Comments
Matt J
on 5 Nov 2013
Let S(x) be the differentiable function that converts your unknown parameter vector x to to the simulation output vector and let R be your reference vector. Then for lsqnonlin, the objective function to be passed as input would be
f(x) = S(x)-R
More Answers (0)
See Also
Categories
Find more on Nonlinear Optimization 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!