MATLAB's custom distance function example for two matrices.
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
hello_world
el 22 de Jul. de 2018
Respondida: Viren Gupta
el 7 de Ag. de 2018
How does MATLAB's @distfun work for two matrices. Suppose:
X1 = rand(5);
X2 = rand(3);
How to compute the KL-Divergence between X1 and X2 using @distfun? I do not see any non trivial distance example in manual. Please advise.
2 comentarios
Viren Gupta
el 3 de Ag. de 2018
I checked the documentation of @distfun here and it says that if Z1 and Z2 are 2 inputs to the function, then Z1 need to have a single row.
Apart from this how are you trying to find KL divergence between 2 vectors of different length?
Respuesta aceptada
Viren Gupta
el 7 de Ag. de 2018
Here is a working example if you want to find KL divergence between 2 vectors.
z1=rand(1,5);
z2=rand(1,5);
X=[z1;z2];
fn=@distfun;
d=pdist(X,fn);
function f = distfun(x1,x2)
l=size(x1,2);
KL=0;
for i=1:l
KL=KL+x2(i)*log(x2(i)/x1(i));
end
f=KL;
end
Hope this helps.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Dimensionality Reduction and Feature Extraction 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!