Step-function Fit with Three Values for a Given Graph

22 Views Asked by At

Given a graph how can we find a step-function that can only take three values to best fit the graph?

For example, given this graph, where the function we want to fit is the one in black. What is the process of finding the three values for y (in the graph y=4, 6, and 8) and the intervals for each of these values to best optimize the fit?

The closest thing I found to this is the 1-dimensional nearest-neighbor interpolation, but I couldn't find an algorithm for that or a way for the fit to take only three values as I want.

I realize how bad my example is. If possible I just want a qualitative description of how one could find a good fit given these restrictions.