23 #ifndef DenoisingLib_H_
24 #define DenoisingLib_H_
34 #include <gsl/gsl_multifit.h>
57 ncomponents_p = ncomponents;
58 model_p.resize(ncomponents_p,ndata_p,
False);
61 size_t ndata() {
return ndata_p;}
95 linearComponent.
reference(model_p.row(1));
96 indgen(linearComponent,-1.0,2.0/(ndata_p-1));
100 for (
size_t model_idx=2;model_idx<ncomponents_p;model_idx++)
102 for (
size_t data_idx=0; data_idx<ndata_p; data_idx++)
104 model_p(model_idx,data_idx) =
pow(model_p(1,data_idx),model_idx);
116 scale = 1.0 / (min-mid);
119 model_p.row(0) = 1.0;
120 if (order > 0) model_p.row(1) = scale*(data_x-mid);
123 for (
size_t model_idx=2;model_idx<ncomponents_p;model_idx++)
125 for (
size_t data_idx=0; data_idx<ndata_p; data_idx++)
127 model_p(model_idx,data_idx) =
pow(model_p(1,data_idx),model_idx);
134 if (linear_component_float_p.size() != ndata_p) initLinearComponentFloat();
135 return linear_component_float_p;
142 linear_component_float_p.resize(ndata_p);
143 for (
size_t data_idx=0; data_idx<ndata_p; data_idx++)
145 linear_component_float_p(data_idx) = model_p(1,data_idx);
169 void resetNComponents(
size_t ncomponents);
180 calcFitCoeffCore(data_p.column(0),gsl_coeff_real_p);
184 for (
size_t coeff_idx=0;coeff_idx<ncomponents_p;coeff_idx++)
186 coeffCASA(coeff_idx) = gsl_vector_get(gsl_coeff_real_p,coeff_idx);
196 for (
size_t model_idx=0;model_idx<ncomponents_p;model_idx++)
198 coeff(model_idx) = gsl_vector_get(gsl_coeff_real_p,model_idx);
207 calcFitModelStdCore(model,std,gsl_coeff_real_p);
215 calcFitModelCore(model,gsl_coeff_real_p);
223 void allocGslResources();
224 void freeGslResources();
239 for (
size_t data_idx=0;data_idx<ndata_p;data_idx++)
242 if (xCASA.
size() != ncomponents_p) xCASA.
resize(ncomponents_p,
True);
247 errno_p = gsl_multifit_linear_est (&xGSL, coeff, gsl_covariance_p, &y, &yerr);
249 if (model.
size() > 0) model(data_idx) = y;
250 if (std.
size() > 0 ) std(data_idx) = yerr;
261 coeff_i = gsl_vector_get(coeff,0);
262 for (
size_t data_idx=0; data_idx<ndata_p; data_idx++)
264 model(data_idx) = coeff_i*modelMatrix(0,data_idx);
267 for (
size_t model_idx=0;model_idx<ncomponents_p;model_idx++)
269 coeff_i = gsl_vector_get(coeff,model_idx);
270 for (
size_t data_idx=0; data_idx<ndata_p; data_idx++)
272 model(data_idx) = coeff_i*modelMatrix(model_idx,data_idx);
GslLinearModelBase< Double > * model_p
void GslMatrixWrap(Matrix< Double > &casa_matrix, gsl_matrix &wrapper, size_t ncols=0)
Matrix< T > & getModelMatrix()
Vector< T > getModelAt(size_t pos)
void calcFitModelStdCore(Vector< T > &model, Vector< T > &std, gsl_vector *coeff)
void getFitCoeff(Vector< T > &coeff)
LatticeExprNode max(const LatticeExprNode &left, const LatticeExprNode &right)
GslPolynomialModel(const Vector< T > &data_x, size_t order)
GslLinearModelBase(size_t ndata, size_t ncomponents)
void setNIter(size_t nIter)
Vector< T > calcFitCoeff(Vector< T > &data)
void calcFitModelStd(Vector< T > &model, Vector< T > &std)
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
void calcFitModel(Vector< T > &model)
Vector< Double > weights_p
Weights.
LatticeExprNode min(const LatticeExprNode &left, const LatticeExprNode &right)
gsl_vector * gsl_coeff_real_p
GSL Resources.
gsl_multifit_linear_workspace * gsl_workspace_p
void indgen(TableVector< T > &tv, Int start, Int inc)
bool Bool
Define the standard types used by Casacore.
void minMax(T &min, T &max, const TableVector< T > &tv)
void setDebug(Bool debug)
void GslVectorWrap(Vector< Double > casa_vector, gsl_vector &wrapper)
void initLinearComponentFloat()
void calcFitModelCore(Vector< T > &model, gsl_vector *coeff)
gsl_matrix * gsl_covariance_p
Vector< Float > & getLinearComponentFloat()
gsl_vector * gsl_coeff_imag_p
Vector< Float > linear_component_float_p
LatticeExprNode pow(const LatticeExprNode &left, const LatticeExprNode &right)
void resize(size_t len, Bool copyValues=False)
Matrix< Double > data_p
Data.
virtual void reference(const Array< T > &other)
Create a reference to "other", which must be of dimension one.
GslPolynomialModel(size_t ndata, size_t order)
#define casacore
<X11/Intrinsic.h> #defines true, false, casacore::Bool, and String.