casacore
Loading...
Searching...
No Matches
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: casa-feedback@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#ifndef SCIMATH_MATRIXSOLVER_H
27#define SCIMATH_MATRIXSOLVER_H
28
29#include <casacore/casa/aips.h>
30#include <casacore/casa/Arrays/Array.h>
31#include <casacore/casa/Arrays/ArrayMath.h>
32#include <casacore/casa/Arrays/Matrix.h>
33#include <casacore/casa/Arrays/Vector.h>
34
35#include <casacore/casa/Logging/LogSink.h>
36#include <casacore/casa/Logging/LogMessage.h>
37
38namespace casacore { // # NAMESPACE CASACORE - BEGIN
39
40typedef Float FType; // floating type (Float, Double)
41
42//<summary>
43// MatrixSolver.h: the base class for solvers of linear equations AX=B
44//</summary>
45
46// <use visibility=local>
47
48// <reviewed reviewer="" date="",tests="" demos="">
49// </reviewed>
50
51// <prerequisite>
52// <li> Matrix, Vector
53// </prerequisite>
54//
55// <etymology>
56// The MatrixSolver class name reflects its use as the base class for solving
57// Linear Equations of the form AX=B. This class is purely virtual
58// and provides the essential implementation for derived solvers
59// classes.
60// </etymology>
61//
62// <synopsis>
63// The MatrixSolver class is a purely virtual base class. The programmer needs
64// to define the following functions in a class derived from MatrixSolver:
65// <ol>
66// <li> the derived destructor.
67// <li> <src>void setImageAndPsf(const Array<FType> & image, const
68// Array<FType> & psf);</src> Set the image and the Point Spread Function
69// (beam). Setting this should reset the internal state, e.g.
70// CurrentIter()==0.
71// <li> <src>Bool solve();</src> Perform solution of AX=B.
72// Returns True if algorithm has converged or stop criterium reached.
73// </ol>
74// </synopsis>
75//
76// <todo asof="">
77// </todo>
78
80 public:
81 // Default Constructor
83
84 // Copy Constructor
86
87 // Create a MatrixSolver from a matrix A and a Vector B
88 // <note role=warning> A and B are accessed by reference, so do not
89 // modify them during the lifetime of the MatrixSolver </note>
91
92 // Virtual destructor: calls all derived class destructors
93 virtual ~MatrixSolver();
94
95 // Assignment operator: uses reference semantics, i.e., it
96 // references the internal arrays of other
98
99 // Set A matrix and B vector
100 void setAB(const Matrix<FType>& A, const Vector<FType>& B);
101
102 // Set initial value of X
103 void setX(const Vector<FType>& X);
104
105 // Solve for the X vector.
106 virtual Bool solve();
107
108 // Is the current solution good enough?
110
111 // Return residual vector B-AX
113
114 // Return solution vector
116
117 // Set the tolerance for solution
118 void setTolerance(FType tol);
119
120 // Return the tolerance for solution
122
123 // Set the maximum number of iterations.
124 void setMaxIters(uInt maxiters);
125
126 // Return the maximum number of iterations.
127 uInt MaxIters();
128
129 // Set the gain for solution
130 void setGain(FType g);
131
132 // Return the gain for solution
133 FType Gain();
134
135 // Set status of solution
136 void setSolved(Bool s);
137
138 // Return status of solution
139 Bool Solved();
140
141 // Return norm of solution i.e. ||B-AX||
142 FType getNorm();
143
144 protected:
146 virtual LogSink& logSink() { return logSink_p; }
147
148 // the A matrix data member
150
151 // the constraint vector data member
153
154 // The residual vector data member
156
157 // The solution vector data member
159
160 // The solution norm i.e. ||B-AX||
162
163 // The data norm i.e. ||B||
165
166 private:
167 // Tolerance for solution i.e. ||B-AX||/||B|| must be less than this
169
170 // Maximum number of iterations
172
173 // Has a solution been found?
175
176 // Gain
178};
179
181
183
184inline void MatrixSolver::setMaxIters(uInt maxiters) { MaxIterations = maxiters; }
185
187
188inline void MatrixSolver::setGain(FType g) { gain = g; }
189
190inline FType MatrixSolver::Gain() { return gain; }
191
192inline void MatrixSolver::setSolved(Bool s) { solved = s; }
193
194inline Bool MatrixSolver::Solved() { return solved; }
195
197
198} // namespace casacore
199
200#endif
void setAB(const Matrix< FType > &A, const Vector< FType > &B)
Set A matrix and B vector.
uInt MaxIterations
Maximum number of iterations.
MatrixSolver(const MatrixSolver &other)
Copy Constructor.
MatrixSolver()
Default Constructor.
Bool Solved()
Return status of solution.
Vector< FType > XVector
The solution vector data member.
const Vector< FType > & getResidual()
Return residual vector B-AX.
void setGain(FType g)
Set the gain for solution.
FType Gain()
Return the gain for solution.
virtual Bool solve()
Solve for the X vector.
FType BNorm
The data norm i.e.
MatrixSolver & operator=(const MatrixSolver &other)
Assignment operator: uses reference semantics, i.e., it references the internal arrays of other.
Vector< FType > RVector
The residual vector data member.
void setMaxIters(uInt maxiters)
Set the maximum number of iterations.
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
FType Tolerance()
Return the tolerance for solution.
void setTolerance(FType tol)
Set the tolerance for solution.
FType getNorm()
Return norm of solution i.e.
void setSolved(Bool s)
Set status of solution.
FType SolTolerance
Tolerance for solution i.e.
void setX(const Vector< FType > &X)
Set initial value of X.
FType RNorm
The solution norm i.e.
virtual LogSink & logSink()
virtual ~MatrixSolver()
Virtual destructor: calls all derived class destructors.
const Vector< FType > & getSolution()
Return solution vector.
uInt MaxIters()
Return the maximum number of iterations.
Bool solved
Has a solution been found?
Vector< FType > BVector
the constraint vector data member
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
Float FType
unsigned int uInt
Definition aipstype.h:49
float Float
Definition aipstype.h:52
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40