The variance and arithmetic mean of affine function are both convex. There is no such API support for there two constraints. Is it possible to add variance and arithmetic mean in the constraint?
import cvxpy as cp
def mean(x):
return cp.sum(x) / x.size
def variance(x, mode='unbiased'):
if mode == 'unbiased':
scale = x.size - 1
elif mode == 'mle':
scale = x.size
else:
raise ValueError('unknown mode: ' + str(mode))
return cp.sum_squares(x - mean(x)) / scale
If someone wants to make a PR for these functions, I'd be happy to review it. Right now those functions only work on individual vectors. A proper implementation will handle axis options, and do more careful parsing of the mode string in the variance function (e.g. convert to lowercase).
Edit: x in those functions can be any affine expression.
Most helpful comment
If someone wants to make a PR for these functions, I'd be happy to review it. Right now those functions only work on individual vectors. A proper implementation will handle axis options, and do more careful parsing of the
modestring in the variance function (e.g. convert to lowercase).Edit:
xin those functions can be any affine expression.