P is for Practical PerlMonks

### Re: Module/Algorithm to reduce data points?

by kvale (Monsignor)
 on Apr 24, 2006 at 18:29 UTC ( #545345=note: print w/replies, xml ) Need Help??

in reply to Module/Algorithm to reduce data points?

If you simply want to reduce the number of points, use a decimation procedure. For example if you want to eliminate half the points, sort the points on the x or y axis and throw out the odd numbered points, keeping the even points.

If your goal is to somehow approximate the curve that these points lie upon, you want to do some sort of regression, that is, create a statistical model of the process generating the points and fit the parameters of the model. An example module that would do this in the linear case is Statistics::Regression. From the synopsis:

```use Statistics::Regression;

# Create regression object
my \$reg = Statistics::Regression->new(
3, "sample regression",
[ "const", "someX", "someY" ]
);

\$reg->include( 2.0, [ 1.0, 3.0, -1.0 ] );
\$reg->include( 1.0, [ 1.0, 5.0, 2.0 ] );
\$reg->include( 20.0, [ 1.0, 31.0, 0.0 ] );
\$reg->include( 15.0, [ 1.0, 11.0, 2.0 ] );

# Print the result
\$reg->print();

# Prints the following:
# ****************************************************************
# Regression 'sample regression'
# ****************************************************************
# Theta[0='const']=       0.2950
# Theta[1='someX']=       0.6723
# Theta[2='someY']=       1.0688
# R^2= 0.808, N= 4
# ****************************************************************

# Or, to get the values of the coefficients and R^2
my @theta = \$reg->theta;
my \$rsq   = \$reg->rsq;

-Mark

Create A New User
Node Status?
node history
Node Type: note [id://545345]
help
Chatterbox?
 cavac replaces stale cookies with fresh on the platter on the sideboard.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (7)
As of 2017-06-23 05:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
How many monitors do you use while coding?

Results (536 votes). Check out past polls.