# Bounded regression on data streams

# 1 Bounded Regression on Data Streams

Hsien-Chih sent me this problem. Similar problem has been asked on Quora. He noticed it might be solved in near linear time using min-cost circulation. Here we show a generalization.

Given

- $(a_{1},…,a_{n})∈R_{n}$,
- $(w_{1},…,w_{n})∈R_{+}$,
- $(l_{1},…,l_{n−1})≤(u_{1},…,u_{n−1})∈R_{n}$.

Output $(x_{1},…,x_{n})∈R_{n}$ such that $l_{i}≤x_{i+1}−x_{i}≤u_{i}$ for all $1≤i<n$, and minimize $∑_{i=1}w_{i}∣a_{i}−x_{i}∣$.

# 2 Reduce the problem to min-cost circulation

It’s natural to model this problem as variations of min-cost circulation problem on a graph.

The graph $G=(V,E)$ with vertices $V={s,v_{0},…,v_{n}}$.

Edges:

- Edge $v_{i}v_{i+1}$ for all $0≤i<n$.
- Edge $sv_{i}$ for all $0≤i≤n$.

Edge Capacity:

- $sv_{i}$ has lower bound $l_{i}$, upper bound $u_{i}$ for all $1≤i≤n−1$.
- All other edges are uncapacited. Namely lower bound and upper bound are $−∞$ and $∞$ respectively.

Edge Costs: $v_{i−1}v_{i}$ has cost function $c_{i}(x)=w_{i}∣a_{i}−x∣$. Cost function on other edges are $0$.

A function $f$ is called a circulation if $∑_{e∈δ_{+}(v)}f(e)−∑_{e∈δ_{−}(v)}f(e)=0$ for all vertex $v$. It is feasible if $f(e)$ is within the capacity. It is min-cost if $∑_{e}c_{e}(f(e))$ is minimized.

Solving the min-cost circulation problem would give us the desired $x_{i}$ by setting $x_{i}=f(v_{i−1}v_{i})$.

# 3 min-cost circulation on series-parallel graphs

The constructed graph is a two terminal series-parallel graph. There is a simple procedure to solve min-cost flow problem on series-parallel graphs. Consider a series connection of two edges, each with cost function $f$ and $g$. We can replace it with an edge with cost function $f+g$. If it is a parallel connection, then we can replace it with one edge and a cost function $f□g$, where $□$ is the infimal convolution: $(f□g)(x)=f_{y}f(x−y)+g(y)$.

Once we have a good data structure to represent the costs, we can reduce the graph to one single edge easily, and find the minimum cost circulation. In particular, if the cost are continuous, convex and piecewise linear in a interval and $∞$ everywhere else, and the total number of breakpoints is $n$, then Booth and Tarjan has an algorithm that runs in $O(ngn)$ time [1].

Because all edge has a cost function with at most $1$ breakpoint. The bounded regression problem can be solved in $O(ngn)$ time.

# 4 Isotonic regression

We can try to minimize $∑_{i=1}w_{i}(a_{i}−x_{i})_{2} $ instead ($L_{2}$ error). It is a generalization of the lipschitz isotonic regression problem [2] when $l_{i}=0$ and $u_{i}=u$ for some constant $u$. We can also ask to minimize the $L_{∞}$ error.

If the upper bounds are $∞$ and all lower bounds are $0$, then the problem is called the isotonic regression problem. I have solved a interesting problem using isotonic regression.

We can express all the problems as min-cost circulation problem on a appropriate graph. If the min-cost circulation algorithm on those graphs have the same running time as current best algorithm, it would imply something more general is acting in the background.

Here is what we know.

- $L_{1}$ error: This post shows it can be solved in $O(ngn)$ time using the min-cost circulation formulation. It matches the running time of specialized algorithms.
- $L_{2}$ error: It can be solved in $O(n)$ time, but doesn’t come from the quadratic cost min-cost circulation formulation.
- $L_{∞}$ error: It can be solved in $O(n)$ time. However, it doesn’t come from the minimax circulation problem. (In the minimax circulation, the cost is the largest edge cost incurred by the circulation).
- $L_{0}$ error: It can be solved in $O(ngn)$ time. This is equivalent to the longest non-decreasing subsequence problem.

This prompt the following two natural problems:

*Can min-cost circulation with quadratic cost on series parallel graph have $O(n)$ time solution?*This is in fact possible when all edges have no capacity[3]. But with capacity, even for a edge with a lower bound of $0$ and $0$ cost, we don’t know.*What about minimax circulation?*We can’t find any study of minimax circulation on series-parallel graphs.

# References

**Finding the minimum-cost maximum flow in a series-parallel network**, Journal of Algorithms. 15 (1993) 416–446 10.1006/jagm.1993.1048.

**Estimation of flows in flow networks**, European Journal of Operational Research. 176 (2007) 691–706 10.1016/j.ejor.2005.08.009.