Harmonic mean in cvx

It depends on what you want to do with it.

For those who don’t know what the harmonic mean is, it’s f(x)=1/\sum_i x_i^{-1}. For positive x, it is concave. It’s also increasing in x, so that means it can accept a concave argument according to the DCP rules. Unfortunately, we haven’t figured out how to map it to the conic solvers in the most important case.

Let’s define g(x)=1/f(x)=\sum_i x_i^{-1}, which is just inv_pos(x):

  • To \text{maximize}~f(x), then you can just do \text{minimize} g(x) instead, which is just minimize(sum(inv_pos(x))).
  • To apply a constant lower bound f(x)\geq \alpha, then you can just multiply through to get 1\geq \alpha g(x), which is just 1 >= alpha*sum(inv_pos(x)).

What we cannot do, to the best of our knowledge, is f(x) \geq y, or equivalently 1 \geq y g(x), where both x and y are variables. If anyone knows how, please tell us, and I’ll put harm_mean into the function library! But that’s exactly the form I need in order to do that.

Again, x can be replaced with a vector of concave expressions according to the DCP rules, because inv_pos is convex and decreasing.