Let $x_1,...x_K \geq 0$ and $f$ be the piecewise-linear function given by $f(k)=x_k$ for every $1 \leq k \leq K$. Denote by $m$ the number of modes (i.e. local maxima) of $f$. Let's associate with every $x_k$ a weight $\mu_k \geq 0$. Now consider the set $B_m$ of all piecewise-linear functions with strictly less than $m$ modes. I am interested in computing $$ \inf_{g \in B_m} \sum_{k=1}^{K} \mu_k\left[f(k)-g(k)\right]^2, $$ that is finding the best approximation of $f$ in the weighted least square sense that is also piecewise-linear and with at least one less local maximum.
I'm not sure computing the infimum is doable, but I would at least like to restrict the set $B_m$ of "minimizing candidates" to a significantly smaller subset.
To that end, I have managed to prove that if $g$ achieves the infimum, then for every $k$, we either have $g(k)=f(k)$ or $g(k) \in \left\{g(k-1),g(k+1)\right\}$, which allows us to reduce the set $B_m$ to the functions of $B_m$ that verifies this condition.
I also believe that an optimal approximation will only modify points between two fixed modes of $f$, but I wasn't able to prove it.