Go to the documentation of this file.
43 #ifndef O2SCL_FIT_LINEAR_H
44 #define O2SCL_FIT_LINEAR_H
50 #include <boost/numeric/ublas/vector.hpp>
51 #include <boost/numeric/ublas/matrix.hpp>
53 #include <o2scl/vector.h>
54 #include <o2scl/fit_base.h>
55 #include <o2scl/permutation.h>
56 #include <o2scl/cblas.h>
57 #include <o2scl/svd.h>
59 #ifndef DOXYGEN_NO_O2NS
65 template<
class vec_t=boost::numeric::ublas::vector<
double>,
66 class mat_t=boost::numeric::ublas::matrix<
double> >
101 tol=2.2204460492503131e-16;
124 virtual void fit_svd(
size_t ndat,
size_t npar) {
140 virtual void fit(
size_t npar,
size_t ndat,
const vec_t &ydat,
141 const mat_t &xpred, vec_t &parms,
142 mat_t &covar,
double &chi2) {
152 QSI.resize(npar,npar);
162 for(
size_t i=0;i<npar;i++) {
167 for(
size_t i=0;i<ndat;i++) {
168 for(
size_t j=0;j<npar;j++) {
176 for(
size_t i=0;i<npar;i++) {
186 (o2scl_cblas::o2cblas_RowMajor,
187 o2scl_cblas::o2cblas_Trans,ndat,npar,1.0,
A,ydat,0.0,
xt);
190 for(
size_t i=0;i<npar;i++) {
191 for(
size_t j=0;j<npar;j++) {
199 for(
size_t j=0;j<npar;j++) {
201 if (alpha<=
tol*alpha0) {
211 for(
size_t i=0;i<npar;i++) {
216 (o2scl_cblas::o2cblas_RowMajor,
217 o2scl_cblas::o2cblas_NoTrans,npar,npar,
218 1.0,
QSI,
xt,0.0,parms);
222 for(
size_t i=0;i<npar;i++) {
228 double s2=0.0, r2=0.0;
229 for(
size_t i=0;i<ndat;i++) {
240 for(
size_t i=0;i<npar;i++) {
242 for(
size_t j=i;j<npar;j++) {
245 for(
size_t k=0;k<npar;k++) {
248 covar(i,j)=s*s2/(d_i*d_j);
249 covar(j,i)=s*s2/(d_i*d_j);
257 virtual const char *
type() {
return "fit_linear"; }
261 #ifndef DOXYGEN_NO_O2NS
mat_t A
Local copy of xpred (and used as workspace by the SV decomposition)
void dgemv(const enum o2cblas_order order, const enum o2cblas_transpose TransA, const size_t M, const size_t N, const double alpha, const mat_t &A, const vec_t &X, const double beta, vec2_t &Y)
Compute .
mat_t QSI
Workspace for the SV decomposition and storage for .
vec_t t
Only used for the weighted fit (not yet implemented)
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
void dscal_subcol(mat_t &A, const size_t ir, const size_t ic, const size_t M, const double alpha)
Compute for a subcolumn of a matrix.
Linear least-squares fitting class (GSL)
The main O<span style='position: relative; top: 0.3em; font-size: 0.8em'>2</span>scl O$_2$scl names...
void balance_columns(size_t M, size_t N, mat_t &A, vec_t &D)
Balance a general matrix A by scaling the columns by the diagonal matrix D.
size_t rank
The rank of the linear system from the last call to fit_linear()
double tol
Tolerance (default )
virtual void fit_svd(size_t ndat, size_t npar)
Perform the SV decomposition.
vec_t D
Balancing factors for A.
vec_t S
The singular values from the SV decomposition.
@ exc_einval
invalid argument supplied by user
bool column_scaling
If true, discard fit components if the associated singular value becomes too small (default true)
virtual void fit(size_t npar, size_t ndat, const vec_t &ydat, const mat_t &xpred, vec_t &parms, mat_t &covar, double &chi2)
Perform a least-squares fit of a linear system.
void SV_decomp_mod(size_t M, size_t N, mat_t &A, mat2_t &X, mat3_t &V, vec_t &S, vec2_t &work)
SV decomposition by the modified Golub-Reinsch algorithm which is better for .
virtual const char * type()
Return string denoting type ("fit_linear")
size_t size_dat
Number of data points.
double ddot_subrow(const size_t N, const mat_t &X, const size_t ir, const size_t ic, const vec_t &Y)
Compute for a subrow of a matrix.
mat_t Q
The first unitary matrix from the SV decomposition.
size_t size_par
Number of parameters.
vec_t xt
SV decomposition workspace and also used to store new predicted values.
Documentation generated with Doxygen. Provided under the
GNU Free Documentation License (see License Information).