1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/* Ergo, version 3.8, a program for linear scaling electronic structure
* calculations.
* Copyright (C) 2019 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
* and Anastasia Kruchinina.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Primary academic reference:
* Ergo: An open-source program for linear-scaling electronic structure
* calculations,
* Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
* Kruchinina,
* SoftwareX 7, 107 (2018),
* <http://dx.doi.org/10.1016/j.softx.2018.03.005>
*
* For further information about Ergo, see <http://www.ergoscf.org>.
*/
/** @file mat_acc_extrapolate.h
@brief Functionality for performing a scan testing different
threshold values for some kind of matrix computation. Can be used
for accuracy scans of e.g. Coulomb of HF exchange matrix
evaluation.
@author: Elias Rudberg <em>responsible</em>
*/
#ifndef ERGO_MAT_ACC_EXTRAPOLATE_HEADER
#define ERGO_MAT_ACC_EXTRAPOLATE_HEADER
#include <vector>
#include "matrix_utilities.h"
template<class Treal, class Tworker>
class MatAccInvestigator
{
public:
explicit MatAccInvestigator(mat::SizesAndBlocks const & matrix_size_block_info_);
void Scan(const Tworker & worker,
Treal firstParam,
Treal stepFactor,
int nSteps);
void GetScanResult(Treal* threshList_,
Treal* errorList_frob_,
Treal* errorList_eucl_,
Treal* errorList_maxe_,
Treal* timeList_);
private:
mat::SizesAndBlocks matrix_size_block_info;
int nScanSteps;
Treal baseThresh;
std::vector<Treal> threshList;
std::vector<Treal> errorList_frob; // Frobenius norm
std::vector<Treal> errorList_eucl; // Euclidean norm
std::vector<Treal> errorList_maxe; // Max element norm
std::vector<Treal> timeList;
};
template<class Treal, class Tworker>
MatAccInvestigator<Treal, Tworker>::MatAccInvestigator(mat::SizesAndBlocks const & matrix_size_block_info_)
: matrix_size_block_info(matrix_size_block_info_)
{}
template<class Treal, class Tworker>
void MatAccInvestigator<Treal, Tworker>
::Scan(const Tworker & worker,
Treal firstParam,
Treal stepFactor,
int nSteps)
{
nScanSteps = nSteps;
baseThresh = firstParam;
threshList.resize(nSteps);
errorList_frob.resize(nSteps);
errorList_eucl.resize(nSteps);
errorList_maxe.resize(nSteps);
timeList.resize(nSteps);
// Prepare matrix objects
symmMatrix accurateMatrix;
accurateMatrix.resetSizesAndBlocks(matrix_size_block_info,
matrix_size_block_info);
symmMatrix otherMatrix;
otherMatrix.resetSizesAndBlocks(matrix_size_block_info,
matrix_size_block_info);
symmMatrix errorMatrix;
errorMatrix.resetSizesAndBlocks(matrix_size_block_info,
matrix_size_block_info);
// Compute "accurate" matrix
worker.ComputeMatrix(firstParam, accurateMatrix);
// Compute other matrices and compare them to "accurate" matrix
Treal currParam = firstParam;
for(int i = 0; i < nSteps; i++)
{
currParam *= stepFactor;
time_t startTime, endTime;
time(&startTime);
worker.ComputeMatrix(currParam, otherMatrix);
time(&endTime);
timeList[i] = endTime - startTime;
threshList[i] = currParam;
// Compute error matrix
errorMatrix = otherMatrix;
errorMatrix += (ergo_real)(-1) * accurateMatrix;
// Compute different norms of error matrix
// Frobenius norm
errorList_frob[i] = errorMatrix.frob();
// Euclidean norm
Treal euclAcc = 1e-11;
errorList_eucl[i] = errorMatrix.eucl(euclAcc);
// Max element norm
errorList_maxe[i] = compute_maxabs_sparse(errorMatrix);
}
}
template<class Treal, class Tworker>
void MatAccInvestigator<Treal, Tworker>
::GetScanResult(Treal* threshList_,
Treal* errorList_frob_,
Treal* errorList_eucl_,
Treal* errorList_maxe_,
Treal* timeList_)
{
for(int i = 0; i < nScanSteps; i++)
{
threshList_[i] = threshList[i];
errorList_frob_[i] = errorList_frob[i];
errorList_eucl_[i] = errorList_eucl[i];
errorList_maxe_[i] = errorList_maxe[i];
timeList_ [i] = timeList [i];
}
}
#endif
|