1Linfit(3)             User Contributed Perl Documentation            Linfit(3)
2
3
4

NAME

6       PDL::Fit::Linfit - routines for fitting data with linear combinations
7       of functions.
8

DESCRIPTION

10       This module contains routines to perform general curve-fits to a set
11       (linear combination) of specified functions.
12
13       Given a set of Data:
14
15         (y0, y1, y2, y3, y4, y5, ...ynoPoints-1)
16
17       The fit routine tries to model y as:
18
19         y' = beta0*x0 + beta1*x1 + ... beta_noCoefs*x_noCoefs
20
21       Where x0, x1, ... x_noCoefs, is a set of functions (curves) that the
22       are combined linearly using the beta coefs to yield an approximation of
23       the input data.
24
25       The Sum-Sq error is reduced to a minimum in this curve fit.
26
27       Inputs:
28
29       $data
30        This is your data you are trying to fit. Size=n
31
32       $functions
33        2D array. size (n, noCoefs). Row 0 is the evaluation of function x0 at
34        all the points in y. Row 1 is the evaluation of of function x1 at all
35        the points in y, ... etc.
36
37        Example of $functions array Structure:
38
39        $data is a set of 10 points that we are trying to model using the
40        linear combination of 3 functions.
41
42         $functions = ( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ],  # Constant Term
43                        [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ],  # Linear Slope Term
44                        [ 0, 2, 4, 9, 16, 25, 36, 49, 64, 81] # quadradic term
45                    )
46

SYNOPSIS

48           $yfit = linfit1d $data, $funcs
49

FUNCTIONS

51   linfit1d
52       1D Fit linear combination of supplied functions to data using min chi^2
53       (least squares).
54
55        Usage: ($yfit, [$coeffs]) = linfit1d [$xdata], $data, $fitFuncs, [Options...]
56
57       Signature: (xdata(n); ydata(n); $fitFuncs(n,order); [o]yfit(n);
58       [o]coeffs(order))
59
60       Uses a standard matrix inversion method to do a least squares/min chi^2
61       fit to data.
62
63       Returns the fitted data and optionally the coefficients.
64
65       One can thread over extra dimensions to do multiple fits (except the
66       order can not be threaded over - i.e. it must be one fixed set of fit
67       functions "fitFuncs".
68
69       The data is normalised internally to avoid overflows (using the mean of
70       the abs value) which are common in large polynomial series but the
71       returned fit, coeffs are in unnormalised units.
72
73         # Generate data from a set of functions
74         $xvalues = sequence(100);
75         $data = 3*$xvalues + 2*cos($xvalues) + 3*sin($xvalues*2);
76
77         # Make the fit Functions
78         $fitFuncs = cat $xvalues, cos($xvalues), sin($xvalues*2);
79
80         # Now fit the data, Coefs should be the coefs in the linear combination
81         #   above: 3,2,3
82         ($yfit, $coeffs) = linfit1d $data,$fitFuncs;
83
84         Options:
85            Weights    Weights to use in fit, e.g. 1/$sigma**2 (default=1)
86
87
88
89perl v5.12.3                      2009-12-29                         Linfit(3)
Impressum