I encountered a task where I have some discrete set of data points $(x_1, y_1), \ldots, (x_n, y_n)$, where
$x_1 < x_2 < \ldots < x_n$.
The discrete function graph they form should ideally be convex, but due to some noise and errors it deviates slightly from being convex everywhere.
I would therefore like to replace the $\{ y_i \}_{i=1, \ldots, n}$ with values $\{ w_i \}_{i=1, \ldots, n}$ so that the new function graph given by the points $(x_1, w_1), \ldots, (x_n, w_n)$ is convex and the squared difference
$$
\sum_{i=1}^n (y_i - w_i)^2
$$
is minimal.
I don't want to assign any parametric model for the $\{ w_i \}_{i=1, \ldots, n}$ unless I have to, since it should not be necessary to do so. This problem should be solvable anyway.
Maybe this is some well known stuff. I would then be thankful if anyone could point me to some good references.
One can of course write it as a general optimization problem in the $n$ unknown variables $\{ w_i \}_{i=1, \ldots, n}$ with a lot of inequalities as side conditions representing the convexity condition.
However, I would prefer some simpler solution, if it exists, or some algorithm that does not give the perfect optimal result, but still a convex graph that approximates the old graph "good enough".
Using a cubic spline we can easily obtain good convex/concave fitting.
Follows a MATHEMATICA script which smooths the data imposing convexity/concavity as required. The quadratic spline has
nequal spaced intervals, from0untiltmax, with coefficients at each interval given bya[k], b[k], c[k]or as $s(k,t) = a_k + b_k(t-k\delta)+c_k(t-k\delta)^2$After the spline formal definition the continuity conditions are introduced.
so the final independent parameters are given in
Now we define a function with concave epigraph, generating data added to noise
Follows a minimization procedure to determine de spline coefficients.
Due to epigraph concavity the condition is $c_k < \kappa$. Here $\kappa$ is the minimum acceptable to avoid the inclusion of line segments $(c_k = 0)$.
Now the minimization results:
result1with imposed concavity andresult2without conditions.Follows a graph shoving in red the data points, in dashed blue the unrestricted minimization and in blue continuous the conditioned minimization.
NOTE
The same data processed with a cubic spline. In this case the concavity/convexity is respectively $d_k > 0, \ \ d_k < 0$