ace.smoother module

Scatterplot smoother with a fixed span.

Takes x,y scattered data and returns a set of (x,s) points that form a smoother curve fitting the data with moving least squares estimates. Similar to a moving average, but with better characteristics. The fundamental issue with this smoother is that the choice of span (window size) is not known in advance. The SuperSmoother uses these smoothers to figure out which span is optimal.

This is a Python port of J. Friedman’s 1982 fixed-span Smoother [Friedman82]

Example:

s = Smoother()
s.specify_data_set(x, y, sort_data = True)
s.set_span(0.05)
s.compute()
smoothed_y = s.smooth_result
class ace.smoother.Smoother[source]

Bases: object

Smoother that accepts data and produces smoother curves that fit the data.

add_data_point_xy(x, y)[source]

Add a new data point to the data set to be smoothed.

specify_data_set(x_input, y_input, sort_data=False)[source]

Fully define data by lists of x values and y values.

This will sort them by increasing x but remember how to unsort them for providing results.

Parameters:
x_inputiterable

list of floats that represent x

y_inputiterable

list of floats that represent y(x) for each x

sort_databool, optional

If true, the data will be sorted by increasing x values.

set_span(span)[source]

Set the window-size for computing the least squares fit.

Parameters:
spanfloat

Fraction on data length N to be considered in smoothing

compute()[source]

Perform the smoothing operations.

plot(fname=None)[source]

Plot the input data and resulting smooth.

Parameters:
fnamestr, optional

name of file to produce. If none, will show interactively.

class ace.smoother.BasicFixedSpanSmoother[source]

Bases: Smoother

A basic fixed-span smoother.

Simple least-squares linear local smoother.

Uses fast updates of means, variances.

compute()[source]

Perform the smoothing operations.

class ace.smoother.BasicFixedSpanSmootherSlowUpdate[source]

Bases: BasicFixedSpanSmoother

Use slow means and variances at each step. Used to validate fast updates.

ace.smoother.DEFAULT_BASIC_SMOOTHER

alias of BasicFixedSpanSmoother

ace.smoother.perform_smooth(x_values, y_values, span=None, smoother_cls=None)[source]

Run the basic smoother (convenience function).

Parameters:
x_valuesiterable

List of x value observations

y_ valuesiterable

list of y value observations

spanfloat, optional

Fraction of data to use as the window

smoother_clsClass

The class of smoother to use to smooth the data

Returns:
smootherobject

The smoother object with results stored on it.