Recipe/Theory/Non-negative least squares

From Open Food Facts wiki
Revision as of 12:53, 21 February 2025 by Aleene (talk | contribs) (Created page with "== Theoretical solution == The best mathematical solution to the recipe estimation problem is offer by the non-negative least squares approach. There are multiple algorithms t...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Theoretical solution

The best mathematical solution to the recipe estimation problem is offer by the non-negative least squares approach. There are multiple algorithms to solve approach. In this approach the general equation is:

pj = β0 + β1x1j + .... + βNxNj

In this is

  • pj - the nutritional value of the product for nutrient j;
  • β0 - the base value without any ingredients;
  • β1 - the fraction of ingredient 1 in the recipe;
  • x1j - the nutritional value of ingredient 1 for nutrient j;
  • N - the total number of ingredients;
  • M - the total number of nutrients used;

It is clear that β0 must be zero and should be set as such in some solvers.

The values for βi will always be larger than 0. We are yet to see ingredients that will subtract nutrients.

Thus a solver that forces the βi larger than 0 is required

Non-Negative Least Squares

Solvers that only support solutions with βi > 0 are called Non-Negative Least Squares.

There seem to be many implementations for this. For instance nnls in the Rstudio package. Or nnls in the SciPy-package.

Unfortunately this approach does not always give the results we are looking for. The results favour ingredients that dominate the nutrients, like oil, sugar or salt. In most case the other ingredients are not needed and set to zero. In fact most products can be explained through these dominating ingredients. So another solution is needed that forces the other ingredients to participate.

Non-Negative Least Squares with forced order

Comparing approaches