discrete optimization for minimizing the distance between vectors
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Natalia
el 4 de Nov. de 2013
Comentada: Natalia
el 5 de Nov. de 2013
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 comentarios
Respuesta aceptada
Matt J
el 4 de Nov. de 2013
Editada: Matt J
el 4 de Nov. de 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 comentarios
Matt J
el 5 de Nov. de 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
Más respuestas (0)
Ver también
Categorías
Más información sobre Optimize Model Response en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!