3
$\begingroup$

I need to compare the outputs of some functions and to rate their "erratness".

Given a function, the less erratic function between a and b would be a straight line and the more erratic function would probably be a triangular or sine wave, the bigger its amplitude or its frequency the bigger their erratness. I'm not sure if it's clear what I mean.

I've thought that a way to calculate it could be to calculate the length of the line generated by the function between a and b. The smaller the length the less erratic will be the function.

The questions are:

  1. Do you think this is a good way to achieve what I need?
  2. How can the length of the output of a function be calculated?

Thanks in advance.

  • 1
    Stock Trading ...2012-04-14

2 Answers 2

4

There is something called the total variation of a function. If the function is differentiable, it's computed as $\int_a^b|f'(x)|\,dx$. There are standard methods for computing the derivative and the integral numerically. If the function is not differentiable, there's a different definition, which should also be suitable for numerical computation. See the discussion at http://en.wikipedia.org/wiki/Total_variation.

  • 0
    You rock man. That's what I was looking for and the wiki explanation is great. Thanks again.2012-04-14
3

If the end-use is an algorithm that must run quickly, your best bet is probably the sum squared difference (or SSD). If the line running between points $a$ and $b$ is: $ y = mx +n$ Then you want to sum the squared difference between each point $(x_i,y_i)$ and the line: $SSD\equiv\sum{(y_i - mx_i -n)^2}$

The smaller the $SSD$, the less "erratic" your function. Also note that if you have many points and not many computer cycles available, you may want to choose a small random subset of the points instead of summing over all of them.

  • 0
    Looks as a good way. I specially like the quadratic feature to penalize more the more erratic points. Thanks, you rock too.2012-04-14