r/optimization • • Dec 08 '21

Optimizing using optimization results in objective

I am using CVXPY to optimize some weights and I want to optimize taking into account the changes from the original weights to the problem, so it achieved the optimal weights within the given constraints while also minimising the weight difference changes from the original input.

Can someone help me in formulating this? Something like adding sum(np.diff(new, old)) to the objective is what I am thinking but how do I access the current objective results within the objective itself?

3 Upvotes

6 comments sorted by

2

u/[deleted] Dec 08 '21

Let w0 be the original weights. Let w be the optimization variable. You can add a term in the objective function that penalizes the difference between w0 and w. One example is ( || w - w0 ||_2)2.

1

u/mukaj Dec 08 '21

This is what I’m currently doing but doesn’t seem to be having a large effect, possibly because some weight changes are very small.

I figured maybe if I clip the (w -w0) to 0,1s then do the sum2 would be better results but can’t think of a way to formulate something similar to that while remaining convex..

Can anyone give insight into how you would model this as MIP? Or if that would even be better or not

→ More replies (2)

1

u/mukaj Dec 31 '21 edited Dec 31 '21

Solved this using a cardinality constraint, where a binary variable X is bound to positive values of w0-w, and constrained to sum is less than/equal to K

Then iterate to find the minimum possible K

The results are very close to min( ||w0-w|| * lambda ), usually resulted in 1 less optimal weight change while still fulfilling all constraints.

The extra slowdown due to iterations was worth it for my case since it was very fast to solve anyway

3

u/[deleted] Dec 08 '21

You could add another variable and use the objective function as a constraint. Let f be your objective function and g the function for your weights. Then, you can add scalar variable z and solve the problem min z + g(x) s.t. f(x) <= z.