00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2009, Marco Cammarata and Andrew W. Steiner 00005 00006 This file is part of O2scl. 00007 00008 O2scl is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 O2scl is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with O2scl. If not, see <http://www.gnu.org/licenses/>. 00020 00021 ------------------------------------------------------------------- 00022 */ 00023 #ifndef GSL_SMOOTH_H 00024 #define GSL_SMOOTH_H 00025 00026 #include <iostream> 00027 #include <fstream> 00028 #include <string> 00029 #include <cmath> 00030 #include <sstream> 00031 00032 #include <gsl/gsl_bspline.h> 00033 #include <gsl/gsl_multifit.h> 00034 00035 #ifndef DOXYGENP 00036 namespace o2scl { 00037 #endif 00038 00039 /** \brief Smooth a GSL vector using GSL bsplines 00040 00041 \todo Needs a bit more error checking and 00042 more documentation. 00043 00044 \future Generalize to generic vector types. (Does this require 00045 reworking the GSL linear fitting routines?) In the meantime, 00046 make a \ref ovector interface. 00047 00048 \future Possibly create a new gsl_bspline class which replaces 00049 the GSL bspline workspace 00050 00051 \future Allow user to probe chi squared and the covariance? 00052 */ 00053 class gsl_smooth { 00054 00055 public: 00056 00057 gsl_smooth() { 00058 init_pointers_and_defs(); 00059 } 00060 00061 /// Begin using x-values from vector \c ix 00062 gsl_smooth(const gsl_vector *ix) { 00063 init_pointers_and_defs(); 00064 x=ix; 00065 init(); 00066 } 00067 00068 ~gsl_smooth() { 00069 free(); 00070 } 00071 00072 /// Set the number of coefficients 00073 void set_ncoeff(int incoeffs) { 00074 ncoeffs=incoeffs; 00075 } 00076 00077 /// Set order 00078 void set_order(int order) { 00079 norder=order; 00080 } 00081 00082 /// Set parameters 00083 void set_pars(int incoeffs, int order) { 00084 ncoeffs=incoeffs; 00085 norder=order; 00086 } 00087 00088 /** \brief Set the x-values 00089 00090 \comment 00091 This is just a reminder to me that this function can't 00092 be virtual since it is called in a constructor. 00093 \endcomment 00094 */ 00095 void set_x(const gsl_vector *ix) { 00096 x=ix; 00097 init(); 00098 } 00099 00100 /** \brief Smooth data in \c y with errors \c e returning result \c ys 00101 */ 00102 int smooth_data(const gsl_vector *y, const gsl_vector *e, gsl_vector *ys); 00103 00104 /** \brief Smooth data in \c y returning result \c ys 00105 */ 00106 int smooth_data(const gsl_vector *y, gsl_vector *ys); 00107 00108 protected: 00109 00110 /// Number of free coefficients for spline 00111 size_t ncoeffs; 00112 00113 /// Order of spline to be used (4=cubic) 00114 size_t norder; 00115 00116 /// internally calculated, number of "segment" to split the data into 00117 size_t nbreak; 00118 00119 /// True of the x values have been set 00120 bool x_set; 00121 00122 /// Spline workspace 00123 gsl_bspline_workspace *bw; 00124 00125 /// Spline temporary vector 00126 gsl_vector *B; 00127 00128 /// Parameters of linear fit, y=X*c 00129 gsl_vector *c; 00130 00131 /// Linear fit workspace 00132 gsl_multifit_linear_workspace *mw; 00133 00134 /// Workspace for spline fitting 00135 gsl_matrix *X; 00136 00137 /// Values of the independent variable 00138 const gsl_vector *x; 00139 00140 /// Covariance matrix 00141 gsl_matrix *cov; 00142 00143 /// Construct un-weighted fit 00144 int fit(const gsl_vector *y); 00145 00146 /// Construct weighted fit 00147 int fit_errors(const gsl_vector *y, const gsl_vector *e); 00148 00149 /// calculate smoothed curve value for a certain xi 00150 double calc_for_x(double xi); 00151 00152 /** \brief Allocate memory and initialize splines 00153 00154 \comment 00155 This is just a reminder to me that this function can't 00156 be virtual since it is called in a constructor. 00157 \endcomment 00158 */ 00159 int init(); 00160 00161 /// Set default values and zero pointers 00162 void init_pointers_and_defs(); 00163 00164 /// Free memory 00165 int free(); 00166 00167 }; 00168 00169 #ifndef DOXYGENP 00170 } 00171 #endif 00172 00173 #endif
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page