# How to measure how erratic is a function between a and b

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.

-
You could look up the arclength integral... – J. M. Apr 14 '12 at 9:21
No idea on what are you talking about :) (I'm not a mathematic) but I will take a look at wikipedia. Thanks! – SoMoS Apr 14 '12 at 9:29
Right, so type the words "arclength" and "integral" into your favorite search engine, and enjoy. Note that most such integrals do not have nice simple forms, and numerics would be needed. – J. M. Apr 14 '12 at 9:32
Do you mean that they cannot be calculated by an algorithm? I'm developing software. – SoMoS Apr 14 '12 at 9:38

1
Stock Trading ... – SoMoS Apr 14 '12 at 9:52
show 4 more comments

## 2 Answers

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.

-

You rock man. That's what I was looking for and the wiki explanation is great. Thanks again. – SoMoS Apr 14 '12 at 20:25

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.

-

Looks as a good way. I specially like the quadratic feature to penalize more the more erratic points. Thanks, you rock too. – SoMoS Apr 14 '12 at 20:27
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 5, "mathjax_display_tex": 2, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": false}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "github"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "english_confidence": 0.9409230947494507, "perplexity_flag": "middle"}