casacore
MatrixSolver.h
Go to the documentation of this file.
1 //# MatrixSolver.h: the base class for solvers of AX=B
2 //# Copyright (C) 1994,1995,1999
3 //# Associated Universities, Inc. Washington DC, USA.
4 //#
5 //# This library is free software; you can redistribute it and/or modify it
6 //# under the terms of the GNU Library General Public License as published by
7 //# the Free Software Foundation; either version 2 of the License, or (at your
8 //# option) any later version.
9 //#
10 //# This library is distributed in the hope that it will be useful, but WITHOUT
11 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13 //# License for more details.
14 //#
15 //# You should have received a copy of the GNU Library General Public License
16 //# along with this library; if not, write to the Free Software Foundation,
17 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18 //#
19 //# Correspondence concerning AIPS++ should be addressed as follows:
20 //# Internet email: aips2-request@nrao.edu.
21 //# Postal address: AIPS++ Project Office
22 //# National Radio Astronomy Observatory
23 //# 520 Edgemont Road
24 //# Charlottesville, VA 22903-2475 USA
25 //#
26 //# $Id$
27 
28 #ifndef SCIMATH_MATRIXSOLVER_H
29 #define SCIMATH_MATRIXSOLVER_H
30 
31 
32 #include <casacore/casa/aips.h>
33 #include <casacore/casa/Arrays/Array.h>
34 #include <casacore/casa/Arrays/ArrayMath.h>
35 #include <casacore/casa/Arrays/Matrix.h>
36 #include <casacore/casa/Arrays/Vector.h>
37 
38 #include <casacore/casa/Logging/LogSink.h>
39 #include <casacore/casa/Logging/LogMessage.h>
40 
41 namespace casacore { //# NAMESPACE CASACORE - BEGIN
42 
43 typedef Float FType; // floating type (Float, Double)
44 
45 //<summary>
46 // MatrixSolver.h: the base class for solvers of linear equations AX=B
47 //</summary>
48 
49 // <use visibility=local>
50 
51 // <reviewed reviewer="" date="",tests="" demos="">
52 // </reviewed>
53 
54 // <prerequisite>
55 // <li> Matrix, Vector
56 // </prerequisite>
57 //
58 // <etymology>
59 // The MatrixSolver class name reflects its use as the base class for solving
60 // Linear Equations of the form AX=B. This class is purely virtual
61 // and provides the essential implementation for derived solvers
62 // classes.
63 // </etymology>
64 //
65 // <synopsis>
66 // The MatrixSolver class is a purely virtual base class. The programmer needs
67 // to define the following functions in a class derived from MatrixSolver:
68 // <ol>
69 // <li> the derived destructor.
70 // <li> <src>void setImageAndPsf(const Array<FType> & image, const
71 // Array<FType> & psf);</src> Set the image and the Point Spread Function
72 // (beam). Setting this should reset the internal state, e.g.
73 // CurrentIter()==0.
74 // <li> <src>Bool solve();</src> Perform solution of AX=B.
75 // Returns True if algorithm has converged or stop criterium reached.
76 // </ol>
77 // </synopsis>
78 //
79 // <todo asof="">
80 // </todo>
81 
82 class MatrixSolver {
83 public:
84 
85  // Default Constructor
87 
88  // Copy Constructor
89  MatrixSolver(const MatrixSolver & other);
90 
91  // Create a MatrixSolver from a matrix A and a Vector B
92  // <note role=warning> A and B are accessed by reference, so do not
93  // modify them during the lifetime of the MatrixSolver </note>
94  MatrixSolver(const Matrix<FType> & A, const Vector<FType> & B);
95 
96  // Virtual destructor: calls all derived class destructors
97  virtual ~MatrixSolver();
98 
99  // Assignment operator: uses reference semantics, i.e., it
100  // references the internal arrays of other
102 
103  // Set A matrix and B vector
104  void setAB(const Matrix<FType> & A, const Vector<FType> & B);
105 
106  // Set initial value of X
107  void setX(const Vector<FType> & X);
108 
109  // Solve for the X vector.
110  virtual Bool solve();
111 
112  // Is the current solution good enough?
114 
115  // Return residual vector B-AX
117 
118  // Return solution vector
120 
121  // Set the tolerance for solution
122  void setTolerance(FType tol);
123 
124  // Return the tolerance for solution
125  FType Tolerance();
126 
127  // Set the maximum number of iterations.
128  void setMaxIters(uInt maxiters);
129 
130  // Return the maximum number of iterations.
131  uInt MaxIters();
132 
133  // Set the gain for solution
134  void setGain(FType g);
135 
136  // Return the gain for solution
137  FType Gain();
138 
139  // Set status of solution
140  void setSolved(Bool s);
141 
142  // Return status of solution
143  Bool Solved();
144 
145  // Return norm of solution i.e. ||B-AX||
146  FType getNorm();
147 
148 protected:
149 
151  virtual LogSink& logSink() {return logSink_p;}
152 
153  // the A matrix data member
155 
156  // the constraint vector data member
158 
159  // The residual vector data member
161 
162  // The solution vector data member
164 
165  // The solution norm i.e. ||B-AX||
167 
168  // The data norm i.e. ||B||
170 
171 private:
172 
173  // Tolerance for solution i.e. ||B-AX||/||B|| must be less than this
175 
176  // Maximum number of iterations
178 
179  // Has a solution been found?
181 
182  // Gain
184 
185 };
186 
188 {SolTolerance=tol;}
189 
191 {return SolTolerance;}
192 
193 inline void MatrixSolver::setMaxIters(uInt maxiters)
194 {MaxIterations = maxiters;}
195 
197 {return MaxIterations;}
198 
200 {gain=g;}
201 
203 {return gain;}
204 
206 {solved=s;}
207 
209 {return solved;}
210 
212 {return RNorm;}
213 
214 
215 } //# NAMESPACE CASACORE - END
216 
217 #endif
void setAB(const Matrix< FType > &A, const Vector< FType > &B)
Set A matrix and B vector.
uInt MaxIterations
Maximum number of iterations.
Definition: MatrixSolver.h:177
MatrixSolver(const MatrixSolver &other)
Copy Constructor.
MatrixSolver()
Default Constructor.
virtual LogSink & logSink()
Definition: MatrixSolver.h:151
Bool Solved()
Return status of solution.
Definition: MatrixSolver.h:208
Vector< FType > XVector
The solution vector data member.
Definition: MatrixSolver.h:163
void setGain(FType g)
Set the gain for solution.
Definition: MatrixSolver.h:199
FType Gain()
Return the gain for solution.
Definition: MatrixSolver.h:202
virtual Bool solve()
Solve for the X vector.
FType BNorm
The data norm i.e.
Definition: MatrixSolver.h:169
Vector< FType > RVector
The residual vector data member.
Definition: MatrixSolver.h:160
MatrixSolver & operator=(const MatrixSolver &other)
Assignment operator: uses reference semantics, i.e., it references the internal arrays of other.
void setMaxIters(uInt maxiters)
Set the maximum number of iterations.
Definition: MatrixSolver.h:193
Bool accurateSolution()
Is the current solution good enough?
MatrixSolver(const Matrix< FType > &A, const Vector< FType > &B)
Create a MatrixSolver from a matrix A and a Vector B Warning: A and B are accessed by reference,...
Matrix< FType > AMatrix
the A matrix data member
Definition: MatrixSolver.h:154
FType Tolerance()
Return the tolerance for solution.
Definition: MatrixSolver.h:190
const Vector< FType > & getSolution()
Return solution vector.
void setTolerance(FType tol)
Set the tolerance for solution.
Definition: MatrixSolver.h:187
FType getNorm()
Return norm of solution i.e.
Definition: MatrixSolver.h:211
void setSolved(Bool s)
Set status of solution.
Definition: MatrixSolver.h:205
FType SolTolerance
Tolerance for solution i.e.
Definition: MatrixSolver.h:174
const Vector< FType > & getResidual()
Return residual vector B-AX.
void setX(const Vector< FType > &X)
Set initial value of X.
FType RNorm
The solution norm i.e.
Definition: MatrixSolver.h:166
virtual ~MatrixSolver()
Virtual destructor: calls all derived class destructors.
uInt MaxIters()
Return the maximum number of iterations.
Definition: MatrixSolver.h:196
Bool solved
Has a solution been found?
Definition: MatrixSolver.h:180
Vector< FType > BVector
the constraint vector data member
Definition: MatrixSolver.h:157
this file contains all the compiler specific defines
Definition: mainpage.dox:28
Float FType
Definition: MatrixSolver.h:43
unsigned int uInt
Definition: aipstype.h:51
float Float
Definition: aipstype.h:54
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42