# Loss function with scalable constraints

**URL:** <https://discourse.julialang.org/t/loss-function-with-scalable-constraints/92433>\
**Category:** General Usage\
**Created:** [January 2, 2023, 10:43pm UTC](https://discourse.julialang.org/t/loss-function-with-scalable-constraints/92433 "2023-01-02T22:43:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Post date:** [January 2, 2023, 10:43pm UTC](https://discourse.julialang.org/t/loss-function-with-scalable-constraints/92433/1 "2023-01-02T22:43:39Z")

</div>

Assume a loss function of the firm L1 + a \* L2 where L1 and L2 depend on model parameters. I wish to adjust the coefficient ‘a’ so that the two terms have equal magnitude. However, I do not want the coefficient to be differentiated by Zygote. How is this achieved? Thanks.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [January 2, 2023, 10:57pm UTC](https://discourse.julialang.org/t/loss-function-with-scalable-constraints/92433/2 "2023-01-02T22:57:43Z")

</div>

Sounds like you may want to solve a maximin problem, i.e. you want \min\_p \{ \ell\_1(p), \ell\_2(p) \} so that the two terms are typically balanced at the minimum?

If so, this can be turned into a differentiable NLP with an “epigraph” transformation: min\_{p,t} t subject to t \ge \ell\_1(p),\;t\ge \ell\_2(p).

---

<div class="post-metadata">

**Author:** ![erlebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/erlebach/32/12973_2.png) [@erlebach](https://discourse.julialang.org/u/erlebach)\
**Post date:** [January 2, 2023, 11:38pm UTC](https://discourse.julialang.org/t/loss-function-with-scalable-constraints/92433/3 "2023-01-02T23:38:49Z")

</div>

Thanks. I am minimizing an AL2 norm subject to a sparsity inducing L1 norm to induce sparsity. Since I do not know the optimum value of the Lagrange multiplier, I wanted to try equating the magnitude of the two norms.
