# Optim.jl optimize over Distances.jl metric

#1

Hello all!

I’m wondering what’s the most efficient way to go about optimizing over a specific distance metric.

As of right now, I have two vectors, `x`, `y` and `bhattacharyya(x, y)` as loaded from Distances.jl. I’d like to call something like `optimize(bhattacharyya(x, y), x)` in order to find the adjustment to x that minimizes the Bhattacharyya distance between it and y.

If I run the above directly, Julia will crash out without a warning or error after some time.
There’s a better way of coding what I’m trying to perform, but I don’t know how to go about that.
Can someone direct me to some resources or tell me if there’s something glaring that I’m missing?

Thanks,

#2

Isn’t y=x the argmin trivially?

#3

Posting a minimal working example would be a good start. But I agree with @Juser, isn’t y=x the minimizer? Or is there some other constraint?

#4

Is this literally what you type? Then it obviously won’t work, as `bhattacharyya(y,x)` is a function call, so you call `optimize` with a number and a vector. What you probably mean is something like

``````optimize(x->bhattacharyya(y,x), x)
``````

but as they others note… Per definition, a metric d has d(x,y)>= 0 and d(x,y)=0<=>x=y, so setting x to y will give you the global minimum, no need to use numerical optimization here.

#5

you are all correct, I posed the problem poorly to myself in my own head. I did find my error in logic.

Thank you to @pkofod for pointing out my Julia syntax issue, the type mismatch was something that I hadn’t considered.

Again, My apologies for posting a poorly defined problem like this, but thank you all for your comments.