geo_mean function

Geometric Mean

Geometric Mean

The (weighted) geometric mean of vector xx with optional powers given by pp. methods

geo_mean(x, p = NA_real_, max_denom = 1024)

Arguments

  • x: An Expression or vector.
  • p: (Optional) A vector of weights for the weighted geometric mean. Defaults to a vector of ones, giving the unweighted geometric mean x11/nxn1/nx_1^{1/n} \cdots x_n^{1/n}.
  • max_denom: (Optional) The maximum denominator to use in approximating p/sum(p) with w. If w is not an exact representation, increasing max_denom may offer a more accurate representation, at the cost of requiring more convex inequalities to represent the geometric mean. Defaults to 1024.

Returns

An Expression representing the geometric mean of the input.

Details

(x1p1xnpn)11Tp \left(x_1^{p_1} \cdots x_n^{p_n} \right)^{\frac{1}{\mathbf{1}^Tp}}

The geometric mean includes an implicit constraint that xi0x_i \geq 0 whenever pi>0p_i > 0. If pi=0,xip_i = 0, x_i will be unconstrained. The only exception to this rule occurs when pp has exactly one nonzero element, say pip_i, in which case geo_mean(x,p) is equivalent to xix_i (without the nonnegativity constraint). A specific case of this is when xR1x \in \mathbf{R}^1.

Examples

x <- Variable(2) cost <- geo_mean(x) prob <- Problem(Maximize(cost), list(sum(x) <= 1)) result <- solve(prob) result$value result$getValue(x) ## Not run: x <- Variable(5) p <- c(0.07, 0.12, 0.23, 0.19, 0.39) prob <- Problem(Maximize(geo_mean(x,p)), list(p_norm(x) <= 1)) result <- solve(prob) result$value result$getValue(x) ## End(Not run)
  • Maintainer: Anqi Fu
  • License: Apache License 2.0 | file LICENSE
  • Last published: 2024-11-07