<commit_before>---
category: example
excerpt: "Be careful with unnecessary symbolic overhead"
title: "Working with sparse parameterizations in optimizer"
tags: [Optimizer, Tricks, Common mistakes]
date: 2018-10-12
---

Notice that the core in YALMIP has had some performance improvements which makes the use of an optimizer object less beneficial in this example. Nevertheless, the general idea introduced here with a sparse parameterization in the optimizer is still important.
{: .notice--info}

The [optimizer framework](/command/optimizer) can be used to reduce overhead significantly when solving many similiar problems, by pre-compiling a model parameterized in set of parameters which can change.

The goal with [optimizer](/command/optimizer) is to move as much as possible of YALMIP overhead related to model analysis, solver selection, operator modelling, and extraction of low-level numerical models closer to solver formats, to a pre-compilation stage, and then only adjust a small part of the partially compiled model when some parameter changes, before compiling the final solver model and sending it to the solver. 

However, with a complicated parameterization, such as when the parameter enters the model nonlinearly with decision variables (bilinear being the typical case, as below), this still requires rather complicated symbolic manipulations when forming the final model given a parameter value. 

In the following model, we are going to study a case where we intend to solve a large ampount of non-negativity constrained least-squares problems \\( \min_{x\geq 0} \left\lVert Ax - b\right\rVert  \\), with the particular feature that all data matrices \\(A\\), which will be a parameter, has a known sparse banded structure.

Let us begin by defining a test-case
<commit_msg>Update 2018-10-12-sparseoptimizer.md<commit_after>---
category: example
excerpt: "Be careful with unnecessary symbolic overhead"
title: Sparse parameterizations in optimizer objects"
tags: [Optimizer, Tricks, Common mistakes]
date: 2018-10-12
---

Notice that the core in YALMIP has had some performance improvements which makes the use of an optimizer object less beneficial in this example. Nevertheless, the general idea introduced here with a sparse parameterization in the optimizer is still important.
{: .notice--info}

The [optimizer framework](/command/optimizer) can be used to reduce overhead significantly when solving many similiar problems, by pre-compiling a model parameterized in set of parameters which can change.

The goal with [optimizer](/command/optimizer) is to move as much as possible of YALMIP overhead related to model analysis, solver selection, operator modelling, and extraction of low-level numerical models closer to solver formats, to a pre-compilation stage, and then only adjust a small part of the partially compiled model when some parameter changes, before compiling the final solver model and sending it to the solver. 

However, with a complicated parameterization, such as when the parameter enters the model nonlinearly with decision variables (bilinear being the typical case, as below), this still requires rather complicated symbolic manipulations when forming the final model given a parameter value. 

In the following model, we are going to study a case where we intend to solve a large ampount of non-negativity constrained least-squares problems \\( \min_{x\geq 0} \left\lVert Ax - b\right\rVert  \\), with the particular feature that all data matrices \\(A\\), which will be a parameter, has a known sparse banded structure.

Let us begin by defining a test-case

{'fraction_non_alphanumeric': 0.05231109880985331, 'fraction_numerical': 0.0071962358151120955, 'mean_word_length': 4.819645732689211, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '968376', 'n_tokens_mistral': 888, 'n_tokens_neox': 821, 'n_words': 504}