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