00001 //# VisCalSolver2.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_VISCALSOL2_H 00029 #define SYNTHESIS_VISCALSOL2_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/MeasurementComponents/SolveDataBuffer.h> 00040 #include <synthesis/MeasurementEquations/VisEquation.h> 00041 00042 namespace casa { //# NAMESPACE CASA - BEGIN 00043 00044 // <summary> 00045 // VisCalSolver2: Default solver for calibration using visibility data 00046 // </summary> 00047 00048 // <use visibility=export> 00049 00050 // <reviewed reviewer="" date="" tests="" demos=""> 00051 00052 // <prerequisite> 00053 // <li> <linkto class="MeasurementComponents">MeasurementComponents</linkto> module 00054 // <li> <linkto class="VisEquation">VisEquation</linkto> module 00055 // </prerequisite> 00056 // 00057 // <etymology> 00058 // VisCal for visibility calibration (meaning solved from visibilities), Solver for 00059 // solving. 00060 // </etymology> 00061 // 00062 // <synopsis> 00063 // 00064 // VisCalSolver2 describes an interface for solving for calibration from visibility 00065 // data in a VisBuffer. It hosts the communication of visibility data with otherwise 00066 // generic solving mechanims. A Levenberg-Marquardt solver is supplied here by 00067 // default, but it is intended that this class be the template for interfaces to 00068 // third-party solving mechanisms. 00069 // 00070 // </synopsis> 00071 // 00072 // <example> 00073 // <srcblock> 00074 00075 // </srcblock> 00076 // </example> 00077 // 00078 // <motivation> 00079 // It is desirable to establish the distinct communicative boundary between generic 00080 // solving mechanims and the particulars of visibility data and calibration 00081 // component descriptions. This class is intended to serve this purpose, by providing 00082 // access to visibility data and calibration in terms of quantities necessary for 00083 // least-squares (and other) style solvers. 00084 // </motivation> 00085 // 00086 // <todo asof="97/10/01"> 00087 // </todo> 00088 00089 // ********************************************************** 00090 // VisCalSolver2 00091 // 00092 00093 class VisCalSolver2 { 00094 public: 00095 00096 // Constructor currently generic 00097 VisCalSolver2(); 00098 00099 // Destructor 00100 ~VisCalSolver2(); 00101 00102 // Do the solve 00103 Bool solve(VisEquation& viseq, SolvableVisCal& svc, SDBList& sdbs); 00104 00105 protected: 00106 00107 // Access to fundamental external objects: 00108 inline SDBList& sdbs() { return *SDBs_; }; 00109 inline VisEquation& ve() { return *ve_; }; 00110 inline SolvableVisCal& svc() { return *svc_; }; 00111 00112 // Access to maxIter_ 00113 inline Int& maxIter() { return maxIter_; }; 00114 00115 // Access to chi2 00116 inline Double& chiSq() { return chiSq_; }; 00117 inline Vector<Double>& chiSqV() { return chiSqV_; }; 00118 inline Double& lastChiSq() { return lastChiSq_; }; 00119 inline Double& dChiSq() { return dChiSq_; }; 00120 inline Double& sumWt() { return sumWt_; }; 00121 inline Vector<Double>& sumWtV() { return sumWtV_; }; 00122 inline Int& nWt() { return nWt_; }; 00123 00124 // Access to parameters, & grad,hess,dp 00125 inline Int& nPar() { return nPar_; }; 00126 inline Vector<Complex>& par() { return par_; }; 00127 inline Vector<Bool>& parOK() { return parOK_; }; 00128 inline Vector<Float>& parErr() { return parErr_; }; 00129 inline Vector<DComplex>& grad() { return grad_; }; 00130 inline Vector<Double>& hess() { return hess_; }; 00131 inline Vector<Complex>& dpar() { return dpar_; }; 00132 inline Vector<Complex>& lastPar() { return lastPar_; }; 00133 00134 inline Double& lambda() { return lambda_; }; 00135 00136 // Initialize solving data 00137 void initSolve(); 00138 00139 // Obtain trial residuals w.r.t svc's current pars 00140 void residualate2(); 00141 00142 // Differentiate w.r.t svc's pars 00143 void differentiate2(); 00144 00145 // Calculate residuals (incl. diff'd) and chi2 00146 void chiSquare2(); 00147 00148 // Check for convergence 00149 Bool converged(); 00150 00151 // Internal solving methods 00152 void accGradHess2(); 00153 void revert(); 00154 void solveGradHess(); 00155 void updatePar(); 00156 00157 // Optimize the step parabolically 00158 void optStepSize2(); 00159 00160 // Get and print par errors 00161 void getErrors(); 00162 00163 void printPar(const Int& iter); 00164 00165 private: 00166 00167 // Diagnostic print level 00168 inline Int& prtlev() { return prtlev_; }; 00169 00170 // VisBuffer (from outside) 00171 SDBList* SDBs_; 00172 00173 // VisEquation (from outside) 00174 VisEquation* ve_; 00175 00176 // SVC (from outside) 00177 SolvableVisCal* svc_; 00178 00179 // Total Number of parameters 00180 Int nPar_; 00181 00182 // Maximum number of solve iterations to attempt 00183 Int maxIter_; 00184 00185 // Chi2, sum wts 00186 Double chiSq_; 00187 Vector<Double> chiSqV_; 00188 Double lastChiSq_; 00189 Double dChiSq_; 00190 Double sumWt_; 00191 Vector<Double> sumWtV_; 00192 Int nWt_; 00193 Int cvrgcount_; 00194 00195 // Parameter storage 00196 // (these are Complex to match the VisCal solvePar) 00197 Vector<Complex> par_; 00198 Vector<Bool> parOK_; 00199 Vector<Float> parErr_; 00200 Vector<Complex> lastPar_; 00201 00202 // Parameter update 00203 Vector<Complex> dpar_; 00204 00205 // Gradient, Hessian 00206 // (these are Double for precision in accumulation 00207 Vector<DComplex> grad_; 00208 Vector<Double> hess_; 00209 00210 // LM factor 00211 Double lambda_; 00212 00213 // Step optimization toggle 00214 Bool optstep_; 00215 00216 // Diagnostic print level 00217 Int prtlev_; 00218 00219 }; 00220 00221 } 00222 #endif