Pair-wise Mahalanobis distance

4 messages
Open this post in threaded view
|

Pair-wise Mahalanobis distance

 In using Distances.jl, the following pair-wise Euclidean distance is successful:julia> X2x2 Array{Float64,2}:1.0 3.02.0 4.0julia> Y2x3 Array{Float64,2}:1.0 3.0 5.02.0 4.0 6.0julia> pairwise(Euclidean(), X, Y)2x3 Array{Float64,2}: 0.0 2.82843 5.65685 2.82843 0.0 2.82843What is the corresponding code to compute the Mahalanobis distances between the columns of X and Y, sqrt of,(X[:,i] - Y[:,j])'*inv(Q)*(X[:,i] - Y[:,j]) for each (i,j).where Q would ideally default to, say, identity (the case of Mahalanobis => Euclidean). I thought this might do it:julia> pairwise(Mahalanobis(), X, Y,eye(2))`Mahalanobis{T}` has no method matching Mahalanobis{T}()Thanks,Bradley -- You received this message because you are subscribed to the Google Groups "julia-stats" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout.
Open this post in threaded view
|

Re: Pair-wise Mahalanobis distance

 The identity matrix you're trying to pass I think as Q as the final argument to pairwise needs to be passed to the Mahalanobis constructor. Read this as "take pairwise distances using the Mahalanobis (with Q=eye(2)) metric between X and Y":pairwise(Mahalanobis(eye(2)), X, Y)On Saturday, August 30, 2014 12:20:20 PM UTC-5, Bradley Setzler wrote:In using Distances.jl, the following pair-wise Euclidean distance is successful:julia> X2x2 Array{Float64,2}:1.0 3.02.0 4.0julia> Y2x3 Array{Float64,2}:1.0 3.0 5.02.0 4.0 6.0julia> pairwise(Euclidean(), X, Y)2x3 Array{Float64,2}: 0.0 2.82843 5.65685 2.82843 0.0 2.82843What is the corresponding code to compute the Mahalanobis distances between the columns of X and Y, sqrt of,(X[:,i] - Y[:,j])'*inv(Q)*(X[:,i] - Y[:,j]) for each (i,j).where Q would ideally default to, say, identity (the case of Mahalanobis => Euclidean). I thought this might do it:julia> pairwise(Mahalanobis(), X, Y,eye(2))`Mahalanobis{T}` has no method matching Mahalanobis{T}()Thanks,Bradley -- You received this message because you are subscribed to the Google Groups "julia-stats" group. To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email]. For more options, visit https://groups.google.com/d/optout.