|
FILTLAN 1.0a
|
00001 #ifndef POLYFILT_H 00002 #define POLYFILT_H 00003 00007 #include "matkitdef.h" 00008 00009 #ifdef USE_NAMESPACE 00010 using namespace MATKIT; 00011 namespace MATKIT { 00012 #endif 00013 00014 class Vector; 00015 class Matrix; 00016 class SymmetricMatrix; 00017 class SparseMatrix; 00018 00019 #ifdef USE_NAMESPACE 00020 } // end of namespace MATKIT 00021 #endif 00022 00023 00025 // Newton - Hermite Polynomial Interpolation 00027 00032 00033 00049 // build P(z) by Newton's divided differences in the form 00050 // P(z) = a(1) + a(2)*(z-x(1)) + a(3)*(z-x(1))*(z-x(2)) + ... + a(n)*(z-x(1))*...*(z-x(n-1)), 00051 // such that P(x(i)) = y(i) for i=1,...,n, where 00052 // x,y are input vectors of length n, and a is the output vector of length n 00053 // if x(i)==x(j) for some i!=j, then it is assumed that the derivative of P(z) is to be zero at x(i), 00054 // and the Hermite polynomial interpolation is applied 00055 // in general, if there are k x(i)'s with the same value x0, then 00056 // the j-th order derivative of P(z) is zero at z=x0 for j=1,...,k-1 00057 Vector NewtonPolynomial(const Vector &x, const Vector &y); 00058 00060 00069 // return the evaluated P(z0), i.e. the value of P(z) at z=z0, where P(z) is a Newton polynomial defined by 00070 // P(z) = a(1) + a(2)*(z-x(1)) + a(3)*(z-x(1))*(z-x(2)) + ... + a(n)*(z-x(1))*...*(z-x(n-1)) 00071 // this routine also works for evluating the function value of a Hermite interpolating polynomial, 00072 // which is in the same form as a Newton polynomial 00073 Real NewtonPolynomialEvaluation(const Vector &a, const Vector &x, const Real z0); 00074 // end of group_poly_intp 00076 00077 00078 00080 // Base Filter 00082 00086 // begin of group_base_filter 00088 00120 // compute a base filter P(z) which is a continuous, piecewise polynomial P(z) expanded 00121 // in a basis of `translated' (i.e. scale-and-shift) Chebyshev polynomials in each interval 00122 // 00123 // The base filter P(z) equals P_j(z) for z in the j-th interval [intv(j), intv(j+1)), where 00124 // P_j(z) a Hermite interpolating polynomial 00125 // 00126 // input: 00127 // intv is a vector which defines the intervals; the j-th interval is [intv(j), intv(j+1)) 00128 // HiLowFlags determines the shape of the base filter P(z) 00129 // Consider the j-th interval [intv(j), intv(j+1)] 00130 // HighLowFlag[j-1]==1, P(z)==1 for z in [intv(j), intv(j+1)] 00131 // ==0, P(z)==0 for z in [intv(j), intv(j+1)] 00132 // ==-1, [intv(j), intv(j+1)] is a transition interval; 00133 // P(intv(j)) and P(intv(j+1)) are defined such that P(z) is continuous 00134 // baseDeg is the degree of smoothness of the Hermite (piecewise polynomial) interpolation 00135 // to be precise, the i-th derivative of P(z) is zero, i.e. d^{i}P(z)/dz^i==0, at all interval end points z=intv(j) for i=1,...,baseDeg 00136 // 00137 // output: 00138 // P(z) expanded in a basis of `translated' (scale-and-shift) Chebyshev polynomials 00139 // to be preicse, for z in the j-th interval [intv(j),intv(j+1)), P(z) equals 00140 // P_j(z) = pp(1,j)*S_0(z) + pp(2,j)*S_1(z) + ... + pp(n,j)*S_{n-1}(z), 00141 // where S_i(z) is the `translated' Chebyshev polynomial in that interval, 00142 // S_i((z-c)/h) = T_i(z), c = (intv(j)+intv(j+1))) / 2, h = (intv(j+1)-intv(j)) / 2, 00143 // with T_i(z) the Chebyshev polynomial of the first kind, 00144 // T_0(z) = 1, T_1(z) = z, and T_i(z) = 2*z*T_{i-1}(z) - T_{i-2}(z) for i>=2 00145 // the return matrix is the matrix of Chebyshev coefficients pp just described 00146 // 00147 // note that the degree of P(z) in each interval is (at most) 2*baseDeg+1, with 2*baseDeg+2 coefficients 00148 // let n be the length of intv; then there are n-1 intervals 00149 // therefore the return matrix pp is of size (2*baseDeg+2)-by-(n-1) 00150 Matrix HermiteBaseFilterInChebyshevBasis(const Vector &intv, const int *HiLowFlags, mkIndex baseDeg); 00151 00153 // an instance of this class, taken by GetIntervals() and PolynomialFilterInterface::setFilter(), is a collection of options to determine the intervals which decides the base filter 00154 // it is used as an input argument of GetIntervals(), and also 00155 struct IntervalOptions { 00157 00162 // interval weights, default 100,1,1,1,100 00163 Vector intervalWeights; 00164 00165 // the following parameter is for high-pass filters (and low-pass filters with conversion) only 00167 // the (relative) length of transition interval (default 0.6) 00168 Real transitionIntervalRatio; 00169 00170 // the following parameters are for mid-pass filters only 00172 // this parameter tells whether to reverse the interval or not; it is effective only for mid-pass filters (default false) 00173 bool reverseInterval; 00175 // initial length of `plateau' relative to the length of the interval of desired eigenvalues (default 0.1) 00176 Real initialPlateau; 00178 // the rate at which the plateau shrinks at each iteration (default 1.5) 00179 Real plateauShrinkRate; 00181 // initial shift step, relative to the length of the interval of desired eigenvalues (default 0.01) 00182 Real initialShiftStep; 00184 // the rate at which the shift step expands (default 1.5) 00185 Real shiftStepExpansionRate; 00187 // maximum number of inner iterations (default 30) 00188 mkIndex maxInnerIter; 00190 // a mid-pass filter P(x) should have P(a1)=P(b1), where [a1,b1] is the interval of desired eigenvalues 00191 // yLimitTol (default 0.0001) is the tolerance allowed for |P(a1)-P(b1)| 00192 Real yLimitTol; 00193 00194 // the following parameters are for all filters 00196 // maximum number of outer iterations, default 50 00197 mkIndex maxOuterIter; 00199 00201 // number of grid points, used to measure the maximum function value of the polynomial P(z) for z not in the interval which the eigenvalues are sought (default 200) 00202 // the value of numGridPoints will automatically be increased if it is too small 00203 mkIndex numGridPoints; 00205 // this is the bottom line (default 0.001) which the function value of the polynomial must be greater than for z is in the interval of desired eigenvalues 00206 Real yBottomLine; 00208 // the limit of height of ripples (not in the interval of desired eigenvalues) relative to the bottom of polynomial values for z in the interval of desired eigenvalues (default 0.8) 00209 Real yRippleLimit; 00210 00212 // a default constructor to set default parameters 00213 IntervalOptions() { 00214 // set default interval weights 00215 intervalWeights.resize(5); 00216 intervalWeights(1) = 100.0; 00217 intervalWeights(2) = 1.0; 00218 intervalWeights(3) = 1.0; 00219 intervalWeights(4) = 1.0; 00220 intervalWeights(5) = 100.0; 00221 00222 // for high-pass filters (and low-pass filters with conversion) 00223 transitionIntervalRatio = 0.6; 00224 00225 // for mid-pass filters 00226 reverseInterval = false; 00227 initialPlateau = 0.1; 00228 plateauShrinkRate = 1.5; 00229 initialShiftStep = 0.01; 00230 shiftStepExpansionRate = 1.5; 00231 maxOuterIter = 50; 00232 yLimitTol = 0.0001; 00233 00234 // for all filters 00235 maxInnerIter = 30; 00236 numGridPoints = 200; 00237 yBottomLine = 0.001; 00238 yRippleLimit = 0.8; 00239 } 00240 }; 00241 00243 // the routine GetIntervals() returns an instance of this class, which gives the information of a polynomial filter 00244 struct PolynomialFilterInfo { 00245 // the following returned values are for all filters 00247 // The partition of the range of spectrum which decides the base filter and the polynomial filter. 00248 Vector intervals; 00250 // 1 means a high-pass filter (or low-pass filter with conversion); 2 means a mid-pass filter 00251 int filterType; 00253 // 0 means no acceptable is found; 1 means an OK filter is found; 2 means an optimal filter is found 00254 int filterOK; 00256 // between 0.0 and 1.0; the higher the better quality of the filter 00257 Real filterQualityIndex; 00259 // number of iterations to get the (transition) intervals 00260 mkIndex numIter; 00262 00264 // total number of iterations performed; this may include a few extra iterations without improving the (transition) intervals, compared to numIter 00265 mkIndex totalNumIter; 00267 // the lowest polynomial value P(z) for z in the interval [a1,b1] of desired eigenvalues 00268 Real yLimit; 00270 // the height of (highest, if more than one) summit in the interval [a1,b1] of desired eigenvalues 00271 Real ySummit; 00273 // number of steps moving leftward 00274 mkIndex numLeftSteps; 00276 // the height of highest summit in the left-hand side of the interval of desired eigenvalues 00277 Real yLeftSummit; 00279 // the height of lowest bottom in the left-hand side of the interval of desired eigenvalues 00280 Real yLeftBottom; 00281 00282 // the following returned values are for high-pass filters (or low-pass filters after conversion) 00284 // in general it is |p(a1)-p(b1)|, where [a1,b1] is the interval of desired eigenvalues 00285 Real yLimitGap; 00287 // number of steps moving rightward 00288 mkIndex numRightSteps; 00290 // the height of highest summit in the right-hand side of the interval of desired eigenvalues 00291 Real yRightSummit; 00293 // the height of lowest bottom in the right-hand side of the interval of desired eigenvalues 00294 Real yRightBottom; 00295 00297 // a default constructor to initialize all zero 00298 PolynomialFilterInfo() { 00299 // zero initialization 00300 filterOK = 0; 00301 filterQualityIndex = 0.0; 00302 00303 numIter = 0; 00304 totalNumIter = 0; 00305 yLimit = 0.0; 00306 yLimitGap = 0.0; 00307 ySummit = 0.0; 00308 00309 numLeftSteps = 0; 00310 yLeftSummit = 0.0; 00311 yLeftBottom = 0.0; 00312 00313 numRightSteps = 0; 00314 yRightSummit = 0.0; 00315 yRightBottom = 0.0; 00316 } 00317 }; 00318 00320 00344 // this routine determines the intervals (including the transition one(s)) by an interative process 00345 // 00346 // frame is a vector consisting of 4 ordered elements: 00347 // [frame(1),frame(4)] is the interval which (tightly) contains all eigenvalues, and 00348 // [frame(2),frame(3)] is the interval in which the eigenvalues are sought 00349 // baseDeg is the left-and-right degree of the base filter for each interval 00350 // polyDeg is the (maximum possible) degree of s(z), with z*s(z) the polynomial filter 00351 // intv is the output; the j-th interval is [intv(j),intv(j+1)) 00352 // opts is a collection of interval options 00353 // 00354 // the base filter P(z) is a piecewise polynomial from Hermite interpolation with degree baseDeg at each end point of intervals 00355 // 00356 // the polynomial filter Q(z) is in the form z*s(z), i.e. Q(0)==0, such that ||(1-P(z))-z*s(z)||_w is minimized with 00357 // s(z) a polynomial of degree up to polyDeg 00358 // 00359 // the resulting polynomial filter Q(z) satisfies Q(x)>=Q(y) for x in [frame(2),frame(3)], and 00360 // y in [frame(1),frame(4)] but not in [frame(2),frame(3)] 00361 // 00362 // the routine returns an instance of PolynomialFilterInfo which gives some information of the polynomial filter 00363 PolynomialFilterInfo GetIntervals(Vector &intv, const Vector &frame, mkIndex polyDeg, mkIndex baseDeg, IntervalOptions &opts); 00364 00366 // same as GetIntervals() above, with default IntervalOptions 00367 PolynomialFilterInfo GetIntervals(Vector &intervals, const Vector &frame, mkIndex polyDeg, mkIndex baseDeg); // default interval options will be used 00368 00370 // end of group_base_filter 00371 00372 00373 00375 // Chebyshev Polynomials 00377 00383 00384 00394 // translate the coefficients of a Newton polynomial to the coefficients 00395 // in a basis of the `translated' Chebyshev polynomials 00396 // 00397 // input: 00398 // a Newton polynomial defined by vectors a and x: 00399 // P(z) = a(1) + a(2)*(z-x(1)) + a(3)*(z-x(1))*(z-x(2)) + ... + a(n)*(z-x(1))*...*(z-x(n-1)) 00400 // the interval [aa,bb] defines the `translated' Chebyshev polynomials S_i(z) = T_i((z-c)/h), 00401 // where c=(aa+bb)/2 and h=(bb-aa)/2, and T_i is the Chebyshev polynomial of the first kind 00402 // note that T_i is defined by T_0(z)=1, T_1(z)=z, and T_i(z)=2*z*T_{i-1}(z)+T_{i-2}(z) for i>=2 00403 // 00404 // output: 00405 // a vector q containing the Chebyshev coefficients, such that 00406 // P(z) = q(1)*S_0(z) + q(2)*S_1(z) + ... + q(n)*S_{n-1}(z) 00407 Vector ExpandNewtonPolynomialInChebyshevBasis(Real aa, Real bb, const Vector &a, const Vector &x); 00408 00410 00424 // evaluate P(z) at z=z0, where P(z) is a polynomial expanded in a basis of 00425 // the `translated' (i.e. scale-and-shift) Chebyshev polynomials 00426 // 00427 // input: 00428 // c is a vector of Chebyshev coefficients which defines the polynomial 00429 // P(z) = c(1)*S_0(z) + c(2)*S_1(z) + ... + c(n)*S_{n-1}(z), 00430 // where S_i is the `translated' Chebyshev polynomial S_i((z-c)/h) = T_i(z), with 00431 // c = (intv(j)+intv(j+1)) / 2, h = (intv(j+1)-intv(j)) / 2 00432 // note that T_i(z) is the Chebyshev polynomial of the first kind, 00433 // T_0(z) = 1, T_1(z) = z, and T_i(z) = 2*z*T_{i-1}(z) - T_{i-2}(z) for i>=2 00434 // 00435 // output: 00436 // the evaluated value of P(z) at z=z0 00437 Real PolynomialEvaluationInChebyshevBasis(const Vector &c, Real z0, Real aa=-1.0, Real bb=1.0); 00438 00440 00462 // evaluate P(z) at z=z0, where P(z) is a piecewise polynomial expanded 00463 // in a basis of the (optionally translated, i.e. scale-and-shift) Chebyshev polynomials for each interval 00464 // 00465 // input: 00466 // intv is a vector which defines the intervals; the j-th interval is [intv(j), intv(j+1)) 00467 // pp is a matrix of Chebyshev coefficients which defines a piecewise polynomial P(z) 00468 // in a basis of the `translated' Chebyshev polynomials in each interval 00469 // the polynomial P_j(z) in the j-th interval, i.e. when z is in [intv(j), intv(j+1)), is defined by the j-th column of pp: 00470 // if basisTranslated == false, then 00471 // P_j(z) = pp(1,j)*T_0(z) + pp(2,j)*T_1(z) + ... + pp(n,j)*T_{n-1}(z), 00472 // where T_i(z) is the Chebyshev polynomial of the first kind, 00473 // T_0(z) = 1, T_1(z) = z, and T_i(z) = 2*z*T_{i-1}(z) - T_{i-2}(z) for i>=2 00474 // if basisTranslated == true, then 00475 // P_j(z) = pp(1,j)*S_0(z) + pp(2,j)*S_1(z) + ... + pp(n,j)*S_{n-1}(z), 00476 // where S_i is the `translated' Chebyshev polynomial S_i((z-c)/h) = T_i(z), with 00477 // c = (intv(j)+intv(j+1)) / 2, h = (intv(j+1)-intv(j)) / 2 00478 // 00479 // output: 00480 // the evaluated value of P(z) at z=z0 00481 // 00482 // note that if z0 falls below the first interval, then the polynomial in the first interval will be used for evaluting P(z0) 00483 // if z0 flies over the last interval, then the polynomial in the last interval will be used for evaluting P(z0) 00484 Real PiecewisePolynomialEvaluationInChebyshevBasis(const Matrix &pp, const Vector &intv, Real z0, bool basisTranslated=true); 00485 00487 00510 // compute the weighted inner product of two piecewise polynomials expanded 00511 // in a basis of `translated' (i.e. scale-and-shift) Chebyshev polynomials for each interval 00512 // 00513 // pp and qq are two matrices of Chebyshev coefficients which define the piecewise polynomials P(z) and Q(z), respectively 00514 // For z in the j-th interval, P(z) equals 00515 // P_j(z) = pp(1,j)*S_0(z) + pp(2,j)*S_1(z) + ... + pp(n,j)*S_{n-1}(z), 00516 // and Q(z) equals 00517 // Q_j(z) = qq(1,j)*S_0(z) + qq(2,j)*S_1(z) + ... + qq(n,j)*S_{n-1}(z), 00518 // where S_i(z) is the `translated' Chebyshev polynomial in that interval, 00519 // S_i((z-c)/h) = T_i(z), c = (aa+bb)) / 2, h = (bb-aa) / 2, 00520 // with T_i(z) the Chebyshev polynomial of the first kind, 00521 // T_0(z) = 1, T_1(z) = z, and T_i(z) = 2*z*T_{i-1}(z) - T_{i-2}(z) for i>=2 00522 // 00523 // the (scaled) j-th interval inner product is defined by 00524 // <P_j,Q_j> = (Pi/2)*( pp(1,j)*qq(1,j) + sum_{k} pp(k,j)*qq(k,j) ), 00525 // which comes from the property 00526 // <T_0,T_0>=pi, <T_i,T_i>=pi/2 for i>=1, and <T_i,T_j>=0 for i!=j 00527 // 00528 // the weighted inner product is <P,Q> = sum_{j} intervalWeights(j)*<P_j,Q_j>, 00529 // which is the return value 00530 // 00531 // note that for unit weights, pass an empty vector of intervalWeights (i.e. of length 0) 00532 Real PiecewisePolynomialInnerProductInChebyshevBasis(const Matrix &pp, const Matrix &qq, const Vector &intervalWeights); 00533 00535 00552 // compute Q(z) = z*P(z), where P(z) and Q(z) are piecewise polynomials expanded 00553 // in a basis of `translated' (i.e. scale-and-shift) Chebyshev polynomials for each interval 00554 // 00555 // P(z) and Q(z) are stored as matrices of Chebyshev coefficients pp and qq, respectively 00556 // 00557 // for z in the j-th interval, P(z) equals 00558 // P_j(z) = pp(1,j)*S_0(z) + pp(2,j)*S_1(z) + ... + pp(n,j)*S_{n-1}(z), 00559 // and Q(z) equals 00560 // Q_j(z) = qq(1,j)*S_0(z) + qq(2,j)*S_1(z) + ... + qq(n,j)*S_{n-1}(z), 00561 // where S_i(z) is the `translated' Chebyshev polynomial in that interval, 00562 // S_i((z-c)/h) = T_i(z), c = (intv(j)+intv(j+1))) / 2, h = (intv(j+1)-intv(j)) / 2, 00563 // with T_i(z) the Chebyshev polynomial of the first kind, 00564 // T_0(z) = 1, T_1(z) = z, and T_i(z) = 2*z*T_{i-1}(z) - T_{i-2}(z) for i>=2 00565 // 00566 // the returned matrix is qq which represents Q(z) = z*P(z) 00567 Matrix PiecewisePolynomialInChebyshevBasisMultiplyX(const Matrix &pp, const Vector &intv); 00568 // end of group_chebyshev 00570 00571 00572 00574 // Conjugate Residual Method in the Polynomial Space 00576 00581 00582 00614 // this routine employs a conjugate-residual-type algorithm in polynomial space to minimize ||P(z)-Q(z)||_w, 00615 // where P(z), the base filter, is the input piecewise polynomial, and 00616 // Q(z) is the output polynomial satisfying Q(0)==1, i.e. the constant term of Q(z) is 1 00617 // niter is the number of conjugate-residual iterations; therefore, the degree of Q(z) is up to niter+1 00618 // both P(z) and Q(z) are expanded in the `translated' (scale-and-shift) Chebyshev basis for each interval, 00619 // and presented as matrices of Chebyshev coefficients, denoted by pp and qq, respectively 00620 // 00621 // input: 00622 // intv is a vector which defines the intervals; the j-th interval is [intv(j),intv(j+1)) 00623 // w is a vector of Chebyshev weights; the weight of j-th interval is w(j) 00624 // the interval weights define the inner product of two continuous functions and then 00625 // the derived w-norm ||P(z)-Q(z)||_w 00626 // pp is a matrix of Chebyshev coefficients which defines the piecewise polynomial P(z) 00627 // to be specific, for z in [intv(j), intv(j+1)), P(z) equals 00628 // P_j(z) = pp(1,j)*S_0(z) + pp(2,j)*S_1(z) + ... + pp(niter+2,j)*S_{niter+1}(z), 00629 // where S_i(z) is the `translated' Chebyshev polynomial in that interval, 00630 // S_i((z-c)/h) = T_i(z), c = (intv(j)+intv(j+1))) / 2, h = (intv(j+1)-intv(j)) / 2, 00631 // with T_i(z) the Chebyshev polynomial of the first kind, 00632 // T_0(z) = 1, T_1(z) = z, and T_i(z) = 2*z*T_{i-1}(z) - T_{i-2}(z) for i>=2 00633 // 00634 // output: 00635 // the return matrix, denoted by qq, represents a polynomial Q(z) with degree up to 1+niter 00636 // and satisfying Q(0)==1, such that ||P(z))-Q(z)||_w is minimized 00637 // this polynomial Q(z) is expanded in the `translated' Chebyshev basis for each interval 00638 // to be precise, considering z in [intv(j), intv(j+1)), Q(z) equals 00639 // Q_j(z) = qq(1,j)*S_0(z) + qq(2,j)*S_1(z) + ... + qq(niter+2,j)*S_{niter+1}(z) 00640 // 00641 // note: 00642 // 1. since Q(0)==1, P(0)==1 is expected; if P(0)!=1, one can translate P(z) 00643 // for example, if P(0)==0, one can use 1-P(z) as input instead of P(z) 00644 // 2. typically, the base filter, defined by pp and intv, is from Hermite interpolation 00645 // in intervals [intv(j),intv(j+1)) for j=1,...,nintv, with nintv the number of intervals 00646 Matrix FilteredConjugateResidualPolynomial(const Matrix &pp, const Vector &intv, 00647 const Vector &w, mkIndex niter); 00648 00650 00696 // this routine employs a conjugate-residual-type algorithm in polynomial space to compute 00697 // x = x0 + s(A)*r0 with r0 = b - A*x0, such that ||(1-P(z))-z*s(z)||_w is minimized, where 00698 // P(z) is a given piecewise polynomial, called the base filter, 00699 // s(z) is a polynomial of degree up to niter, the number of conjugate-residual iterations, 00700 // and b and x0 are given vectors 00701 // 00702 // note that P(z) is expanded in the `translated' (scale-and-shift) Chebyshev basis for each interval, 00703 // and presented as a matrix of Chebyshev coefficients pp 00704 // 00705 // input: 00706 // A is a sparse matrix 00707 // x0, b are vectors 00708 // niter is the number of conjugate-residual iterations 00709 // intv is a vector which defines the intervals; the j-th interval is [intv(j),intv(j+1)) 00710 // w is a vector of Chebyshev weights; the weight of j-th interval is w(j) 00711 // the interval weights define the inner product of two continuous functions and then 00712 // the derived w-norm ||P(z)-Q(z)||_w 00713 // pp is a matrix of Chebyshev coefficients which defines the piecewise polynomial P(z) 00714 // to be specific, for z in [intv(j), intv(j+1)), P(z) equals 00715 // P_j(z) = pp(1,j)*S_0(z) + pp(2,j)*S_1(z) + ... + pp(niter+2,j)*S_{niter+1}(z), 00716 // where S_i(z) is the `translated' Chebyshev polynomial in that interval, 00717 // S_i((z-c)/h) = T_i(z), c = (intv(j)+intv(j+1))) / 2, h = (intv(j+1)-intv(j)) / 2, 00718 // with T_i(z) the Chebyshev polynomial of the first kind, 00719 // T_0(z) = 1, T_1(z) = z, and T_i(z) = 2*z*T_{i-1}(z) - T_{i-2}(z) for i>=2 00720 // tol is the tolerance; if the residual polynomial in z-norm is dropped by a factor lower 00721 // than tol, then stop the conjugate-residual iteration 00722 // 00723 // output: 00724 // the return vector is x = x0 + s(A)*r0 with r0 = b - A*x0, such that ||(1-P(z))-z*s(z)||_w is minimized, 00725 // subject to that s(z) is a polynomial of degree up to niter, where P(z) is the base filter 00726 // in short, z*s(z) approximates 1-P(z) 00727 // 00728 // note: 00729 // 1. since z*s(z) approximates 1-P(z), P(0)==1 is expected; if P(0)!=1, one can translate P(z) 00730 // for example, if P(0)==0, one can use 1-P(z) as input instead of P(z) 00731 // 2. typically, the base filter, defined by pp and intv, is from Hermite interpolation 00732 // in intervals [intv(j),intv(j+1)) for j=1,...,nintv, with nintv the number of intervals 00733 // 3. a common application is to compute R(A)*b, where R(z) approximates 1-P(z) 00734 // in this case, one can set x0 = 0 and then the return vector is x = s(A)*b, where 00735 // z*s(z) approximates 1-P(z); therefore, A*x is the wanted R(A)*b 00736 // see also PolynomialFilterInterface::filteredSparseMatrixPolynomialVectorProduct() 00737 Vector FilteredConjugateResidualMatrixPolynomialVectorProduct(const SparseMatrix &A, const Vector &x0, const Vector &b, 00738 const Matrix &pp, const Vector &intv, const Vector &w, 00739 mkIndex niter, Real tol=0.0); 00740 00742 00751 // an interface to define R(S), i.e. set R and S, and compute R(S)*v, where 00752 // S is a sparse symmetric matrix, 00753 // R(z) is a polynomial which approximates a piecewise polynomial 1-P(z), with P(z) the base filter, and 00754 // v is the input vector 00755 // 00756 // in short, use setFilter() to define R(S) once, and 00757 // use filteredSparseMatrixPolynomialVectorProduct() to compute R(S)*v for every v 00758 class PolynomialFilterInterface { 00759 private: 00760 // works for SparseMatrix only 00762 // a pointer to the input sparse symmetric matrix via setFilter() 00763 static const SparseMatrix *Sptr; 00765 // the sparse symmetric matrix S in computing R(S)*v; S is translated from the input sparse symmetric matrix S0 in setFilter() 00766 static SparseMatrix S; 00767 00768 // parameters for polynomial filtering 00770 00779 // the j-th interval is [intervals(j),intervals(j+1)) 00780 // the intervals are decided by GetIntervals() invoked by setFilter() which takes parameters frame, baseDeg, and polyDeg: 00781 // 1. frame is a vector consisting of 4 ordered elements: 00782 // [frame(1),frame(4)] is the interval which (tightly) contains all eigenvalues of S, and 00783 // [frame(2),frame(3)] is the interval in which the eigenvalues are sought 00784 // 2. baseDeg is the left-and-right degree of the base filter for each interval 00785 // 3. polyDeg is the (maximum possible) degree of z*s(z), with s(z) the polynomial filter 00786 static Vector intervals; 00788 // intervalWeights(j) is the weight of j-th interval [intervals(j), intervals(j+1)) 00789 static Vector intervalWeights; 00791 // maximum possible degree of s(z), with z*s(z) the polynomial filter 00792 static mkIndex polyDegree; 00794 // left-and-right degree of the base filter in each interval 00795 static mkIndex baseDegree; 00797 00800 // a base filter, which is a piecewise polynomial typically from Hermite interpolation 00801 // for j-th interval, the polynomial is expanded in the `translated' (scale-and-shift) Chebyshev basis, 00802 // with the Chebyshev coefficients stored in baseFilter(:,j) 00803 static Matrix baseFilter; 00805 // a zero vector of length the number of rows/columns of S 00806 static Vector zn; 00807 00808 public: 00810 // the information of computing the polynomial filter; see class PolynomialFilterInfo in polyfilt.h for more information 00811 static PolynomialFilterInfo filterInfo; 00812 00813 // routines for the polynomial filtered Lanczos eigensolver 00815 00825 // this member function sets the sparse matrix S translated from S0, and also the base filter P(z) 00826 // S0 is the sparse symmetric matrix of concern 00827 // frame is a vector of 4 ordered elements 00828 // [frame(1),frame(4)] is the interval which (tightly) contains all eigenvalues of S0, and 00829 // [frame(2),frame(3)] is the interval in which the eigenvalues of S0 are sought 00830 // polyDeg is the (maximum possible) degree of s(z), with z*s(z) the polynomial filter 00831 // baseDeg is the left-and-right degree of the base filter for each interval 00832 // opts is a collection of options to determine the intervals 00833 static Vector setFilter(const SparseMatrix &S0, const Vector &frame, mkIndex polyDeg, mkIndex baseDeg, IntervalOptions &opts); 00835 00843 // this routine computes R(S)*v, where it is assumed that S and R(z) have been defined by setFilter() 00844 // R(z) is in the form z*s(z) which minimizes ||(1-P(z))-z*s(z)||_w by a conjugate-residual-type algorithm, 00845 // where P(z) is a piecewise polynomial as the base filter, and s(z) is a polynomial of degree up to polyDegree, 00846 // and w-norm is defined by data members intervals and intervalWeights 00847 // 00848 // note that P(z) is defined by the data members baseFilter and intervals 00849 // it is expanded in the `translated' (scale-and-shift) Chebyshev basis for each interval, 00850 // and presented as a matrix of Chebyshev coefficients baseFilter 00851 // 00852 // see also FilteredConjugateResidualMatrixPolynomialVectorProduct() 00853 static Vector filteredSparseMatrixPolynomialVectorProduct(const Vector &v) { 00854 return (*Sptr)*FilteredConjugateResidualMatrixPolynomialVectorProduct(*Sptr, zn, v, baseFilter, intervals, intervalWeights, polyDegree); 00855 } 00856 }; 00857 // end of group_cr_poly 00859 00860 00861 #endif
1.7.3