casa
$Rev:20696$
|
00001 //# VisCalSolver.h: Default solver for calibration using visibilities 00002 //# Copyright (C) 1996,1997,2000,2001,2002,2003 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be adressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# 00027 00028 #ifndef SYNTHESIS_VISCALSOL_H 00029 #define SYNTHESIS_VISCALSOL_H 00030 00031 #include <casa/aips.h> 00032 #include <casa/BasicSL/Complex.h> 00033 #include <casa/BasicSL/Constants.h> 00034 #include <casa/Arrays/Array.h> 00035 #include <casa/Arrays/Vector.h> 00036 #include <casa/Arrays/Matrix.h> 00037 #include <synthesis/MeasurementComponents/VisCal.h> 00038 #include <synthesis/MeasurementComponents/SolvableVisCal.h> 00039 #include <synthesis/MeasurementEquations/VisEquation.h> 00040 #include <synthesis/MSVis/VisBuffGroupAcc.h> 00041 #include <synthesis/MSVis/CalVisBuffer.h> 00042 00043 namespace casa { //# NAMESPACE CASA - BEGIN 00044 00045 // <summary> 00046 // VisCalSolver: Default solver for calibration using visibility data 00047 // </summary> 00048 00049 // <use visibility=export> 00050 00051 // <reviewed reviewer="" date="" tests="" demos=""> 00052 00053 // <prerequisite> 00054 // <li> <linkto class="MeasurementComponents">MeasurementComponents</linkto> module 00055 // <li> <linkto class="VisEquation">VisEquation</linkto> module 00056 // </prerequisite> 00057 // 00058 // <etymology> 00059 // VisCal for visibility calibration (meaning solved from visibilities), Solver for 00060 // solving. 00061 // </etymology> 00062 // 00063 // <synopsis> 00064 // 00065 // VisCalSolver describes an interface for solving for calibration from visibility 00066 // data in a VisBuffer. It hosts the communication of visibility data with otherwise 00067 // generic solving mechanims. A Levenberg-Marquardt solver is supplied here by 00068 // default, but it is intended that this class be the template for interfaces to 00069 // third-party solving mechanisms. 00070 // 00071 // </synopsis> 00072 // 00073 // <example> 00074 // <srcblock> 00075 00076 // </srcblock> 00077 // </example> 00078 // 00079 // <motivation> 00080 // It is desirable to establish the distinct communicative boundary between generic 00081 // solving mechanims and the particulars of visibility data and calibration 00082 // component descriptions. This class is intended to serve this purpose, by providing 00083 // access to visibility data and calibration in terms of quantities necessary for 00084 // least-squares (and other) style solvers. 00085 // </motivation> 00086 // 00087 // <todo asof="97/10/01"> 00088 // </todo> 00089 00090 // ********************************************************** 00091 // VisCalSolver 00092 // 00093 00094 class VisCalSolver { 00095 public: 00096 00097 // Constructor currently generic 00098 VisCalSolver(); 00099 00100 // Destructor 00101 ~VisCalSolver(); 00102 00103 // Do the solve 00104 Bool solve(VisEquation& viseq, SolvableVisCal& svc, VisBuffer& svb); 00105 Bool solve(VisEquation& viseq, SolvableVisCal& svc, VisBuffGroupAcc& vbga); 00106 00107 protected: 00108 00109 // Access to fundamental external objects: 00110 inline VisBuffer& svb() { return *svb_; }; 00111 inline VisBuffGroupAcc& vbga() { return *vbga_; }; 00112 inline VisEquation& ve() { return *ve_; }; 00113 inline SolvableVisCal& svc() { return *svc_; }; 00114 00115 // Accessors to current svb's (differentiated) Residuals 00116 inline Cube<Complex>& R() { return R_; }; 00117 inline Array<Complex>& dR() { return dR_; }; 00118 inline Matrix<Bool>& Rflg() { return Rflg_; }; 00119 00120 inline Array<Complex>& dSrc() { return dSrc_; }; 00121 00122 // Access to maxIter_ 00123 inline Int& maxIter() { return maxIter_; }; 00124 00125 // Access to chi2 00126 inline Double& chiSq() { return chiSq_; }; 00127 inline Vector<Double>& chiSqV() { return chiSqV_; }; 00128 inline Double& lastChiSq() { return lastChiSq_; }; 00129 inline Double& dChiSq() { return dChiSq_; }; 00130 inline Double& sumWt() { return sumWt_; }; 00131 inline Int& nWt() { return nWt_; }; 00132 00133 // Access to parameters, & grad,hess,dp 00134 inline Int& nTotalPar() { return nTotalPar_; }; 00135 inline Int& nCalPar() { return nCalPar_; }; 00136 inline Int& nSrcPar() { return nSrcPar_; }; 00137 inline Vector<Complex>& par() { return par_; }; 00138 inline Vector<Bool>& parOK() { return parOK_; }; 00139 inline Vector<Float>& parErr() { return parErr_; }; 00140 inline Vector<Complex>& srcPar() { return srcPar_; }; 00141 inline Vector<DComplex>& grad() { return grad_; }; 00142 inline Vector<Double>& hess() { return hess_; }; 00143 inline Vector<Complex>& dpar() { return dpar_; }; 00144 inline Vector<Complex>& dCalPar() { return dsrcpar_; }; 00145 inline Vector<Complex>& dSrcPar() { return dcalpar_; }; 00146 inline Vector<Complex>& lastCalPar() { return lastCalPar_; }; 00147 inline Vector<Complex>& lastSrcPar() { return lastSrcPar_; }; 00148 00149 inline Double& lambda() { return lambda_; }; 00150 00151 // Initialize solving data 00152 void initSolve(); 00153 00154 // Obtain trial residuals w.r.t svc's current pars 00155 void residualate(); 00156 void residualate2(); 00157 00158 // Differentiate the svb w.r.t svc's pars 00159 void differentiate(); 00160 void differentiate2(); 00161 00162 // Calculate residuals (incl. diff'd) and chi2 00163 void chiSquare(); 00164 void chiSquare2(); 00165 00166 // Check for convergence 00167 Bool converged(); 00168 00169 // Internal solving methods 00170 void accGradHess(); 00171 void accGradHess2(); 00172 void revert(); 00173 void solveGradHess(); 00174 void updatePar(); 00175 00176 // Optimize the step parabolically 00177 void optStepSize(); 00178 void optStepSize2(); 00179 00180 // Get and print par errors 00181 void getErrors(); 00182 00183 void printPar(const Int& iter); 00184 00185 private: 00186 00187 // Diagnostic print level 00188 inline Int& prtlev() { return prtlev_; }; 00189 00190 // VisBuffer (from outside) 00191 VisBuffer* svb_; 00192 VisBuffGroupAcc* vbga_; 00193 00194 // VisEquation (from outside) 00195 VisEquation* ve_; 00196 00197 // SVC (from outside) 00198 SolvableVisCal* svc_; 00199 00200 // Total Number of parameters 00201 Int nTotalPar_; 00202 Int nCalPar_; 00203 Int nSrcPar_; 00204 00205 // Residual/Differentiation caches 00206 Cube<Complex> R_; 00207 Array<Complex> dR_; 00208 Matrix<Bool> Rflg_; 00209 00210 // Derivative wrt Q and U 00211 Array<Complex> dSrc_; 00212 00213 // Maximum number of solve iterations to attempt 00214 Int maxIter_; 00215 00216 // Chi2, sum wts 00217 Double chiSq_; 00218 Vector<Double> chiSqV_; 00219 Double lastChiSq_; 00220 Double dChiSq_; 00221 Double sumWt_; 00222 Int nWt_; 00223 Int cvrgcount_; 00224 00225 // Parameter storage 00226 // (these are Complex to match the VisCal solvePar) 00227 Vector<Complex> par_; 00228 Vector<Bool> parOK_; 00229 Vector<Float> parErr_; 00230 Vector<Complex> srcPar_; 00231 Vector<Complex> lastCalPar_,lastSrcPar_; 00232 00233 // Parameter update 00234 Vector<Complex> dpar_; 00235 Vector<Complex> dcalpar_,dsrcpar_; 00236 00237 // Gradient, Hessian 00238 // (these are Double for precision in accumulation 00239 Vector<DComplex> grad_; 00240 Vector<Double> hess_; 00241 00242 // LM factor 00243 Double lambda_; 00244 00245 // Step optimization toggle 00246 Bool optstep_; 00247 00248 // Diagnostic print level 00249 Int prtlev_; 00250 00251 }; 00252 00253 } 00254 #endif