.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Linfit 3pm" .TH Linfit 3pm "2021-04-02" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" PDL::Fit::Linfit \- routines for fitting data with linear combinations of functions. .SH "DESCRIPTION" .IX Header "DESCRIPTION" This module contains routines to perform general curve-fits to a set (linear combination) of specified functions. .PP Given a set of Data: .PP .Vb 1 \& (y0, y1, y2, y3, y4, y5, ...ynoPoints\-1) .Ve .PP The fit routine tries to model y as: .PP .Vb 1 \& y\*(Aq = beta0*x0 + beta1*x1 + ... beta_noCoefs*x_noCoefs .Ve .PP Where x0, x1, ... x_noCoefs, is a set of functions (curves) that the are combined linearly using the beta coefs to yield an approximation of the input data. .PP The Sum-Sq error is reduced to a minimum in this curve fit. .PP \&\fBInputs:\fR .ie n .IP "$data" 1 .el .IP "\f(CW$data\fR" 1 .IX Item "$data" This is your data you are trying to fit. Size=n .ie n .IP "$functions" 1 .el .IP "\f(CW$functions\fR" 1 .IX Item "$functions" 2D array. size (n, noCoefs). Row 0 is the evaluation of function x0 at all the points in y. Row 1 is the evaluation of of function x1 at all the points in y, ... etc. .Sp Example of \f(CW$functions\fR array Structure: .Sp \&\f(CW$data\fR is a set of 10 points that we are trying to model using the linear combination of 3 functions. .Sp .Vb 4 \& $functions = ( [ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ], # Constant Term \& [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 ], # Linear Slope Term \& [ 0, 2, 4, 9, 16, 25, 36, 49, 64, 81] # quadradic term \& ) .Ve .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 1 \& $yfit = linfit1d $data, $funcs .Ve .SH "FUNCTIONS" .IX Header "FUNCTIONS" .SS "linfit1d" .IX Subsection "linfit1d" 1D Fit linear combination of supplied functions to data using min chi^2 (least squares). .PP .Vb 1 \& Usage: ($yfit, [$coeffs]) = linfit1d [$xdata], $data, $fitFuncs, [Options...] .Ve .PP .Vb 1 \& Signature: (xdata(n); ydata(n); $fitFuncs(n,order); [o]yfit(n); [o]coeffs(order)) .Ve .PP Uses a standard matrix inversion method to do a least squares/min chi^2 fit to data. .PP Returns the fitted data and optionally the coefficients. .PP One can thread over extra dimensions to do multiple fits (except the order can not be threaded over \- i.e. it must be one fixed set of fit functions \f(CW\*(C`fitFuncs\*(C'\fR. .PP The data is normalised internally to avoid overflows (using the mean of the abs value) which are common in large polynomial series but the returned fit, coeffs are in unnormalised units. .PP .Vb 3 \& # Generate data from a set of functions \& $xvalues = sequence(100); \& $data = 3*$xvalues + 2*cos($xvalues) + 3*sin($xvalues*2); \& \& # Make the fit Functions \& $fitFuncs = cat $xvalues, cos($xvalues), sin($xvalues*2); \& \& # Now fit the data, Coefs should be the coefs in the linear combination \& # above: 3,2,3 \& ($yfit, $coeffs) = linfit1d $data,$fitFuncs; .Ve .PP .Vb 2 \& Options: \& Weights Weights to use in fit, e.g. 1/$sigma**2 (default=1) .Ve