3.6. Objective¶
Every model has at most one objective, and that objective must evaluate to a scalar. The model sense is minimization by default.
For a first model, it helps to think of the objective as one final scalar built from three layers:
a fit term that measures how well the model matches the data
a regularization term that expresses what kind of solution you prefer
an optional structural term for extra smoothness, barriers, or domain-specific shaping
Rule |
What it means in practice |
|---|---|
one objective per model |
combine fit, regularization, and other terms into one final scalar expression |
scalar-valued expression |
aggregate vectorized losses with functions such as |
minimization by default |
write the quantity you want to minimize directly |
3.6.1. Build the Objective in Layers¶
Start with the simplest fit term that captures the task. Then add regularization only if it helps resolve
ambiguity or improves the kind of solution you want. If the model still needs extra structure, add a third
term and sum everything into one scalar before calling Model.setObjective().
For example, a common beginner pattern is a least-squares fit with L1 regularization and an optional smoothness term:
fit = 0.5 * admm.sum(admm.square(A @ x - b))
regularization = lam * admm.norm(x, ord=1)
structure = mu * admm.sum(admm.square(D @ x))
model.setObjective(fit + regularization + structure)
If you do not need the third term, leave it out. If your expression is already scalar, such as
admm.norm(A @ x - b, ord=1), you can pass it directly to Model.setObjective().
For matrix models, the optional structural term might instead be a barrier or spectral expression such as
-admm.log_det(X) + admm.trace(S @ X).
3.6.2. Common Objective Ingredients¶
Common objective functions are summarized below. In practice, most models choose one fit term from this table and then add one regularizer before exploring more specialized structure.
Ingredient family |
Example |
|---|---|
linear objective |
|
least-squares data fit |
|
quadratic regularization |
|
sparsity regularization |
|
robust loss |
|
classification loss |
|
matrix barrier or spectral term |
|
user-defined proximal term |
|
For the full atom catalog, see Supported Building Blocks. For feasibility conditions that accompany the objective, see Constraints.