42 #ifndef O2SCL_FIT_LINEAR_H
43 #define O2SCL_FIT_LINEAR_H
49 #include <boost/numeric/ublas/vector.hpp>
50 #include <boost/numeric/ublas/matrix.hpp>
52 #include <o2scl/vector.h>
53 #include <o2scl/fit_base.h>
54 #include <o2scl/permutation.h>
55 #include <o2scl/cblas.h>
56 #include <o2scl/svd.h>
58 #ifndef DOXYGEN_NO_O2NS
64 template<
class vec_t=boost::numeric::ublas::vector<
double>,
65 class mat_t=boost::numeric::ublas::matrix<
double> >
100 tol=2.2204460492503131e-16;
123 virtual void fit_svd(
size_t ndat,
size_t npar) {
139 virtual void fit(
size_t npar,
size_t ndat,
const vec_t &ydat,
140 const mat_t &xpred, vec_t &parms,
141 mat_t &covar,
double &chi2) {
151 QSI.resize(npar,npar);
161 for(
size_t i=0;i<npar;i++) {
166 for(
size_t i=0;i<ndat;i++) {
167 for(
size_t j=0;j<npar;j++) {
175 for(
size_t i=0;i<npar;i++) {
185 (o2scl_cblas::o2cblas_RowMajor,
186 o2scl_cblas::o2cblas_Trans,ndat,npar,1.0,
A,ydat,0.0,
xt);
189 for(
size_t i=0;i<npar;i++) {
190 for(
size_t j=0;j<npar;j++) {
198 for(
size_t j=0;j<npar;j++) {
200 if (alpha<=
tol*alpha0) {
210 for(
size_t i=0;i<npar;i++) {
215 (o2scl_cblas::o2cblas_RowMajor,
216 o2scl_cblas::o2cblas_NoTrans,npar,npar,
217 1.0,
QSI,
xt,0.0,parms);
221 for(
size_t i=0;i<npar;i++) {
227 double s2=0.0, r2=0.0;
228 for(
size_t i=0;i<ndat;i++) {
239 for(
size_t i=0;i<npar;i++) {
241 for(
size_t j=i;j<npar;j++) {
244 for(
size_t k=0;k<npar;k++) {
247 covar(i,j)=s*s2/(d_i*d_j);
248 covar(j,i)=s*s2/(d_i*d_j);
256 virtual const char *
type() {
return "fit_linear"; }
260 #ifndef DOXYGEN_NO_O2NS
size_t rank
The rank of the linear system from the last call to fit_linear()
double tol
Tolerance (default )
Linear least-squares fitting class (GSL)
size_t size_par
Number of parameters.
invalid argument supplied by user
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.
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.
size_t size_dat
Number of data points.
vec_t D
Balancing factors for A.
virtual void fit_svd(size_t ndat, size_t npar)
Perform the SV decomposition.
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 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 .
#define O2SCL_ERR2(d, d2, n)
Set an error, two-string version.
vec_t S
The singular values from the SV decomposition.
mat_t A
Local copy of xpred (and used as workspace by the SV decomposition)
mat_t Q
The first unitary matrix from the SV decomposition.
virtual const char * type()
Return string denoting type ("fit_linear")
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 .
vec_t t
Only used for the weighted fit (not yet implemented)
bool column_scaling
If true, discard fit components if the associated singular value becomes too small (default true) ...
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.
vec_t xt
SV decomposition workspace and also used to store new predicted values.