我有一个凸问题,其sum_square项运行良好:
from cvxpy import Variable, Parameter, Problem, Minimize
from pandas import Series
target = Variable(n, nonneg=True, name='Target')
optimal = Series([val0, ..., valN], index)
other_func = #some func of target
cost_func = other_func(target) + sum_squares(target - optimal.values)
problem = Problem(Minimize(costs))
但是,在某些情况下,我需要修改问题并在执行sum_square之前对值进行分组。
因为other_func没有分组,所以我不能轻易做到只需要解决“grouped_target”。我还需要解决“目标”问题。像下面这样......
groups = Series([g0, g1, g0, g2, ..., gM, index)
grouped_optimal = optimal.groupBy(groups).sum()
grouped_target = ???
other_func = #same func of target as before
cost_func = other_func(target) + sum_squares(grouped_target - grouped_optimal.values)
problem = Problem(Minimize(costs))
如何将目标变量分组,类似于Pandas但使用CVXPY原子?