Reference > Properties > Flexibility Property

SharpPlot.Flexibility Property

When you use the ‘Trend’ style to draw an approximate curve through a scatter of points, it uses a default ‘flex’ value of 3 which actually sets the rate of die-away of the gaussian weighting used to emphasise nearby points.

public double Flexibility {get; set;}

A value of 0 will just draw an average (all points are weighted equally). A value of 100 will effectively force the line to visit every point. You will need to experiment with particular datasets to find the value that best hides the noise and reveals the underlying pattern in the data.

Example

sp.Flexibility = 4;

Technical data

For the statistically-minded, who want to know how this actually works!

It is a Gaussian-weighted moving average. The ‘Flexibility’ sets the exponent of the gaussian, so the way SharpPlot calculates it is to divide the x-axis range arbitrarily into 100 parts and for each point compute a y-value by adding up all the y-values from the data, weighted by the x-distance expressed as a classic ‘bell-curve’ function.

I think the more traditional approach is to use an inverse exponential weighting based on the absolute distance, but this ‘peaks’ very sharply and also tends to ‘whiplash’ at the ends, whereas the gaussian is more flat-topped, so the trend is effectively an average of nearby points with far-away points included but heavily discounted.

Basically, it just looks better for most reasonable timeseries!

Note that for very small datasets (below about 10 points) the weighting is adjusted to prevent the curve simply forming plateaux at each data point. This adjustment is simply to maintain visual consistency, and has no mathematical significance whatsoever.

See also ...

SharpPlot Members


Send comments on this topic
© Dyalog Ltd 2013