# Huber objective

**URL:** <https://discourse.julialang.org/t/huber-objective/14338>\
**Category:** Optimization (Mathematical)\
**Tags:** question\
**Created:** [August 30, 2018, 10:36pm UTC](https://discourse.julialang.org/t/huber-objective/14338 "2018-08-30T22:36:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Zranz](https://avatars.discourse-cdn.com/v4/letter/z/90ced4/32.png) [@Zranz](https://discourse.julialang.org/u/Zranz)\
**Post date:** [August 30, 2018, 10:36pm UTC](https://discourse.julialang.org/t/huber-objective/14338/1 "2018-08-30T22:36:47Z")

</div>

Hi. I wanted to know if it is possible to place a Huber loss in the objective of a quadratic problem in JuMP 0.18.  
The Huber function can be defined as follows:

`huber(a,delta)= abs(a) <= delta ? 1/2*a^2 : delta*(abs(a)-1/2*delta)`

For the absolute value, I can always use the trick of adding a slack variable z = abs(a) and use that:  
@variable(m, z)  
@constraint(m, z\>=a)  
@constraint(m, z\<=-a)

But I don’t know how to solve the piecewise part. I get the following error:  
`MethodError: no method matching isless(::Float64, ::JuMP.Variable)`

Is there a way to code this, or not currently supported? Thank you.

---

<div class="post-metadata">

**Author:** ![bbrunaud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bbrunaud/32/1737_2.png) [@bbrunaud](https://discourse.julialang.org/u/bbrunaud)\
**Post date:** [August 31, 2018, 4:32am UTC](https://discourse.julialang.org/t/huber-objective/14338/2 "2018-08-31T04:32:06Z")

</div>

What you have in the objective function is a disjunction. They can be modeled and formulated with a few techniques such as the Big M. Check:

Raman, Ramesh, and Ignacio E. Grossmann. “Modelling and computational techniques for logic based integer programming.” _Computers & Chemical Engineering_ 18, no. 7 (1994): 563-578.

Also check [ConditionalJuMP](https://github.com/rdeits/ConditionalJuMP.jl), a package to will do the transformations for you.

regards

---

<div class="post-metadata">

**Author:** ![Zranz](https://avatars.discourse-cdn.com/v4/letter/z/90ced4/32.png) [@Zranz](https://discourse.julialang.org/u/Zranz)\
**Post date:** [August 31, 2018, 11:40pm UTC](https://discourse.julialang.org/t/huber-objective/14338/3 "2018-08-31T23:40:46Z")

</div>

Thank you for the reference and the package. I’ll definitely try that one.
