43 #ifndef MAT_TRUNCATION 44 #define MAT_TRUNCATION 52 template<
typename Tmatrix,
typename Treal>
56 Treal
run(Treal
const threshold);
60 Treal
const threshold ) = 0;
61 virtual void getFrobSqNorms( std::vector<Treal> & frobsq_norms ) = 0;
64 Treal
const threshold ) = 0;
69 template<
typename Tmatrix,
typename Treal>
79 template<
typename Tmatrix,
typename Treal>
81 assert(threshold >= (Treal)0.0);
82 if (threshold == (Treal)0.0)
84 std::vector<Treal> frobsq_norms;
85 this->getFrobSqNorms( frobsq_norms );
86 std::sort(frobsq_norms.begin(), frobsq_norms.end());
88 int high = frobsq_norms.size() - 1;
89 Treal lowFrobTrunc, highFrobTrunc;
90 this->getFrobTruncBounds( lowFrobTrunc, highFrobTrunc, threshold );
92 while( low < (
int)frobsq_norms.size() - 1 && frobsqSum < lowFrobTrunc ) {
94 frobsqSum += frobsq_norms[low];
98 while( high < (
int)frobsq_norms.size() - 1 && frobsqSum < highFrobTrunc ) {
100 frobsqSum += frobsq_norms[high];
103 int minStep = int( 0.01 * frobsq_norms.size() );
104 minStep = minStep > 0 ? minStep : 1;
105 int testIndex = high;
106 int previousTestIndex = high * 2;
110 while ( euclEInt.
upp() > threshold ) {
113 int stepSize = (int)((high - low) * 0.01);
115 stepSize = stepSize >= minStep ? stepSize : minStep;
116 previousTestIndex = testIndex;
117 testIndex -= stepSize;
119 testIndex = testIndex > low ? testIndex : low;
124 while(testIndex >= 0 && frobsq_norms[testIndex] == frobsq_norms[testIndex+1])
131 assert( previousTestIndex != testIndex );
132 Treal currentFrobTrunc = frobsq_norms[testIndex];
133 frobThreshLowLevel( currentFrobTrunc );
134 euclEInt =
euclIfSmall( Treal(threshold * 1e-2), threshold );
138 if ( testIndex <= -1 ) {
139 frobThreshLowLevel( (Treal)0.0 );
143 euclE = euclEInt.
upp();
153 template<
typename Tmatrix,
typename Treal>
160 Treal
const threshold );
164 Treal
const threshold );
167 template<
typename Tmatrix,
typename Treal>
169 Treal
const threshold ) {
171 lowTrunc = (threshold * threshold) / 2;
172 highTrunc = (threshold * threshold * this->
A.get_nrows()) / 2;
175 template<
typename Tmatrix,
typename Treal>
177 this->
A.getMatrix().getFrobSqLowestLevel(frobsq_norms);
180 template<
typename Tmatrix,
typename Treal>
182 this->
A.getMatrix().frobThreshLowestLevel( threshold, &this->E.getMatrix() );
185 template<
typename Tmatrix,
typename Treal>
187 Treal
const threshold ) {
190 if ( tmpInterval.
length() < 2*absTol )
202 template<
typename Tmatrix,
typename TmatrixZ,
typename Treal>
209 Treal
const threshold );
213 Treal
const threshold );
217 template<
typename Tmatrix,
typename TmatrixZ,
typename Treal>
219 Treal
const threshold ) {
220 Treal Zfrob = Z.frob();
221 Treal thresholdTakingZIntoAccount = threshold / (Zfrob * Zfrob);
223 lowTrunc = thresholdTakingZIntoAccount * thresholdTakingZIntoAccount / 2.0;
224 highTrunc = template_blas_get_num_limit_max<Treal>();
227 template<
typename Tmatrix,
typename TmatrixZ,
typename Treal>
229 Treal
const threshold ) {
233 if ( tmpInterval.
length() < 2*absTol )
245 template<
typename Tmatrix,
typename Treal>
257 template<
typename Tmatrix,
typename Treal>
259 this->
A.getMatrix().getFrobSqElementLevel(frobsq_norms);
262 template<
typename Tmatrix,
typename Treal>
264 this->
A.getMatrix().frobThreshElementLevel(threshold, &this->E.getMatrix() );
271 template<
typename Tmatrix,
typename Treal>
278 Treal
const threshold );
282 Treal
const threshold );
285 template<
typename Tmatrix,
typename Treal>
287 Treal
const threshold ) {
293 lowTrunc = (threshold * threshold);
298 highTrunc = (threshold * threshold * this->
A.get_nrows());
301 template<
typename Tmatrix,
typename Treal>
303 this->
A.getMatrix().getFrobSqLowestLevel(frobsq_norms);
306 template<
typename Tmatrix,
typename Treal>
308 this->
A.getMatrix().frobThreshLowestLevel( threshold, &this->E.getMatrix() );
311 template<
typename Tmatrix,
typename Treal>
313 Treal
const threshold ) {
318 Treal absTolDummy = template_blas_get_num_limit_max<Treal>();
319 Treal relTol = 100 * mat::getMachineEpsilon<Treal>();
322 if ( tmpInterval.length() < 2*absTol )
324 tmpInterval.midPoint()+absTol );
337 template<
typename Tmatrix,
typename TmatrixB,
typename Treal>
344 Treal
const threshold );
348 Treal
const threshold );
352 template<
typename Tmatrix,
typename TmatrixB,
typename Treal>
355 Treal
const threshold ) {
356 Treal Afrob = this->
A.frob();
357 Treal Bfrob =
B.frob();
360 highTrunc = template_blas_get_num_limit_max<Treal>();
363 template<
typename Tmatrix,
typename TmatrixB,
typename Treal>
365 Treal
const threshold ) {
369 if ( tmpInterval.
length() < 2*absTol ) {
Treal upp() const
Definition: Interval.h:145
virtual void frobThreshLowLevel(Treal const threshold)
Definition: truncation.h:181
EuclTruncationBase(Tmatrix &A_)
Definition: truncation.h:70
Tmatrix & A
Definition: truncation.h:65
mat::SizesAndBlocks rows
Definition: test.cc:51
mat::SizesAndBlocks cols
Definition: test.cc:52
TmatrixZ const & Z
Definition: truncation.h:214
EuclTruncationSymm(Tmatrix &A_)
Definition: truncation.h:156
virtual void getFrobSqNorms(std::vector< Treal > &frobsq_norms)
Definition: truncation.h:176
Truncation of symmetric matrices at the element level (used for mixed norm truncation) ...
Definition: truncation.h:246
EuclTruncationSymmWithZ(Tmatrix &A_, TmatrixZ const &Z_)
Definition: truncation.h:205
Interval< Treal > euclIfSmall(Tmatrix const &M, Treal const requestedAbsAccuracy, Treal const requestedRelAccuracy, Treal const maxAbsVal, typename Tmatrix::VectorType *const eVecPtr=0, int maxIter=-1)
Returns interval containing the Euclidean norm of the matrix M.
Definition: LanczosLargestMagnitudeEig.h:260
Truncation of general matrices.
Definition: truncation.h:272
virtual void getFrobTruncBounds(Treal &lowTrunc, Treal &highTrunc, Treal const threshold)
Definition: truncation.h:286
virtual Interval< Treal > euclIfSmall(Treal const absTol, Treal const threshold)=0
virtual void getFrobTruncBounds(Treal &lowTrunc, Treal &highTrunc, Treal const threshold)
Definition: truncation.h:218
Definition: allocate.cc:39
Describes dimensions of matrix and its blocks on all levels.
Definition: SizesAndBlocks.h:45
Definition: Interval.h:46
EuclTruncationCongrTransMeasure(Tmatrix &A_, TmatrixB const &B_)
Definition: truncation.h:340
EuclTruncationSymmElementLevel(Tmatrix &A_)
Definition: truncation.h:248
EuclTruncationGeneral(Tmatrix &A_)
Definition: truncation.h:274
virtual void frobThreshLowLevel(Treal const threshold)
Definition: truncation.h:263
TmatrixB const & B
Definition: truncation.h:349
virtual void frobThreshLowLevel(Treal const threshold)=0
Treal run(Treal const threshold)
Definition: truncation.h:80
virtual void getFrobSqNorms(std::vector< Treal > &frobsq_norms)
Definition: truncation.h:258
Treal midPoint() const
Definition: Interval.h:115
virtual Interval< Treal > euclIfSmall(Treal const absTol, Treal const threshold)
Definition: truncation.h:364
Definition: mat_utils.h:106
virtual void getFrobTruncBounds(Treal &lowTrunc, Treal &highTrunc, Treal const threshold)
Definition: truncation.h:353
Definition: mat_utils.h:137
Definition: mat_utils.h:78
virtual void getFrobSqNorms(std::vector< Treal > &frobsq_norms)=0
Definition: truncation.h:53
virtual void frobThreshLowLevel(Treal const threshold)
Definition: truncation.h:307
virtual ~EuclTruncationBase()
Definition: truncation.h:57
Tmatrix E
Definition: truncation.h:66
virtual void getFrobTruncBounds(Treal &lowTrunc, Treal &highTrunc, Treal const threshold)=0
virtual Interval< Treal > euclIfSmall(Treal const absTol, Treal const threshold)
Definition: truncation.h:186
Treal length() const
Returns the length of the interval.
Definition: Interval.h:109
Truncation of symmetric matrices.
Definition: truncation.h:154
Truncation of symmetric matrices with Z.
Definition: truncation.h:203
virtual Interval< Treal > euclIfSmall(Treal const absTol, Treal const threshold)
Definition: truncation.h:312
virtual void getFrobSqNorms(std::vector< Treal > &frobsq_norms)
Definition: truncation.h:302
Truncation of general matrices with impact on matrix triple multiply as error measure.
Definition: truncation.h:338
Treal template_blas_sqrt(Treal x)
virtual Interval< Treal > euclIfSmall(Treal const absTol, Treal const threshold)
Definition: truncation.h:228
virtual void getFrobTruncBounds(Treal &lowTrunc, Treal &highTrunc, Treal const threshold)
Definition: truncation.h:168