The (weighted) geometric mean of vector x with optional powers given by p.
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/n⋯xn1/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
(x1p1⋯xnpn)1Tp1
The geometric mean includes an implicit constraint that xi≥0 whenever pi>0. If pi=0,xi will be unconstrained. The only exception to this rule occurs when p has exactly one nonzero element, say pi, in which case geo_mean(x,p) is equivalent to xi (without the nonnegativity constraint). A specific case of this is when x∈R1.
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)