1# This file was automatically generated by SWIG (http://www.swig.org). 2# Version 4.0.1 3# 4# Do not make changes to this file unless you know what you are doing--modify 5# the SWIG interface file instead. 6 7package Math::GSL::Fit; 8use base qw(Exporter); 9use base qw(DynaLoader); 10package Math::GSL::Fitc; 11bootstrap Math::GSL::Fit; 12package Math::GSL::Fit; 13@EXPORT = qw(); 14 15# ---------- BASE METHODS ------------- 16 17package Math::GSL::Fit; 18 19sub TIEHASH { 20 my ($classname,$obj) = @_; 21 return bless $obj, $classname; 22} 23 24sub CLEAR { } 25 26sub FIRSTKEY { } 27 28sub NEXTKEY { } 29 30sub FETCH { 31 my ($self,$field) = @_; 32 my $member_func = "swig_${field}_get"; 33 $self->$member_func(); 34} 35 36sub STORE { 37 my ($self,$field,$newval) = @_; 38 my $member_func = "swig_${field}_set"; 39 $self->$member_func($newval); 40} 41 42sub this { 43 my $ptr = shift; 44 return tied(%$ptr); 45} 46 47 48# ------- FUNCTION WRAPPERS -------- 49 50package Math::GSL::Fit; 51 52*gsl_error = *Math::GSL::Fitc::gsl_error; 53*gsl_stream_printf = *Math::GSL::Fitc::gsl_stream_printf; 54*gsl_strerror = *Math::GSL::Fitc::gsl_strerror; 55*gsl_set_error_handler = *Math::GSL::Fitc::gsl_set_error_handler; 56*gsl_set_error_handler_off = *Math::GSL::Fitc::gsl_set_error_handler_off; 57*gsl_set_stream_handler = *Math::GSL::Fitc::gsl_set_stream_handler; 58*gsl_set_stream = *Math::GSL::Fitc::gsl_set_stream; 59*gsl_fit_linear = *Math::GSL::Fitc::gsl_fit_linear; 60*gsl_fit_wlinear = *Math::GSL::Fitc::gsl_fit_wlinear; 61*gsl_fit_linear_est = *Math::GSL::Fitc::gsl_fit_linear_est; 62*gsl_fit_mul = *Math::GSL::Fitc::gsl_fit_mul; 63*gsl_fit_wmul = *Math::GSL::Fitc::gsl_fit_wmul; 64*gsl_fit_mul_est = *Math::GSL::Fitc::gsl_fit_mul_est; 65 66# ------- VARIABLE STUBS -------- 67 68package Math::GSL::Fit; 69 70*GSL_VERSION = *Math::GSL::Fitc::GSL_VERSION; 71*GSL_MAJOR_VERSION = *Math::GSL::Fitc::GSL_MAJOR_VERSION; 72*GSL_MINOR_VERSION = *Math::GSL::Fitc::GSL_MINOR_VERSION; 73*GSL_POSZERO = *Math::GSL::Fitc::GSL_POSZERO; 74*GSL_NEGZERO = *Math::GSL::Fitc::GSL_NEGZERO; 75*GSL_SUCCESS = *Math::GSL::Fitc::GSL_SUCCESS; 76*GSL_FAILURE = *Math::GSL::Fitc::GSL_FAILURE; 77*GSL_CONTINUE = *Math::GSL::Fitc::GSL_CONTINUE; 78*GSL_EDOM = *Math::GSL::Fitc::GSL_EDOM; 79*GSL_ERANGE = *Math::GSL::Fitc::GSL_ERANGE; 80*GSL_EFAULT = *Math::GSL::Fitc::GSL_EFAULT; 81*GSL_EINVAL = *Math::GSL::Fitc::GSL_EINVAL; 82*GSL_EFAILED = *Math::GSL::Fitc::GSL_EFAILED; 83*GSL_EFACTOR = *Math::GSL::Fitc::GSL_EFACTOR; 84*GSL_ESANITY = *Math::GSL::Fitc::GSL_ESANITY; 85*GSL_ENOMEM = *Math::GSL::Fitc::GSL_ENOMEM; 86*GSL_EBADFUNC = *Math::GSL::Fitc::GSL_EBADFUNC; 87*GSL_ERUNAWAY = *Math::GSL::Fitc::GSL_ERUNAWAY; 88*GSL_EMAXITER = *Math::GSL::Fitc::GSL_EMAXITER; 89*GSL_EZERODIV = *Math::GSL::Fitc::GSL_EZERODIV; 90*GSL_EBADTOL = *Math::GSL::Fitc::GSL_EBADTOL; 91*GSL_ETOL = *Math::GSL::Fitc::GSL_ETOL; 92*GSL_EUNDRFLW = *Math::GSL::Fitc::GSL_EUNDRFLW; 93*GSL_EOVRFLW = *Math::GSL::Fitc::GSL_EOVRFLW; 94*GSL_ELOSS = *Math::GSL::Fitc::GSL_ELOSS; 95*GSL_EROUND = *Math::GSL::Fitc::GSL_EROUND; 96*GSL_EBADLEN = *Math::GSL::Fitc::GSL_EBADLEN; 97*GSL_ENOTSQR = *Math::GSL::Fitc::GSL_ENOTSQR; 98*GSL_ESING = *Math::GSL::Fitc::GSL_ESING; 99*GSL_EDIVERGE = *Math::GSL::Fitc::GSL_EDIVERGE; 100*GSL_EUNSUP = *Math::GSL::Fitc::GSL_EUNSUP; 101*GSL_EUNIMPL = *Math::GSL::Fitc::GSL_EUNIMPL; 102*GSL_ECACHE = *Math::GSL::Fitc::GSL_ECACHE; 103*GSL_ETABLE = *Math::GSL::Fitc::GSL_ETABLE; 104*GSL_ENOPROG = *Math::GSL::Fitc::GSL_ENOPROG; 105*GSL_ENOPROGJ = *Math::GSL::Fitc::GSL_ENOPROGJ; 106*GSL_ETOLF = *Math::GSL::Fitc::GSL_ETOLF; 107*GSL_ETOLX = *Math::GSL::Fitc::GSL_ETOLX; 108*GSL_ETOLG = *Math::GSL::Fitc::GSL_ETOLG; 109*GSL_EOF = *Math::GSL::Fitc::GSL_EOF; 110 111@EXPORT_OK = qw/ 112 gsl_fit_linear 113 gsl_fit_wlinear 114 gsl_fit_linear_est 115 gsl_fit_mul 116 gsl_fit_wmul 117 gsl_fit_mul_est 118 /; 119%EXPORT_TAGS = ( all => [ @EXPORT_OK ] ); 120 121__END__ 122 123=encoding utf8 124 125 126=head1 NAME 127 128Math::GSL::Fit - Least-squares functions for a general linear model with one- or two-parameter regression 129 130=head1 SYNOPSIS 131 132 use Math::GSL::Fit qw/:all/; 133 134=head1 DESCRIPTION 135 136The functions in this module perform least-squares fits to a general linear 137model, y = X c where y is a vector of n observations, X is an n by p matrix of 138predictor variables, and the elements of the vector c are the p unknown 139best-fit parameters which are to be estimated. 140 141Here is a list of all the functions in this module : 142 143=over 144 145=item gsl_fit_linear($x, $xstride, $y, $ystride, $n) 146 147This function computes the best-fit linear regression coefficients (c0,c1) of 148the model Y = c_0 + c_1 X for the dataset ($x, $y), two vectors (in form of 149arrays) of length $n with strides $xstride and $ystride. The errors on y are 150assumed unknown so the variance-covariance matrix for the parameters (c0, c1) 151is estimated from the scatter of the points around the best-fit line and 152returned via the parameters (cov00, cov01, cov11). The sum of squares of the 153residuals from the best-fit line is returned in sumsq. Note: the correlation 154coefficient of the data can be computed using gsl_stats_correlation (see 155Correlation), it does not depend on the fit. The function returns the following 156values in this order : 0 if the operation succeeded, 1 otherwise, c0, c1, 157cov00, cov01, cov11 and sumsq. 158 159=item gsl_fit_wlinear($x, $xstride, $w, $wstride, $y, $ystride, $n) 160 161This function computes the best-fit linear regression coefficients (c0,c1) of 162the model Y = c_0 + c_1 X for the weighted dataset ($x, $y), two vectors (in 163form of arrays) of length $n with strides $xstride and $ystride. The vector 164(also in the form of an array) $w, of length $n and stride $wstride, specifies 165the weight of each datapoint. The weight is the reciprocal of the variance for 166each datapoint in y. The covariance matrix for the parameters (c0, c1) is 167computed using the weights and returned via the parameters (cov00, cov01, 168cov11). The weighted sum of squares of the residuals from the best-fit line, 169\chi^2, is returned in chisq. The function returns the following values in this 170order : 0 if the operation succeeded, 1 otherwise, c0, c1, cov00, cov01, cov11 171and sumsq. 172 173=item gsl_fit_linear_est($x, $c0, $c1, $cov00, $cov01, $cov11) 174 175This function uses the best-fit linear regression coefficients $c0, $c1 and 176their covariance $cov00, $cov01, $cov11 to compute the fitted function y and 177its standard deviation y_err for the model Y = c_0 + c_1 X at the point $x. The 178function returns the following values in this order : 0 if the operation 179succeeded, 1 otherwise, y and y_err. 180 181=item gsl_fit_mul($x, $xstride, $y, $ystride, $n) 182 183This function computes the best-fit linear regression coefficient c1 of the 184model Y = c_1 X for the datasets ($x, $y), two vectors (in form of arrays) of 185length $n with strides $xstride and $ystride. The errors on y are assumed 186unknown so the variance of the parameter c1 is estimated from the scatter of 187the points around the best-fit line and returned via the parameter cov11. The 188sum of squares of the residuals from the best-fit line is returned in sumsq. 189The function returns the following values in this order : 0 if the operation 190succeeded, 1 otherwise, c1, cov11 and sumsq. 191 192=item gsl_fit_wmul($x, $xstride, $w, $wstride, $y, $ystride, $n) 193 194This function computes the best-fit linear regression coefficient c1 of the 195model Y = c_1 X for the weighted datasets ($x, $y), two vectors (in form of 196arrays) of length $n with strides $xstride and $ystride. The vector (also in 197the form of an array) $w, of length $n and stride $wstride, specifies the 198weight of each datapoint. The weight is the reciprocal of the variance for each 199datapoint in y. The variance of the parameter c1 is computed using the weights 200and returned via the parameter cov11. The weighted sum of squares of the 201residuals from the best-fit line, \chi^2, is returned in chisq. The function 202returns the following values in this order : 0 if the operation succeeded, 1 203otherwise, c1, cov11 and sumsq. 204 205=item gsl_fit_mul_est($x, $c1, $cov11) 206 207This function uses the best-fit linear regression coefficient $c1 and its 208covariance $cov11 to compute the fitted function y and its standard deviation 209y_err for the model Y = c_1 X at the point $x. The function returns the 210following values in this order : 0 if the operation succeeded, 1 otherwise, y 211and y_err. 212 213=back 214 215For more informations on the functions, we refer you to the GSL official 216documentation: L<http://www.gnu.org/software/gsl/manual/html_node/> 217 218 219 220=head1 EXAMPLES 221 222This example shows how to use the function gsl_fit_linear. It's important to 223see that the array passed to to function must be an array reference, not a 224simple array. Also when you use strides, you need to initialize all the value 225in the range used, otherwise you will get warnings. 226 227 my @norris_x = (0.2, 337.4, 118.2, 884.6, 10.1, 226.5, 666.3, 996.3, 228 448.6, 777.0, 558.2, 0.4, 0.6, 775.5, 666.9, 338.0, 229 447.5, 11.6, 556.0, 228.1, 995.8, 887.6, 120.2, 0.3, 230 0.3, 556.8, 339.1, 887.2, 999.0, 779.0, 11.1, 118.3, 231 229.2, 669.1, 448.9, 0.5 ) ; 232 my @norris_y = ( 0.1, 338.8, 118.1, 888.0, 9.2, 228.1, 668.5, 998.5, 233 449.1, 778.9, 559.2, 0.3, 0.1, 778.1, 668.8, 339.3, 234 448.9, 10.8, 557.7, 228.3, 998.0, 888.8, 119.6, 0.3, 235 0.6, 557.6, 339.3, 888.0, 998.5, 778.9, 10.2, 117.6, 236 228.9, 668.4, 449.2, 0.2); 237 my $xstride = 2; 238 my $wstride = 3; 239 my $ystride = 5; 240 my ($x, $w, $y); 241 for my $i (0 .. 175) 242 { 243 $x->[$i] = 0; 244 $w->[$i] = 0; 245 $y->[$i] = 0; 246 } 247 248 for my $i (0 .. 35) 249 { 250 $x->[$i*$xstride] = $norris_x[$i]; 251 $w->[$i*$wstride] = 1.0; 252 $y->[$i*$ystride] = $norris_y[$i]; 253 } 254 my ($status, @results) = gsl_fit_linear($x, $xstride, $y, $ystride, 36); 255 256=head1 AUTHORS 257 258Jonathan "Duke" Leto <jonathan@leto.net> and Thierry Moisan <thierry.moisan@gmail.com> 259 260=head1 COPYRIGHT AND LICENSE 261 262Copyright (C) 2008-2021 Jonathan "Duke" Leto and Thierry Moisan 263 264This program is free software; you can redistribute it and/or modify it 265under the same terms as Perl itself. 266 267=cut 268 2691; 270