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