mirror of
https://github.com/TREX-CoE/Sherman-Morrison.git
synced 2024-12-24 13:23:45 +01:00
- Added a small 3x3 example that will always become singular regardles the order of the applied updates. This example is added to test Maponi A3 augmented with Slagel-splitting.
- Slagel-splitting in Maponi A3 is now working. A thourough analysis on the QMC=Chem datasets still has te be done. - Acceptance tollerance in 'test_h5' on the residuals can be set at runtime now.
This commit is contained in:
parent
e3815267fb
commit
3ee4d3b56d
@ -1,5 +1,5 @@
|
||||
#START_PACKET
|
||||
#CYCLE_ID: 13
|
||||
#CYCLE_ID: 1
|
||||
#SLATER_MATRIX_DIM: 21
|
||||
#NUPDATES: 3
|
||||
#SLATER_MATRIX: (i (outer), j (inner)), slater_matrix_alpha(i,j), ddet * slater_matrix_alpha_inv_det(i,j) / ddet
|
||||
@ -513,7 +513,7 @@
|
||||
#END_PACKET
|
||||
|
||||
#START_PACKET
|
||||
#CYCLE_ID: 8169
|
||||
#CYCLE_ID: 2
|
||||
#SLATER_MATRIX_DIM: 4
|
||||
#NUPDATES: 2
|
||||
#SLATER_MATRIX: (i (outer), j (inner)), slater_matrix_alpha(i,j), ddet * slater_matrix_alpha_inv_det(i,j) / ddet
|
||||
@ -544,3 +544,31 @@
|
||||
#COL_UPDATE_COMP_(03): 0.000000000000000E+00
|
||||
#COL_UPDATE_COMP_(04): -1.000000000000000E+00
|
||||
#END_PACKET
|
||||
|
||||
#START_PACKET
|
||||
#CYCLE_ID: 3
|
||||
#SLATER_MATRIX_DIM: 3
|
||||
#NUPDATES: 3
|
||||
#SLATER_MATRIX: (i (outer), j (inner)), slater_matrix_alpha(i,j), ddet * slater_matrix_alpha_inv_det(i,j) / ddet
|
||||
(01,01) 1.000000000000000E+00 1.000000000000000E+00
|
||||
(01,02) 0.000000000000000E+00 0.000000000000000E+00
|
||||
(01,03) 0.000000000000000E+00 0.000000000000000E+00
|
||||
(02,01) 0.000000000000000E+00 0.000000000000000E+00
|
||||
(02,02) 1.000000000000000E+00 1.000000000000000E+00
|
||||
(02,03) 0.000000000000000E+00 0.000000000000000E+00
|
||||
(03,01) 0.000000000000000E+00 0.000000000000000E+00
|
||||
(03,02) 0.000000000000000E+00 0.000000000000000E+00
|
||||
(03,03) -1.000000000000000E+00 -1.000000000000000E+00
|
||||
#COL_UPDATE_INDEX: 1
|
||||
#COL_UPDATE_COMP_(01): 1.000000000000000E+00
|
||||
#COL_UPDATE_COMP_(02): 1.000000000000000E+00
|
||||
#COL_UPDATE_COMP_(03): -1.000000000000000E+00
|
||||
#COL_UPDATE_INDEX: 2
|
||||
#COL_UPDATE_COMP_(01): 1.000000000000000E+00
|
||||
#COL_UPDATE_COMP_(02): 1.000000000000000E+00
|
||||
#COL_UPDATE_COMP_(03): 0.000000000000000E+00
|
||||
#COL_UPDATE_INDEX: 3
|
||||
#COL_UPDATE_COMP_(01): 1.000000000000000E+00
|
||||
#COL_UPDATE_COMP_(02): 0.000000000000000E+00
|
||||
#COL_UPDATE_COMP_(03): -1.000000000000000E+00
|
||||
#END_PACKET
|
||||
|
Binary file not shown.
@ -4,14 +4,14 @@
|
||||
#include "SM_MaponiA3S.hpp"
|
||||
#include "SM_Helpers.hpp"
|
||||
|
||||
#define DEBUG
|
||||
// #define DEBUG
|
||||
|
||||
void MaponiA3S(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
double *Updates, unsigned int *Updates_index) {
|
||||
/*
|
||||
DECLARE AND INITIALISE ARRAYS
|
||||
*/
|
||||
|
||||
showVector(Updates_index, Dim, "Updates_index");
|
||||
unsigned int k, l, i, j, component;
|
||||
unsigned int *p = new unsigned int[N_updates + 1]{0};
|
||||
double alpha, beta;
|
||||
@ -40,13 +40,14 @@ void MaponiA3S(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
/*
|
||||
START ALGORITHM
|
||||
*/
|
||||
showMatrix(Slater_inv, Dim, "S^{-1}");
|
||||
|
||||
// Calculate the {y_{0,k}}
|
||||
// Calculate the y_{0,k} = S_0^{-1} u_k
|
||||
for (k = 1; k < N_updates + 1; k++) {
|
||||
#ifdef DEBUG
|
||||
std::cout << "Compute y0k: " << std::endl;
|
||||
std::cout << "ylk[0][" << k << "][:]";
|
||||
std::cout << std::endl;
|
||||
std::cerr << "Compute y0k: " << std::endl;
|
||||
std::cerr << "ylk[0][" << k << "][:]";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
for (i = 1; i < Dim + 1; i++) {
|
||||
for (j = 1; j < Dim + 1; j++) {
|
||||
@ -55,15 +56,15 @@ void MaponiA3S(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
}
|
||||
}
|
||||
#ifdef DEBUG
|
||||
showVector(ylk[0][k], Dim, "");
|
||||
showVector(ylk[0][k], Dim+1, "");
|
||||
#endif
|
||||
}
|
||||
|
||||
// Calculate the {y_{l,k}} from the {y_{0,k}}
|
||||
for (l = 0; l < N_updates; l++) {
|
||||
#ifdef DEBUG
|
||||
std::cout << "In outer compute-ylk-loop: l = " << l << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cerr << "In outer compute-ylk-loop: l = " << l << std::endl;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
|
||||
// For given l select intermediate update with largest break-down val
|
||||
@ -73,35 +74,44 @@ void MaponiA3S(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
component = Updates_index[p[l + 1] - 1];
|
||||
beta = 1 + ylk[l][p[l + 1]][component];
|
||||
#ifdef DEBUG
|
||||
std::cout << "p[l+1] = " << p[l + 1] << std::endl;
|
||||
std::cout << "component = " << component << std::endl;
|
||||
std::cout << "beta = 1 + ylk[" << l << "][" << p[l + 1] << "][" << component
|
||||
std::cerr << "p[l+1] = " << p[l + 1] << std::endl;
|
||||
std::cerr << "component = " << component << std::endl;
|
||||
std::cerr << "beta = 1 + ylk[" << l << "][" << p[l + 1] << "][" << component
|
||||
<< "] = " << beta << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
if (fabs(beta) < threshold()) {
|
||||
std::cerr << "Breakdown condition triggered at " << component
|
||||
#ifdef DEBUG
|
||||
std::cerr << "Breakdown condition triggered at l = " << l << " and component "<< component
|
||||
<< std::endl;
|
||||
|
||||
for (unsigned int i = 0; i < Dim; i++) {
|
||||
later_updates[later * Dim + i] = Updates[l * Dim + i] * 0.5;
|
||||
#endif
|
||||
for (unsigned int i = 1; i < Dim + 1; i++) {
|
||||
std::cout << "Let's split..." << std::endl;
|
||||
ylk[l][p[l + 1]][i] *= 0.5;
|
||||
// later_updates[later * Dim + i - 1] = ylk[l][p[l + 1]][i]; // Updates[l * Dim + i] * 0.5;
|
||||
later_updates[later * Dim + i - 1] = Updates[l * Dim + i - 1] * 0.5;
|
||||
}
|
||||
later_index[later] = Updates_index[p[l + 1]];
|
||||
later_index[later] = Updates_index[p[l + 1] - 1];
|
||||
std::cout << "Later = " << later << std::endl;
|
||||
later++;
|
||||
std::cout << "Later = " << later << std::endl;
|
||||
beta = 1 + ylk[l][p[l + 1]][component];
|
||||
std::cout << "New beta is: " << beta << std::endl;
|
||||
}
|
||||
double ibeta = 1.0 / beta;
|
||||
showVector(ylk[l][p[l + 1]], Dim+1, "");
|
||||
showVector(later_updates+(Dim*0), Dim, "later_updateds");
|
||||
|
||||
|
||||
// Compute intermediate update to Slater_inv
|
||||
#ifdef DEBUG
|
||||
std::cout << "Compute intermediate update to Slater_inv" << std::endl;
|
||||
std::cout << "component = " << component << std::endl;
|
||||
std::cout << "beta = 1 + ylk[" << l << "][" << p[l + 1] << "][" << component
|
||||
std::cerr << "Compute intermediate update to Slater_inv" << std::endl;
|
||||
std::cerr << "component = " << component << std::endl;
|
||||
std::cerr << "beta = 1 + ylk[" << l << "][" << p[l + 1] << "][" << component
|
||||
<< "]" << std::endl;
|
||||
std::cout << "ylk[l][p[k]][:] = ylk[" << l << "][" << p[l + 1] << "][:]"
|
||||
std::cerr << "ylk[l][p[k]][:] = ylk[" << l << "][" << p[l + 1] << "][:]"
|
||||
<< std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
for (i = 0; i < Dim; i++) {
|
||||
for (j = 0; j < Dim; j++) {
|
||||
@ -118,13 +128,14 @@ void MaponiA3S(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
for (k = l + 2; k < N_updates + 1; k++) {
|
||||
alpha = ylk[l][p[k]][component] * ibeta;
|
||||
#ifdef DEBUG
|
||||
std::cout << "Inside k-loop: k = " << k << std::endl;
|
||||
std::cout << "ylk[" << l + 1 << "][" << p[k] << "][:]" << std::endl;
|
||||
std::cout << std::endl;
|
||||
std::cerr << "Inside k-loop: k = " << k << std::endl;
|
||||
std::cerr << "ylk[" << l + 1 << "][" << p[k] << "][:]";
|
||||
std::cerr << std::endl;
|
||||
#endif
|
||||
for (i = 1; i < Dim + 1; i++) {
|
||||
ylk[l + 1][p[k]][i] = ylk[l][p[k]][i] - alpha * ylk[l][p[l + 1]][i];
|
||||
}
|
||||
showVector(ylk[l + 1][p[k]], Dim+1, "");
|
||||
}
|
||||
}
|
||||
memcpy(Slater_inv, last, Dim * Dim * sizeof(double));
|
||||
@ -142,7 +153,8 @@ void MaponiA3S(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
delete[] Al, next, p, ylk;
|
||||
|
||||
if (later > 0) {
|
||||
std::cout << "Entering recursive loop with " << l << " updates" << std::endl;
|
||||
std::cerr << "Entering recursive loop with " << later << " updates" << std::endl;
|
||||
std::cout << later_index[0] << std::endl;
|
||||
MaponiA3S(Slater_inv, Dim, later, later_updates, later_index);
|
||||
}
|
||||
}
|
||||
|
@ -162,7 +162,8 @@ void SM3(double *Slater_inv, unsigned int Dim, unsigned int N_updates,
|
||||
|
||||
// If all the updates have failed, exit early with an error
|
||||
if (later == N_updates) {
|
||||
std::cerr << "SM3 cannot invert this matrix" << std::endl;
|
||||
std::cerr << "SM3 cannot invert matrix." << std::endl;
|
||||
showMatrix(Slater_inv, Dim, "Slater_inverse");
|
||||
return;
|
||||
}
|
||||
// If some have failed, make a recursive call
|
||||
|
@ -12,6 +12,7 @@ ALGO=$1
|
||||
START=$2
|
||||
STOP=$3
|
||||
BLOCKSIZE=329
|
||||
TOLERANCE=1e-3
|
||||
|
||||
BLOCKS=$((STOP / BLOCKSIZE))
|
||||
LEFT=$((STOP % BLOCKSIZE))
|
||||
@ -25,17 +26,17 @@ then
|
||||
do
|
||||
BSTART=$(((i-1)*BLOCKSIZE+1))
|
||||
BSTOP=$((i*BLOCKSIZE-1))
|
||||
$TEST $ALGO $BSTART $BSTOP
|
||||
$TEST $ALGO $BSTART $BSTOP $TOLERANCE
|
||||
LAST=$i
|
||||
done
|
||||
LSTART=$((LAST*BLOCKSIZE+1))
|
||||
LSTOP=$((LSTART+LEFT-1))
|
||||
$TEST $ALGO $LSTART $LSTOP
|
||||
$TEST $ALGO $LSTART $LSTOP $TOLERANCE
|
||||
else
|
||||
for ((i=1; i<=$BLOCKS; i++))
|
||||
do
|
||||
BSTART=$(((i-1)*BLOCKSIZE+1))
|
||||
BSTOP=$((i*BLOCKSIZE-1))
|
||||
$TEST $ALGO $BSTART $BSTOP
|
||||
$TEST $ALGO $BSTART $BSTOP $TOLERANCE
|
||||
done
|
||||
fi
|
||||
|
@ -7,7 +7,7 @@
|
||||
#include "SM_Helpers.hpp"
|
||||
|
||||
using namespace H5;
|
||||
// #define DEBUG
|
||||
#define DEBUG
|
||||
|
||||
const H5std_string FILE_NAME( "dataset.hdf5" );
|
||||
|
||||
@ -46,7 +46,7 @@ void read_double(H5File file, std::string key, double * data) {
|
||||
ds.close();
|
||||
}
|
||||
|
||||
int test_cycle(H5File file, int cycle, std::string version) {
|
||||
int test_cycle(H5File file, int cycle, std::string version, double tolerance) {
|
||||
|
||||
/* Read the data */
|
||||
|
||||
@ -71,10 +71,6 @@ int test_cycle(H5File file, int cycle, std::string version) {
|
||||
double * u = new double[nupdates*dim];
|
||||
|
||||
/* Test */
|
||||
#ifdef DEBUG
|
||||
showMatrix(slater_matrix, dim, "OLD Slater");
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
showMatrix(slater_inverse, dim, "OLD Inverse");
|
||||
#endif
|
||||
@ -88,6 +84,16 @@ int test_cycle(H5File file, int cycle, std::string version) {
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
showMatrix(slater_matrix, dim, "OLD Slater");
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG
|
||||
showMatrix(u, dim, "Updates");
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
if (version == "maponia3") {
|
||||
MaponiA3(slater_inverse, dim, nupdates, u, col_update_index);
|
||||
} else if (version == "maponia3s") {
|
||||
@ -113,7 +119,7 @@ int test_cycle(H5File file, int cycle, std::string version) {
|
||||
|
||||
double * res = new double[dim*dim] {0};
|
||||
matMul(slater_matrix, slater_inverse, res, dim);
|
||||
bool ok = is_identity(res, dim, 1e-3);
|
||||
bool ok = is_identity(res, dim, tolerance);
|
||||
|
||||
double res_max = residual_max(res, dim);
|
||||
double res2 = residual2(res, dim);
|
||||
@ -130,19 +136,20 @@ int test_cycle(H5File file, int cycle, std::string version) {
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
if (argc != 4) {
|
||||
if (argc != 5) {
|
||||
std::cerr << "Execute from within 'datasets/'" << std::endl;
|
||||
std::cerr << "usage: test_h5 <version> <start cycle> <stop cycle>" << std::endl;
|
||||
std::cerr << "usage: test_h5 <version> <start cycle> <stop cycle> <tolerance>" << std::endl;
|
||||
return 1;
|
||||
}
|
||||
std::string version(argv[1]);
|
||||
int start_cycle = std::stoi(argv[2]);
|
||||
int stop_cycle = std::stoi(argv[3]);
|
||||
double tolerance = std::stod(argv[4]);
|
||||
H5File file(FILE_NAME, H5F_ACC_RDONLY);
|
||||
|
||||
bool ok;
|
||||
for (int cycle = start_cycle; cycle < stop_cycle+1; cycle++) {
|
||||
ok = test_cycle(file, cycle, version);
|
||||
ok = test_cycle(file, cycle, version, tolerance);
|
||||
if (ok) {
|
||||
std::cerr << "ok -- cycle " << std::to_string(cycle)
|
||||
<< std::endl;
|
||||
|
Loading…
Reference in New Issue
Block a user