How do I rate smoothness of discretely sampled data? (Picture!!!) In the sense that the following curves pictured in order will be rated 98%, 80%, 40%, 5% smooth approximating by eye.
My ideas:  
(1) If the curves all follow some general shape like a polynomial curve then do curve fitting and calculate the total "distance from the curve" of the data.
(2) Count the number of times a slope line between two datapoints intersects the data lines (line segments between data points) and divide by the number of data samples.
Your ideas?

 A: A simple approach would be to calculate the slope of the interpolating line between every successive pair of points, then take the standard deviation of the slopes.
A: Regard your data points as simple support points
through which an elastic thin beam has to pass.
The beam deforms to a curve that minimizes the energy required for bending it.
You might be interested in that amount of energy.
It can be used to measure the beam curve's deviation from a straight line.
The simplest theory for thin elastic beams is Bernoulli's beam theory,
and its solution for the given problem is equivalent to cubic spline interpolation.
Without going into much details, the method would therefore be the following:


*

*Apply the first step of a cubic spline interpolation algorithm
to your data. That step determines the cubic spline pieces
for later interpolation. It takes your data points
$(x_0,y_0),\ldots,(x_n,y_n)$ and gives you estimates of derivatives
$y_0',\ldots,y_n'$ at the sample points, obtained by solving a tridiagonal
system of equations.
Some numerical libraries are generous enough
to also give you second derivatives $y_0'',\ldots,y_n''$
as part of the solution. Otherwise you can compute them as
$$\begin{align}
   y_0'' &= 0 = y_n'' \\
   y_k'' &= \frac{2}{\ell_k^2}
   \left(3(y_{k-1} - y_k) + \ell_k (y_{k-1}' + 2y_k')\right)
   && \text{for } k = 1,\ldots,n \\
   &= \frac{2}{\ell_{k+1}^2}
   \left(3(y_{k+1} - y_k) - \ell_{k+1} (y_{k+1}' + 2y_k')\right)
   && \text{for } k = 0,\ldots,n-1 \\
   &\text{where }
   \ell_k = x_k-x_{k-1}
   \end{align}$$
Besides, the above equations state that the second derivative
is zero at the ends and continuous across pieces.
The tridiagonal system for the $y_k'$ can be derived from these conditions.

*Compute the bending energy $W$. This is essentially
$$2W = \int_{x_0}^{x_n} y''(x)^2\mathrm{d}x$$
where $y(x)$ is the piecewise cubic spline.
If you already have the second derivatives at the sample points,
note that these are interpolated linearly in each piece, so the
integral can be simplified to
$$6W = \sum_{k=1}^n \ell_k (y_{k-1}''^2 + y_{k-1}''y_k'' + y_k''^2)$$
If step 1 has given you first derivatives only
and you have been too lazy to compute the second derivatives,
you can as well use the (known) stiffness matrix of cubic splines:
$$W = \sum_{k=1}^n \frac{1}{\ell_k^3}
   \begin{bmatrix}
   y_{k-1} \\ y_{k-1}' \\ y_k \\ y_k'
   \end{bmatrix}^\top
   \begin{bmatrix}
   6       & 3\ell_k   & -6       & 3\ell_k \\
   3\ell_k & 2\ell_k^2 & -3\ell_k & \ell_k^2 \\
   -6      & -3\ell_k  & 6        & -3\ell_k \\
   3\ell_k & \ell_k^2  & -3\ell_k & 2\ell_k^2 \\
   \end{bmatrix}
   \begin{bmatrix}
   y_{k-1} \\ y_{k-1}' \\ y_k \\ y_k'
   \end{bmatrix}$$


Do not forget to test your implementation:
For example, constant-slope lines should have bending energy $W=0$.
