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
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/Array.h>
32#include <casacore/casa/Arrays/ArrayMath.h>
33#include <casacore/casa/Arrays/Matrix.h>
34#include <casacore/casa/Arrays/Vector.h>
35
36#include <casacore/casa/Logging/LogSink.h>
37#include <casacore/casa/Logging/LogMessage.h>
38
39namespace casacore { //# NAMESPACE CASACORE - BEGIN
40
41typedef Float FType; // floating type (Float, Double)
42
43//<summary>
44// MatrixSolver.h: the base class for solvers of linear equations AX=B
45//</summary>
46
47// <use visibility=local>
48
49// <reviewed reviewer="" date="",tests="" demos="">
50// </reviewed>
51
52// <prerequisite>
53// <li> Matrix, Vector
54// </prerequisite>
55//
56// <etymology>
57// The MatrixSolver class name reflects its use as the base class for solving
58// Linear Equations of the form AX=B. This class is purely virtual
59// and provides the essential implementation for derived solvers
60// classes.
61// </etymology>
62//
63// <synopsis>
64// The MatrixSolver class is a purely virtual base class. The programmer needs
65// to define the following functions in a class derived from MatrixSolver:
66// <ol>
67// <li> the derived destructor.
68// <li> <src>void setImageAndPsf(const Array<FType> & image, const
69// Array<FType> & psf);</src> Set the image and the Point Spread Function
70// (beam). Setting this should reset the internal state, e.g.
71// CurrentIter()==0.
72// <li> <src>Bool solve();</src> Perform solution of AX=B.
73// Returns True if algorithm has converged or stop criterium reached.
74// </ol>
75// </synopsis>
76//
77// <todo asof="">
78// </todo>
79
81public:
82
83 // Default Constructor
85
86 // Copy Constructor
87 MatrixSolver(const MatrixSolver & other);
88
89 // Create a MatrixSolver from a matrix A and a Vector B
90 // <note role=warning> A and B are accessed by reference, so do not
91 // modify them during the lifetime of the MatrixSolver </note>
93
94 // Virtual destructor: calls all derived class destructors
95 virtual ~MatrixSolver();
96
97 // Assignment operator: uses reference semantics, i.e., it
98 // references the internal arrays of other
100
101 // Set A matrix and B vector
102 void setAB(const Matrix<FType> & A, const Vector<FType> & B);
103
104 // Set initial value of X
105 void setX(const Vector<FType> & X);
106
107 // Solve for the X vector.
108 virtual Bool solve();
109
110 // Is the current solution good enough?
112
113 // Return residual vector B-AX
115
116 // Return solution vector
118
119 // Set the tolerance for solution
120 void setTolerance(FType tol);
121
122 // Return the tolerance for solution
124
125 // Set the maximum number of iterations.
126 void setMaxIters(uInt maxiters);
127
128 // Return the maximum number of iterations.
129 uInt MaxIters();
130
131 // Set the gain for solution
132 void setGain(FType g);
133
134 // Return the gain for solution
135 FType Gain();
136
137 // Set status of solution
138 void setSolved(Bool s);
139
140 // Return status of solution
141 Bool Solved();
142
143 // Return norm of solution i.e. ||B-AX||
144 FType getNorm();
145
146protected:
147
149 virtual LogSink& logSink() {return logSink_p;}
150
151 // the A matrix data member
153
154 // the constraint vector data member
156
157 // The residual vector data member
159
160 // The solution vector data member
162
163 // The solution norm i.e. ||B-AX||
165
166 // The data norm i.e. ||B||
168
169private:
170
171 // Tolerance for solution i.e. ||B-AX||/||B|| must be less than this
173
174 // Maximum number of iterations
176
177 // Has a solution been found?
179
180 // Gain
182
183};
184
187
190
191inline void MatrixSolver::setMaxIters(uInt maxiters)
192{MaxIterations = maxiters;}
193
196
198{gain=g;}
199
201{return gain;}
202
204{solved=s;}
205
207{return solved;}
208
210{return RNorm;}
211
212
213} //# NAMESPACE CASACORE - END
214
215#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
this file contains all the compiler specific defines
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