Morten Hjorth-Jensen Email morten.hjorth-jensen@fys.uio.no, Department of Physics, University of Oslo and Department of Physics and Astronomy and National Superconducting Cyclotron Laboratory, Michigan State University
Date: Jan 17, 2019
Copyright 1999-2019, Morten Hjorth-Jensen Email morten.hjorth-jensen@fys.uio.no. Released under CC Attribution-NonCommercial 4.0 license
We start with the variational principle. Given a hamiltonian $H$ and a trial wave function $\Psi_T$, the variational principle states that the expectation value of $\langle H \rangle$, defined through
is an upper bound to the ground state energy $E_0$ of the hamiltonian $H$, that is
In general, the integrals involved in the calculation of various expectation values are multi-dimensional ones. Traditional integration methods such as the Gauss-Legendre will not be adequate for say the computation of the energy of a many-body system.
The trial wave function can be expanded in the eigenstates of the hamiltonian since they form a complete set, viz.,
and assuming the set of eigenfunctions to be normalized one obtains
where we used that $H(\boldsymbol{R})\Psi_n(\boldsymbol{R})=E_n\Psi_n(\boldsymbol{R})$. In general, the integrals involved in the calculation of various expectation values are multi-dimensional ones. The variational principle yields the lowest state of a given symmetry.
In most cases, a wave function has only small values in large parts of configuration space, and a straightforward procedure which uses homogenously distributed random points in configuration space will most likely lead to poor results. This may suggest that some kind of importance sampling combined with e.g., the Metropolis algorithm may be a more efficient way of obtaining the ground state energy. The hope is then that those regions of configurations space where the wave function assumes appreciable values are sampled more efficiently.
The tedious part in a VMC calculation is the search for the variational minimum. A good knowledge of the system is required in order to carry out reasonable VMC calculations. This is not always the case, and often VMC calculations serve rather as the starting point for so-called diffusion Monte Carlo calculations (DMC). DMC is a way of solving exactly the many-body Schroedinger equation by means of a stochastic procedure. A good guess on the binding energy and its wave function is however necessary. A carefully performed VMC calculation can aid in this context.
Construct first a trial wave function $\psi_T(\boldsymbol{R},\boldsymbol{\alpha})$, for a many-body system consisting of $N$ particles located at positions $\boldsymbol{R}=(\boldsymbol{R}_1,\dots ,\boldsymbol{R}_N)$. The trial wave function depends on $\alpha$ variational parameters $\boldsymbol{\alpha}=(\alpha_1,\dots ,\alpha_M)$.
Then we evaluate the expectation value of the hamiltonian $H$
This is our new probability distribution function (PDF). The approximation to the expectation value of the Hamiltonian is now
called the local energy, which, together with our trial PDF yields
with $N$ being the number of Monte Carlo samples.
The Algorithm for performing a variational Monte Carlo calculations runs thus as this
Initialisation: Fix the number of Monte Carlo steps. Choose an initial $\boldsymbol{R}$ and variational parameters $\alpha$ and calculate $\left|\psi_T^{\alpha}(\boldsymbol{R})\right|^2$.
Initialise the energy and the variance and start the Monte Carlo calculation.
Calculate a trial position $\boldsymbol{R}_p=\boldsymbol{R}+r*step$ where $r$ is a random variable $r \in [0,1]$.
Metropolis algorithm to accept or reject this move $w = P(\boldsymbol{R}_p)/P(\boldsymbol{R})$.
If the step is accepted, then we set $\boldsymbol{R}=\boldsymbol{R}_p$.
Update averages
Observe that the jumping in space is governed by the variable step. This is Called brute-force sampling. Need importance sampling to get more relevant sampling, see lectures below.
The radial Schroedinger equation for the hydrogen atom can be written as
or with dimensionless variables
with the hamiltonian
Use variational parameter $\alpha$ in the trial wave function
A simple variational Monte Carlo calculation results in
$\alpha$ | $\langle H \rangle $ | $\sigma^2$ | $\sigma/\sqrt{N}$ |
---|---|---|---|
7.00000E-01 | -4.57759E-01 | 4.51201E-02 | 6.71715E-04 |
8.00000E-01 | -4.81461E-01 | 3.05736E-02 | 5.52934E-04 |
9.00000E-01 | -4.95899E-01 | 8.20497E-03 | 2.86443E-04 |
1.00000E-00 | -5.00000E-01 | 0.00000E+00 | 0.00000E+00 |
1.10000E+00 | -4.93738E-01 | 1.16989E-02 | 3.42036E-04 |
1.20000E+00 | -4.75563E-01 | 8.85899E-02 | 9.41222E-04 |
1.30000E+00 | -4.54341E-01 | 1.45171E-01 | 1.20487E-03 |
We note that at $\alpha=1$ we obtain the exact result, and the variance is zero, as it should. The reason is that we then have the exact wave function, and the action of the hamiltionan on the wave function
yields just a constant. The integral which defines various expectation values involving moments of the hamiltonian becomes then
This gives an important information: the exact wave function leads to zero variance! Variation is then performed by minimizing both the energy and the variance.
For bosons in a harmonic oscillator-like trap we will use is a spherical (S) or an elliptical (E) harmonic trap in one, two and finally three dimensions, with the latter given by
where (S) stands for symmetric and
as the two-body Hamiltonian of the system.
We will represent the inter-boson interaction by a pairwise, repulsive potential
where $a$ is the so-called hard-core diameter of the bosons. Clearly, $V_{int}(|\mathbf{r}_i-\mathbf{r}_j|)$ is zero if the bosons are separated by a distance $|\mathbf{r}_i-\mathbf{r}_j|$ greater than $a$ but infinite if they attempt to come within a distance $|\mathbf{r}_i-\mathbf{r}_j| \leq a$.
Our trial wave function for the ground state with $N$ atoms is given by
where $\alpha$ and $\beta$ are variational parameters. The single-particle wave function is proportional to the harmonic oscillator function for the ground state
For spherical traps we have $\beta = 1$ and for non-interacting bosons ($a=0$) we have $\alpha = 1/2a_{ho}^2$. The correlation wave function is
In [1]:
%matplotlib inline
# Importing various packages
from math import exp, sqrt
from random import random, seed
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
import sys
#Trial wave function for quantum dots in two dims
def WaveFunction(r,alpha,beta):
r1 = r[0,0]**2 + r[0,1]**2
r2 = r[1,0]**2 + r[1,1]**2
r12 = sqrt((r[0,0]-r[1,0])**2 + (r[0,1]-r[1,1])**2)
deno = r12/(1+beta*r12)
return exp(-0.5*alpha*(r1+r2)+deno)
#Local energy for quantum dots in two dims, using analytical local energy
def LocalEnergy(r,alpha,beta):
r1 = (r[0,0]**2 + r[0,1]**2)
r2 = (r[1,0]**2 + r[1,1]**2)
r12 = sqrt((r[0,0]-r[1,0])**2 + (r[0,1]-r[1,1])**2)
deno = 1.0/(1+beta*r12)
deno2 = deno*deno
return 0.5*(1-alpha*alpha)*(r1 + r2) +2.0*alpha + 1.0/r12+deno2*(alpha*r12-deno2+2*beta*deno-1.0/r12)
# The Monte Carlo sampling with the Metropolis algo
def MonteCarloSampling():
NumberMCcycles= 100000
StepSize = 1.0
# positions
PositionOld = np.zeros((NumberParticles,Dimension), np.double)
PositionNew = np.zeros((NumberParticles,Dimension), np.double)
# seed for rng generator
seed()
# start variational parameter
alpha = 0.9
for ia in range(MaxVariations):
alpha += .025
AlphaValues[ia] = alpha
beta = 0.2
for jb in range(MaxVariations):
beta += .01
BetaValues[jb] = beta
energy = energy2 = 0.0
DeltaE = 0.0
#Initial position
for i in range(NumberParticles):
for j in range(Dimension):
PositionOld[i,j] = StepSize * (random() - .5)
wfold = WaveFunction(PositionOld,alpha,beta)
#Loop over MC MCcycles
for MCcycle in range(NumberMCcycles):
#Trial position
for i in range(NumberParticles):
for j in range(Dimension):
PositionNew[i,j] = PositionOld[i,j] + StepSize * (random() - .5)
wfnew = WaveFunction(PositionNew,alpha,beta)
#Metropolis test to see whether we accept the move
if random() < wfnew**2 / wfold**2:
PositionOld = PositionNew.copy()
wfold = wfnew
DeltaE = LocalEnergy(PositionOld,alpha,beta)
energy += DeltaE
energy2 += DeltaE**2
#We calculate mean, variance and error ...
energy /= NumberMCcycles
energy2 /= NumberMCcycles
variance = energy2 - energy**2
error = sqrt(variance/NumberMCcycles)
Energies[ia,jb] = energy
return Energies, AlphaValues, BetaValues
#Here starts the main program with variable declarations
NumberParticles = 2
Dimension = 2
MaxVariations = 10
Energies = np.zeros((MaxVariations,MaxVariations))
AlphaValues = np.zeros(MaxVariations)
BetaValues = np.zeros(MaxVariations)
(Energies, AlphaValues, BetaValues) = MonteCarloSampling()
# Prepare for plots
fig = plt.figure()
ax = fig.gca(projection='3d')
# Plot the surface.
X, Y = np.meshgrid(AlphaValues, BetaValues)
surf = ax.plot_surface(X, Y, Energies,cmap=cm.coolwarm,linewidth=0, antialiased=False)
# Customize the z axis.
zmin = np.matrix(Energies).min()
zmax = np.matrix(Energies).max()
ax.set_zlim(zmin, zmax)
ax.set_xlabel(r'$\alpha$')
ax.set_ylabel(r'$\beta$')
ax.set_zlabel(r'$\langle E \rangle$')
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()
and if we add the repulsion arising from the two interacting electrons, we obtain the potential energy
and Schroedingers equation reads
All observables are evaluated with respect to the probability distribution
2 7
< < < ! ! M A T H _ B L O C K
For small values of $r_1$, the terms which dominate are
and
A similar condition applies to electron 2 as well. For orbital momenta $l > 0$ we have
Similarly, studying the case $r_{12}\rightarrow 0$ we can write a possible trial wave function as
The last equation can be generalized to
for a system with $N$ electrons or particles.
During the development of our code we need to make several checks. It is also very instructive to compute a closed form expression for the local energy. Since our wave function is rather simple it is straightforward to find an analytic expressions. Consider first the case of the simple helium function
The local energy is for this case
which gives an expectation value for the local energy given by
which means that the gradient needed for the so-called quantum force and local energy can be calculated analytically. This will speed up your code since the computation of the correlation part and the Slater determinant are the most time consuming parts in your code.
We will refer to this correlation function as $\Psi_C$ or the linear Pade-Jastrow.
We can test this by computing the local energy for our helium wave function
with $\alpha$ and $\beta$ as variational parameters.
The local energy is for this case
It is very useful to test your code against these expressions. It means also that you don't need to compute a derivative numerically as discussed in the code example below.
For the computation of various derivatives with different types of wave functions, you will find it useful to use python with symbolic python, that is sympy, see online manual. Using sympy allows you autogenerate both Latex code as well c++, python or Fortran codes. Here you will find some simple examples. We choose the $2s$ hydrogen-orbital (not normalized) as an example
with $ r^2 = x^2 + y^2 + z^2$.
In [2]:
from sympy import symbols, diff, exp, sqrt
x, y, z, Z = symbols('x y z Z')
r = sqrt(x*x + y*y + z*z)
r
phi = (Z*r - 2)*exp(-Z*r/2)
phi
diff(phi, x)
In [3]:
from sympy import symbols, diff, exp, sqrt, factor, Symbol, printing
x, y, z, Z = symbols('x y z Z')
r = sqrt(x*x + y*y + z*z)
phi = (Z*r - 2)*exp(-Z*r/2)
R = Symbol('r') #Creates a symbolic equivalent of r
#print latex and c++ code
print printing.latex(diff(phi, x).factor().subs(r, R))
print printing.ccode(diff(phi, x).factor().subs(r, R))
In [4]:
from sympy import symbols, diff, exp, sqrt, factor, Symbol, printing
x, y, z, Z = symbols('x y z Z')
r = sqrt(x*x + y*y + z*z)
phi = (Z*r - 2)*exp(-Z*r/2)
R = Symbol('r') #Creates a symbolic equivalent of r
(diff(diff(phi, x), x) + diff(diff(phi, y), y) + diff(diff(phi, z), z)).factor().subs(r, R)
# Collect the Z values
(diff(diff(phi, x), x) + diff(diff(phi, y), y) +diff(diff(phi, z), z)).factor().collect(Z).subs(r, R)
# Factorize also the r**2 terms
(diff(diff(phi, x), x) + diff(diff(phi, y), y) + diff(diff(phi, z), z)).factor().collect(Z).subs(r, R).subs(r**2, R**2).factor()
print printing.ccode((diff(diff(phi, x), x) + diff(diff(phi, y), y) + diff(diff(phi, z), z)).factor().collect(Z).subs(r, R).subs(r**2, R**2).factor())
#include "vmcsolver.h"
#include <iostream>
using namespace std;
int main()
{
VMCSolver *solver = new VMCSolver();
solver->runMonteCarloIntegration();
return 0;
}
#ifndef VMCSOLVER_H
#define VMCSOLVER_H
#include <armadillo>
using namespace arma;
class VMCSolver
{
public:
VMCSolver();
void runMonteCarloIntegration();
private:
double waveFunction(const mat &r);
double localEnergy(const mat &r);
int nDimensions;
int charge;
double stepLength;
int nParticles;
double h;
double h2;
long idum;
double alpha;
int nCycles;
mat rOld;
mat rNew;
};
#endif // VMCSOLVER_H
#include "vmcsolver.h"
#include "lib.h"
#include <armadillo>
#include <iostream>
using namespace arma;
using namespace std;
VMCSolver::VMCSolver() :
nDimensions(3),
charge(2),
stepLength(1.0),
nParticles(2),
h(0.001),
h2(1000000),
idum(-1),
alpha(0.5*charge),
nCycles(1000000)
{
}
void VMCSolver::runMonteCarloIntegration()
{
rOld = zeros<mat>(nParticles, nDimensions);
rNew = zeros<mat>(nParticles, nDimensions);
double waveFunctionOld = 0;
double waveFunctionNew = 0;
double energySum = 0;
double energySquaredSum = 0;
double deltaE;
// initial trial positions
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rOld(i,j) = stepLength * (ran2(&idum) - 0.5);
}
}
rNew = rOld;
// loop over Monte Carlo cycles
for(int cycle = 0; cycle < nCycles; cycle++) {
// Store the current value of the wave function
waveFunctionOld = waveFunction(rOld);
// New position to test
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rNew(i,j) = rOld(i,j) + stepLength*(ran2(&idum) - 0.5);
}
// Recalculate the value of the wave function
waveFunctionNew = waveFunction(rNew);
// Check for step acceptance (if yes, update position, if no, reset position)
if(ran2(&idum) <= (waveFunctionNew*waveFunctionNew) / (waveFunctionOld*waveFunctionOld)) {
for(int j = 0; j < nDimensions; j++) {
rOld(i,j) = rNew(i,j);
waveFunctionOld = waveFunctionNew;
}
} else {
for(int j = 0; j < nDimensions; j++) {
rNew(i,j) = rOld(i,j);
}
}
// update energies
deltaE = localEnergy(rNew);
energySum += deltaE;
energySquaredSum += deltaE*deltaE;
}
}
double energy = energySum/(nCycles * nParticles);
double energySquared = energySquaredSum/(nCycles * nParticles);
cout << "Energy: " << energy << " Energy (squared sum): " << energySquared << endl;
}
double VMCSolver::localEnergy(const mat &r)
{
mat rPlus = zeros<mat>(nParticles, nDimensions);
mat rMinus = zeros<mat>(nParticles, nDimensions);
rPlus = rMinus = r;
double waveFunctionMinus = 0;
double waveFunctionPlus = 0;
double waveFunctionCurrent = waveFunction(r);
// Kinetic energy, brute force derivations
double kineticEnergy = 0;
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rPlus(i,j) += h;
rMinus(i,j) -= h;
waveFunctionMinus = waveFunction(rMinus);
waveFunctionPlus = waveFunction(rPlus);
kineticEnergy -= (waveFunctionMinus + waveFunctionPlus - 2 * waveFunctionCurrent);
rPlus(i,j) = r(i,j);
rMinus(i,j) = r(i,j);
}
}
kineticEnergy = 0.5 * h2 * kineticEnergy / waveFunctionCurrent;
// Potential energy
double potentialEnergy = 0;
double rSingleParticle = 0;
for(int i = 0; i < nParticles; i++) {
rSingleParticle = 0;
for(int j = 0; j < nDimensions; j++) {
rSingleParticle += r(i,j)*r(i,j);
}
potentialEnergy -= charge / sqrt(rSingleParticle);
}
// Contribution from electron-electron potential
double r12 = 0;
for(int i = 0; i < nParticles; i++) {
for(int j = i + 1; j < nParticles; j++) {
r12 = 0;
for(int k = 0; k < nDimensions; k++) {
r12 += (r(i,k) - r(j,k)) * (r(i,k) - r(j,k));
}
potentialEnergy += 1 / sqrt(r12);
}
}
return kineticEnergy + potentialEnergy;
}
double VMCSolver::waveFunction(const mat &r)
{
double argument = 0;
for(int i = 0; i < nParticles; i++) {
double rSingleParticle = 0;
for(int j = 0; j < nDimensions; j++) {
rSingleParticle += r(i,j) * r(i,j);
}
argument += sqrt(rSingleParticle);
}
return exp(-argument * alpha);
}
#include <armadillo>
#include <iostream>
using namespace arma;
using namespace std;
double ran2(long *);
class VMCSolver
{
public:
VMCSolver();
void runMonteCarloIntegration();
private:
double waveFunction(const mat &r);
double localEnergy(const mat &r);
int nDimensions;
int charge;
double stepLength;
int nParticles;
double h;
double h2;
long idum;
double alpha;
int nCycles;
mat rOld;
mat rNew;
};
VMCSolver::VMCSolver() :
nDimensions(3),
charge(2),
stepLength(1.0),
nParticles(2),
h(0.001),
h2(1000000),
idum(-1),
alpha(0.5*charge),
nCycles(1000000)
{
}
void VMCSolver::runMonteCarloIntegration()
{
rOld = zeros<mat>(nParticles, nDimensions);
rNew = zeros<mat>(nParticles, nDimensions);
double waveFunctionOld = 0;
double waveFunctionNew = 0;
double energySum = 0;
double energySquaredSum = 0;
double deltaE;
// initial trial positions
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rOld(i,j) = stepLength * (ran2(&idum) - 0.5);
}
}
rNew = rOld;
// loop over Monte Carlo cycles
for(int cycle = 0; cycle < nCycles; cycle++) {
// Store the current value of the wave function
waveFunctionOld = waveFunction(rOld);
// New position to test
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rNew(i,j) = rOld(i,j) + stepLength*(ran2(&idum) - 0.5);
}
// Recalculate the value of the wave function
waveFunctionNew = waveFunction(rNew);
// Check for step acceptance (if yes, update position, if no, reset position)
if(ran2(&idum) <= (waveFunctionNew*waveFunctionNew) / (waveFunctionOld*waveFunctionOld)) {
for(int j = 0; j < nDimensions; j++) {
rOld(i,j) = rNew(i,j);
waveFunctionOld = waveFunctionNew;
}
} else {
for(int j = 0; j < nDimensions; j++) {
rNew(i,j) = rOld(i,j);
}
}
// update energies
deltaE = localEnergy(rNew);
energySum += deltaE;
energySquaredSum += deltaE*deltaE;
}
}
double energy = energySum/(nCycles * nParticles);
double energySquared = energySquaredSum/(nCycles * nParticles);
cout << "Energy: " << energy << " Energy (squared sum): " << energySquared << endl;
}
double VMCSolver::localEnergy(const mat &r)
{
mat rPlus = zeros<mat>(nParticles, nDimensions);
mat rMinus = zeros<mat>(nParticles, nDimensions);
rPlus = rMinus = r;
double waveFunctionMinus = 0;
double waveFunctionPlus = 0;
double waveFunctionCurrent = waveFunction(r);
// Kinetic energy, brute force derivations
double kineticEnergy = 0;
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rPlus(i,j) += h;
rMinus(i,j) -= h;
waveFunctionMinus = waveFunction(rMinus);
waveFunctionPlus = waveFunction(rPlus);
kineticEnergy -= (waveFunctionMinus + waveFunctionPlus - 2 * waveFunctionCurrent);
rPlus(i,j) = r(i,j);
rMinus(i,j) = r(i,j);
}
}
kineticEnergy = 0.5 * h2 * kineticEnergy / waveFunctionCurrent;
// Potential energy
double potentialEnergy = 0;
double rSingleParticle = 0;
for(int i = 0; i < nParticles; i++) {
rSingleParticle = 0;
for(int j = 0; j < nDimensions; j++) {
rSingleParticle += r(i,j)*r(i,j);
}
potentialEnergy -= charge / sqrt(rSingleParticle);
}
// Contribution from electron-electron potential
double r12 = 0;
for(int i = 0; i < nParticles; i++) {
for(int j = i + 1; j < nParticles; j++) {
r12 = 0;
for(int k = 0; k < nDimensions; k++) {
r12 += (r(i,k) - r(j,k)) * (r(i,k) - r(j,k));
}
potentialEnergy += 1 / sqrt(r12);
}
}
return kineticEnergy + potentialEnergy;
}
double VMCSolver::waveFunction(const mat &r)
{
double argument = 0;
for(int i = 0; i < nParticles; i++) {
double rSingleParticle = 0;
for(int j = 0; j < nDimensions; j++) {
rSingleParticle += r(i,j) * r(i,j);
}
argument += sqrt(rSingleParticle);
}
return exp(-argument * alpha);
}
/*
** The function
** ran2()
** is a long periode (> 2 x 10^18) random number generator of
** L'Ecuyer and Bays-Durham shuffle and added safeguards.
** Call with idum a negative integer to initialize; thereafter,
** do not alter idum between sucessive deviates in a
** sequence. RNMX should approximate the largest floating point value
** that is less than 1.
** The function returns a uniform deviate between 0.0 and 1.0
** (exclusive of end-point values).
*/
#define IM1 2147483563
#define IM2 2147483399
#define AM (1.0/IM1)
#define IMM1 (IM1-1)
#define IA1 40014
#define IA2 40692
#define IQ1 53668
#define IQ2 52774
#define IR1 12211
#define IR2 3791
#define NTAB 32
#define NDIV (1+IMM1/NTAB)
#define EPS 1.2e-7
#define RNMX (1.0-EPS)
double ran2(long *idum)
{
int j;
long k;
static long idum2 = 123456789;
static long iy=0;
static long iv[NTAB];
double temp;
if(*idum <= 0) {
if(-(*idum) < 1) *idum = 1;
else *idum = -(*idum);
idum2 = (*idum);
for(j = NTAB + 7; j >= 0; j--) {
k = (*idum)/IQ1;
*idum = IA1*(*idum - k*IQ1) - k*IR1;
if(*idum < 0) *idum += IM1;
if(j < NTAB) iv[j] = *idum;
}
iy=iv[0];
}
k = (*idum)/IQ1;
*idum = IA1*(*idum - k*IQ1) - k*IR1;
if(*idum < 0) *idum += IM1;
k = idum2/IQ2;
idum2 = IA2*(idum2 - k*IQ2) - k*IR2;
if(idum2 < 0) idum2 += IM2;
j = iy/NDIV;
iy = iv[j] - idum2;
iv[j] = *idum;
if(iy < 1) iy += IMM1;
if((temp = AM*iy) > RNMX) return RNMX;
else return temp;
}
#undef IM1
#undef IM2
#undef AM
#undef IMM1
#undef IA1
#undef IA2
#undef IQ1
#undef IQ2
#undef IR1
#undef IR2
#undef NTAB
#undef NDIV
#undef EPS
#undef RNMX
// End: function ran2()
#include <iostream>
using namespace std;
int main()
{
VMCSolver *solver = new VMCSolver();
solver->runMonteCarloIntegration();
return 0;
}
The Metropolis algorithm , see the original article was invented by Metropolis et. al and is often simply called the Metropolis algorithm. It is a method to sample a normalized probability distribution by a stochastic process. We define $\mathbf{P}_i^{(n)}$ to be the probability for finding the system in the state $i$ at step $n$. The algorithm is then
Sample a possible new state $j$ with some probability $T_{i\rightarrow j}$.
Accept the new state $j$ with probability $A_{i \rightarrow j}$ and use it as the next sample. With probability $1-A_{i\rightarrow j}$ the move is rejected and the original state $i$ is used again as a sample.
We wish to derive the required properties of $T$ and $A$ such that $\mathbf{P}_i^{(n\rightarrow \infty)} \rightarrow p_i$ so that starting from any distribution, the method converges to the correct distribution. Note that the description here is for a discrete probability distribution. Replacing probabilities $p_i$ with expressions like $p(x_i)dx_i$ will take all of these over to the corresponding continuum expressions.
The dynamical equation for $\mathbf{P}_i^{(n)}$ can be written directly from the description above. The probability of being in the state $i$ at step $n$ is given by the probability of being in any state $j$ at the previous step, and making an accepted transition to $i$ added to the probability of being in the state $i$, making a transition to any state $j$ and rejecting the move:
Since the probability of making some transition must be 1, $\sum_j T_{i\rightarrow j} = 1$, and the above equation becomes
The balance requirement is very weak. Typically the much stronger detailed balance requirement is enforced, that is rather than the sum being set to zero, we set each term separately to zero and use this to determine the acceptance probabilities. Rearranging, the result is
Other choices are possible, but they all correspond to multilplying $A_{i\rightarrow j}$ and $A_{j\rightarrow i}$ by the same constant smaller than unity.\footnote{The penalty function method uses just such a factor to compensate for $p_i$ that are evaluated stochastically and are therefore noisy.}
Having chosen the acceptance probabilities, we have guaranteed that if the $\mathbf{P}_i^{(n)}$ has equilibrated, that is if it is equal to $p_i$, it will remain equilibrated. Next we need to find the circumstances for convergence to equilibrium.
The dynamical equation can be written as
with the matrix $M$ given by
Summing over $i$ shows that $\sum_i M_{ij} = 1$, and since $\sum_k T_{i\rightarrow k} = 1$, and $A_{i \rightarrow k} \leq 1$, the elements of the matrix satisfy $M_{ij} \geq 0$. The matrix $M$ is therefore a stochastic matrix.
The Metropolis method is simply the power method for computing the right eigenvector of $M$ with the largest magnitude eigenvalue. By construction, the correct probability distribution is a right eigenvector with eigenvalue 1. Therefore, for the Metropolis method to converge to this result, we must show that $M$ has only one eigenvalue with this magnitude, and all other eigenvalues are smaller.
We need to replace the brute force Metropolis algorithm with a walk in coordinate space biased by the trial wave function. This approach is based on the Fokker-Planck equation and the Langevin equation for generating a trajectory in coordinate space. The link between the Fokker-Planck equation and the Langevin equations are explained, only partly, in the slides below. An excellent reference on topics like Brownian motion, Markov chains, the Fokker-Planck equation and the Langevin equation is the text by Van Kampen Here we will focus first on the implementation part first.
For a diffusion process characterized by a time-dependent probability density $P(x,t)$ in one dimension the Fokker-Planck equation reads (for one particle /walker)
with $\eta$ a random variable, yielding a new position
where $\xi$ is gaussian random variable and $\Delta t$ is a chosen time step. The quantity $D$ is, in atomic units, equal to $1/2$ and comes from the factor $1/2$ in the kinetic energy operator. Note that $\Delta t$ is to be viewed as a parameter. Values of $\Delta t \in [0.001,0.01]$ yield in general rather stable values of the ground state energy.
The process of isotropic diffusion characterized by a time-dependent probability density $P(\mathbf{x},t)$ obeys (as an approximation) the so-called Fokker-Planck equation
where $\mathbf{F_i}$ is the $i^{th}$ component of the drift term (drift velocity) caused by an external potential, and $D$ is the diffusion coefficient. The convergence to a stationary probability density can be obtained by setting the left hand side to zero. The resulting equation will be satisfied if and only if all the terms of the sum are equal zero,
The condition of stationary density means that the left hand side equals zero. In other words, the terms containing first and second derivatives have to cancel each other. It is possible only if $g = \frac{1}{P}$, which yields
which is known as the so-called quantum force. This term is responsible for pushing the walker towards regions of configuration space where the trial wave function is large, increasing the efficiency of the simulation in contrast to the Metropolis algorithm where the walker has the same probability of moving in every direction.
The Fokker-Planck equation yields a (the solution to the equation) transition probability given by the Green's function
which in turn means that our brute force Metropolis algorithm
with $q(y,x) = |\Psi_T(y)|^2/|\Psi_T(x)|^2$ is now replaced by the Metropolis-Hastings algorithm as well as Hasting's article,
The full code is this link. Here we include only the parts pertaining to the computation of the quantum force and the Metropolis update. The program is a modfication of our previous c++ program discussed previously. Here we display only the part from the vmcsolver.cpp file. Note the usage of the function GaussianDeviate.
void VMCSolver::runMonteCarloIntegration()
{
rOld = zeros<mat>(nParticles, nDimensions);
rNew = zeros<mat>(nParticles, nDimensions);
QForceOld = zeros<mat>(nParticles, nDimensions);
QForceNew = zeros<mat>(nParticles, nDimensions);
double waveFunctionOld = 0;
double waveFunctionNew = 0;
double energySum = 0;
double energySquaredSum = 0;
double deltaE;
// initial trial positions
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rOld(i,j) = GaussianDeviate(&idum)*sqrt(timestep);
}
}
rNew = rOld;
for(int cycle = 0; cycle < nCycles; cycle++) {
// Store the current value of the wave function
waveFunctionOld = waveFunction(rOld);
QuantumForce(rOld, QForceOld); QForceOld = QForceOld*h/waveFunctionOld;
// New position to test
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rNew(i,j) = rOld(i,j) + GaussianDeviate(&idum)*sqrt(timestep)+QForceOld(i,j)*timestep*D;
}
// for the other particles we need to set the position to the old position since
// we move only one particle at the time
for (int k = 0; k < nParticles; k++) {
if ( k != i) {
for (int j=0; j < nDimensions; j++) {
rNew(k,j) = rOld(k,j);
}
}
}
// loop over Monte Carlo cycles
// Recalculate the value of the wave function and the quantum force
waveFunctionNew = waveFunction(rNew);
QuantumForce(rNew,QForceNew) = QForceNew*h/waveFunctionNew;
// we compute the log of the ratio of the greens functions to be used in the
// Metropolis-Hastings algorithm
GreensFunction = 0.0;
for (int j=0; j < nDimensions; j++) {
GreensFunction += 0.5*(QForceOld(i,j)+QForceNew(i,j))*
(D*timestep*0.5*(QForceOld(i,j)-QForceNew(i,j))-rNew(i,j)+rOld(i,j));
}
GreensFunction = exp(GreensFunction);
// The Metropolis test is performed by moving one particle at the time
if(ran2(&idum) <= GreensFunction*(waveFunctionNew*waveFunctionNew) / (waveFunctionOld*waveFunctionOld)) {
for(int j = 0; j < nDimensions; j++) {
rOld(i,j) = rNew(i,j);
QForceOld(i,j) = QForceNew(i,j);
waveFunctionOld = waveFunctionNew;
}
} else {
for(int j = 0; j < nDimensions; j++) {
rNew(i,j) = rOld(i,j);
QForceNew(i,j) = QForceOld(i,j);
}
}
double VMCSolver::QuantumForce(const mat &r, mat &QForce)
{
mat rPlus = zeros<mat>(nParticles, nDimensions);
mat rMinus = zeros<mat>(nParticles, nDimensions);
rPlus = rMinus = r;
double waveFunctionMinus = 0;
double waveFunctionPlus = 0;
double waveFunctionCurrent = waveFunction(r);
// Kinetic energy
double kineticEnergy = 0;
for(int i = 0; i < nParticles; i++) {
for(int j = 0; j < nDimensions; j++) {
rPlus(i,j) += h;
rMinus(i,j) -= h;
waveFunctionMinus = waveFunction(rMinus);
waveFunctionPlus = waveFunction(rPlus);
QForce(i,j) = (waveFunctionPlus-waveFunctionMinus);
rPlus(i,j) = r(i,j);
rMinus(i,j) = r(i,j);
}
}
}
However, with our written in way which can be reused later as
the gradient needed for the quantum force and local energy is easy to compute.
The function $f(r_{ij})$ will depends on the system under study. In the equations below we will keep this general form.
In the Metropolis/Hasting algorithm, the acceptance ratio determines the probability for a particle to be accepted at a new position. The ratio of the trial wave functions evaluated at the new and current positions is given by ($OB$ for the onebody part)
Here $\Psi_{OB}$ is our onebody part (Slater determinant or product of boson single-particle states) while $\Psi_{C}$ is our correlation function, or Jastrow factor. We need to optimize the $\nabla \Psi_T / \Psi_T$ ratio and the second derivative as well, that is the $\mathbf{\nabla}^2 \Psi_T/\Psi_T$ ratio. The first is needed when we compute the so-called quantum force in importance sampling. The second is needed when we compute the kinetic energy term of the local energy.
6 3
< < < ! ! M A T H _ B L O C K
with $r_{ij}=|\mathbf{r}_i-\mathbf{r}_j|=\sqrt{(x_i-x_j)^2+(y_i-y_j)^2+(z_i-z_j)^2}$ in three dimensions or $r_{ij}=|\mathbf{r}_i-\mathbf{r}_j|=\sqrt{(x_i-x_j)^2+(y_i-y_j)^2}$ if we work with two-dimensional systems.
In our particular case we have
This applies to $\mathbf{g} = \mathbf{g}(r_{ij})$ as well.
In our algorithm we will move one particle at the time, say the $kth$-particle. This sampling will be seen to be particularly efficient when we are going to compute a Slater determinant.
We have that the ratio between Jastrow factors $R_C$ is given by
For the Pade-Jastrow form
where
An equivalent equation is obtained for the exponential form after replacing $g_{ij}$ by $\exp(f_{ij})$, yielding:
we get expressions where all the derivatives acting on the particle are represented by the second index of $g$:
and for the exponential case:
we arrive at
Therefore,
where
and it is easy to see that for particle $k$ we have
// Initialize the seed and call the Mersienne algo
std::random_device rd;
std::mt19937_64 gen(rd());
// Set up the uniform distribution for x \in [[0, 1]
std::uniform_real_distribution<double> UniformNumberGenerator(0.0,1.0);
std::normal_distribution<double> Normaldistribution(0.0,1.0);
for (int cycles = 1; cycles <= NumberMCsamples; cycles++){
// new position
for (int i = 0; i < NumberParticles; i++) {
for (int j = 0; j < Dimension; j++) {
// gaussian deviate to compute new positions using a given timestep
NewPosition(i,j) = OldPosition(i,j) + Normaldistribution(gen)*sqrt(timestep)+OldQuantumForce(i,j)*timestep*D;
}
// Metropolis-Hastings algorithm
double GreensFunction = 0.0;
for (int j = 0; j < Dimension; j++) {
GreensFunction += 0.5*(OldQuantumForce(i,j)+NewQuantumForce(i,j))*
(D*timestep*0.5*(OldQuantumForce(i,j)-NewQuantumForce(i,j))-NewPosition(i,j)+OldPosition(i,j));
}
GreensFunction = exp(GreensFunction);
// The Metropolis test is performed by moving one particle at the time
if(UniformNumberGenerator(gen) <= GreensFunction*NewWaveFunction*NewWaveFunction/OldWaveFunction/OldWaveFunction ) {
for (int j = 0; j < Dimension; j++) {
OldPosition(i,j) = NewPosition(i,j);
OldQuantumForce(i,j) = NewQuantumForce(i,j);
}
OldWaveFunction = NewWaveFunction;
}
A stochastic process is simply a function of two variables, one is the time, the other is a stochastic variable $X$, defined by specifying
the set $\left\{x\right\}$ of possible values for $X$;
the probability distribution, $w_X(x)$, over this set, or briefly $w(x)$
The set of values $\left\{x\right\}$ for $X$ may be discrete, or continuous. If the set of values is continuous, then $w_X (x)$ is a probability density so that $w_X (x)dx$ is the probability that one finds the stochastic variable $X$ to have values in the range $[x, x + dx]$ .
An arbitrary number of other stochastic variables may be derived from
$X$. For example, any $Y$ given by a mapping of $X$, is also a stochastic variable. The mapping may also be time-dependent, that is, the mapping depends on an additional variable $t$
The quantity $Y_X (t)$ is called a random function, or, since $t$ often is time, a stochastic process. A stochastic process is a function of two variables, one is the time, the other is a stochastic variable $X$. Let $x$ be one of the possible values of $X$ then
is a function of $t$, called a sample function or realization of the process. In physics one considers the stochastic process to be an ensemble of such sample functions.
For many physical systems initial distributions of a stochastic
variable $y$ tend to equilibrium distributions: $w(y, t)\rightarrow w_0(y)$ as $t\rightarrow\infty$. In equilibrium detailed balance constrains the transition rates
where $W(y'\rightarrow y)$ is the probability, per unit time, that the system changes from a state $|y\rangle$ , characterized by the value $y$ for the stochastic variable $Y$ , to a state $|y'\rangle$.
Note that for a system in equilibrium the transition rate $W(y'\rightarrow y)$ and the reverse $W(y\rightarrow y')$ may be very different.
Consider, for instance, a simple system that has only two energy levels $\epsilon_0 = 0$ and $\epsilon_1 = \Delta E$.
For a system governed by the Boltzmann distribution we find (the partition function has been taken out)
We get then
and its time-development after a given time step $\Delta t=\epsilon$ is
The continuous analog to $w_i(0)$ is
where we now have generalized the one-dimensional position $x$ to a generic-dimensional
vector $\mathbf{x}$. The Kroenecker $\delta$ function is replaced by the $\delta$ distribution
function $\delta(\mathbf{x})$ at $t=0$.
The transition from a state $j$ to a state $i$ is now replaced by a transition to a state with position $\mathbf{y}$ from a state with position $\mathbf{x}$. The discrete sum of transition probabilities can then be replaced by an integral and we obtain the new distribution at a time $t+\Delta t$ as
and after $m$ time steps we have
When equilibrium is reached we have
that is no time-dependence. Note our change of notation for $W$
We can solve the equation for $w(\mathbf{y},t)$ by making a Fourier transform to momentum space. The PDF $w(\mathbf{x},t)$ is related to its Fourier transform $\tilde{w}(\mathbf{k},t)$ through
and using the definition of the $\delta$-function
we see that
with the obvious solution
with the normalization condition
The solution represents the probability of finding our random walker at position $\mathbf{x}$ at time $t$ if the initial distribution was placed at $\mathbf{x}=0$ at $t=0$.
There is another interesting feature worth observing. The discrete transition probability $W$ itself is given by a binomial distribution. The results from the central limit theorem state that transition probability in the limit $n\rightarrow \infty$ converges to the normal distribution. It is then possible to show that
and that it satisfies the normalization condition and is itself a solution to the diffusion equation.
Let us now assume that we have three PDFs for times $t_0 < t' < t$, that is $w(\mathbf{x}_0,t_0)$, $w(\mathbf{x}',t')$ and $w(\mathbf{x},t)$. We have then
and
and
We can replace the spatial dependence with a dependence upon say the velocity (or momentum), that is we have
Define $s=t'-t_0$, $\tau=t-t'$ and $t-t_0=s+\tau$. We have then
We assume that $W(\mathbf{x},\tau|\mathbf{x}-\xi)$ takes non-negligible values only when $\xi$ is small. This is just another way of stating the Master equation!!
We say thus that $\mathbf{x}$ changes only by a small amount in the time interval $\tau$. This means that we can make a Taylor expansion in terms of $\xi$, that is we expand
We have neglected higher powers of $\tau$ and have used that for $n=0$ we get simply $W(\mathbf{x},s|\mathbf{x}_0)$ due to normalization.
We say thus that $\mathbf{x}$ changes only by a small amount in the time interval $\tau$. This means that we can make a Taylor expansion in terms of $\xi$, that is we expand
resulting in
When $\tau \rightarrow 0$ we assume that $\langle [\Delta x(\tau)]^n\rangle \rightarrow 0$ more rapidly than $\tau$ itself if $n > 2$. When $\tau$ is much larger than the standard correlation time of system then $M_n$ for $n > 2$ can normally be neglected. This means that fluctuations become negligible at large time scales.
If we neglect such terms we can rewrite the ESKC equation as
which is the Fokker-Planck equation! It is trivial to replace position with velocity (momentum).
Langevin equation.
Consider a particle suspended in a liquid. On its path through the liquid it will continuously collide with the liquid molecules. Because on average the particle will collide more often on the front side than on the back side, it will experience a systematic force proportional with its velocity, and directed opposite to its velocity. Besides this systematic force the particle will experience a stochastic force $\mathbf{F}(t)$. The equations of motion are
$\frac{d\mathbf{r}}{dt}=\mathbf{v}$ and
$\frac{d\mathbf{v}}{dt}=-\xi \mathbf{v}+\mathbf{F}$.
Langevin equation.
From hydrodynamics we know that the friction constant $\xi$ is given by
where $\eta$ is the viscosity of the solvent and a is the radius of the particle .
Solving the second equation in the previous slide we get
1 2 3
< < < ! ! M A T H _ B L O C K
and
We omit the subscript $\mathbf{v}_{0}$, when the quantity of interest turns out to be independent of $\mathbf{v}_{0}$. Using the last three equations we get
For large t this should be equal to 3kT/m, from which it follows that
we get
from which we calculate the mean square displacement
from which we get the Einstein relation
where we have used $\langle (\mathbf{r}(t)-\mathbf{r}_{0})^{2}\rangle =6Dt$.
Statistical analysis.
* Monte Carlo simulations can be treated as *computer experiments*
* The results can be analysed with the same statistical tools as we would use analysing experimental data.
* As in all experiments, we are looking for expectation values and an estimate of how accurate they are, i.e., possible sources for errors.
A very good article which explains blocking is H. Flyvbjerg and H. G. Petersen, Error estimates on averages of correlated data, Journal of Chemical Physics 91, 461-466 (1989).
Statistical analysis.
* As in other experiments, Monte Carlo experiments have two classes of errors:
* Statistical errors
* Systematical errors
* Statistical errors can be estimated using standard tools from statistics
* Systematical errors are method specific and must be treated differently from case to case. (In VMC a common source is the step length or time step in importance sampling)
The probability distribution function (PDF) is a function $p(x)$ on the domain which, in the discrete case, gives us the probability or relative frequency with which these values of $X$ occur:
In the continuous case, the PDF does not directly depict the actual probability. Instead we define the probability for the stochastic variable to assume any value on an infinitesimal interval around $x$ to be $p(x)dx$. The continuous function $p(x)$ then gives us the density of the probability rather than the probability itself. The probability for a stochastic variable to assume any value on a non-infinitesimal interval $[a,\,b]$ is then just the integral:
Qualitatively speaking, a stochastic variable represents the values of numbers chosen as if by chance from some specified PDF so that the selection of a large set of these numbers reproduces this PDF.
Also of interest to us is the cumulative probability distribution function (CDF), $P(x)$, which is just the probability for a stochastic variable $X$ to assume any value less than $x$:
The relation between a CDF and its corresponding PDF is then:
The zero-th moment $\langle 1\rangle$ is just the normalization condition of $p$. The first moment, $\langle x\rangle$, is called the mean of $p$ and often denoted by the letter $\mu$:
The zero-th and first central moments are both trivial, equal $1$ and $0$, respectively. But the second central moment, known as the variance of $p$, is of particular interest. For the stochastic variable $X$, the variance is denoted as $\sigma^2_X$ or $\mathrm{var}(X)$:
The square root of the variance, $\sigma =\sqrt{\langle (x-\langle x\rangle)^2\rangle}$ is called the standard deviation of $p$. It is clearly just the RMS (root-mean-square) value of the deviation of the PDF from its mean value, interpreted qualitatively as the spread of $p$ around its mean.
Another important quantity is the so called covariance, a variant of the above defined variance. Consider again the set $\{X_i\}$ of $n$ stochastic variables (not necessarily uncorrelated) with the multivariate PDF $P(x_1,\dots,x_n)$. The covariance of two of the stochastic variables, $X_i$ and $X_j$, is defined as follows:
with
If we consider the above covariance as a matrix $C_{ij}=\mathrm{cov}(X_i,\,X_j)$, then the diagonal elements are just the familiar variances, $C_{ii} = \mathrm{cov}(X_i,\,X_i) = \mathrm{var}(X_i)$. It turns out that all the off-diagonal elements are zero if the stochastic variables are uncorrelated. This is easy to show, keeping in mind the linearity of the expectation value. Consider the stochastic variables $X_i$ and $X_j$, ($i\neq j$):
If $X_i$ and $X_j$ are independent, we get $\langle x_i x_j\rangle =\langle x_i\rangle\langle x_j\rangle$, resulting in $\mathrm{cov}(X_i, X_j) = 0\ \ (i\neq j)$.
Also useful for us is the covariance of linear combinations of stochastic variables. Let $\{X_i\}$ and $\{Y_i\}$ be two sets of stochastic variables. Let also $\{a_i\}$ and $\{b_i\}$ be two sets of scalars. Consider the linear combination:
By the linearity of the expectation value
And in the special case when the stochastic variables are uncorrelated, the off-diagonal elements of the covariance are as we know zero, resulting in:
1 5 6
< < < ! ! M A T H _ B L O C K
We will call these values our measurements and the entire set as our measured sample. The action of measuring all the elements of a sample we will call a stochastic experiment since, operationally, they are often associated with results of empirical observation of some physical or mathematical phenomena; precisely an experiment. We assume that these values are distributed according to some PDF $p_X^{\phantom X}(x)$, where $X$ is just the formal symbol for the stochastic variable whose PDF is $p_X^{\phantom X}(x)$. Instead of trying to determine the full distribution $p$ we are often only interested in finding the few lowest moments, like the mean $\mu_X^{\phantom X}$ and the variance $\sigma_X^{\phantom X}$.
In practical situations a sample is always of finite size. Let that size be $n$. The expectation value of a sample, the sample mean, is then defined as follows:
The sample variance is:
its square root being the standard deviation of the sample. The sample covariance is:
Note that the sample variance is the sample covariance without the cross terms. In a similar manner as the covariance in Eq. (16) is a measure of the correlation between two stochastic variables, the above defined sample covariance is a measure of the sequential correlation between succeeding measurements of a sample.
These quantities, being known experimental values, differ significantly from and must not be confused with the similarly named quantities for stochastic variables, mean $\mu_X$, variance $\mathrm{var}(X)$ and covariance $\mathrm{cov}(X,Y)$.
The law of large numbers states that as the size of our sample grows to infinity, the sample mean approaches the true mean $\mu_X^{\phantom X}$ of the chosen PDF:
The sample mean $\bar{x}_n$ works therefore as an estimate of the true mean $\mu_X^{\phantom X}$.
What we need to find out is how good an approximation $\bar{x}_n$ is to $\mu_X^{\phantom X}$. In any stochastic measurement, an estimated mean is of no use to us without a measure of its error. A quantity that tells us how well we can reproduce it in another experiment. We are therefore interested in the PDF of the sample mean itself. Its standard deviation will be a measure of the spread of sample means, and we will simply call it the error of the sample mean, or just sample error, and denote it by $\mathrm{err}_X^{\phantom X}$. In practice, we will only be able to produce an estimate of the sample error since the exact value would require the knowledge of the true PDFs behind, which we usually do not have.
The straight forward brute force way of estimating the sample error is simply by producing a number of samples, and treating the mean of each as a measurement. The standard deviation of these means will then be an estimate of the original sample error. If we are unable to produce more than one sample, we can split it up sequentially into smaller ones, treating each in the same way as above. This procedure is known as blocking and will be given more attention shortly. At this point it is worth while exploring more indirect methods of estimation that will help us understand some important underlying principles of correlational effects.
Let us first take a look at what happens to the sample error as the size of the sample grows. In a sample, each of the measurements $x_i$ can be associated with its own stochastic variable $X_i$. The stochastic variable $\overline X_n$ for the sample mean $\bar{x}_n$ is then just a linear combination, already familiar to us:
All the coefficients are just equal $1/n$. The PDF of $\overline X_n$, denoted by $p_{\overline X_n}(x)$ is the desired PDF of the sample means.
The probability density of obtaining a sample mean $\bar x_n$ is the product of probabilities of obtaining arbitrary values $x_1, x_2,\dots,x_n$ with the constraint that the mean of the set $\{x_i\}$ is $\bar x_n$:
And in particular we are interested in its variance $\mathrm{var}(\overline X_n)$.
It is generally not possible to express $p_{\overline X_n}(x)$ in a closed form given an arbitrary PDF $p_X^{\phantom X}$ and a number $n$. But for the limit $n\to\infty$ it is possible to make an approximation. The very important result is called the central limit theorem. It tells us that as $n$ goes to infinity, $p_{\overline X_n}(x)$ approaches a Gaussian distribution whose mean and variance equal the true mean and variance, $\mu_{X}^{\phantom X}$ and $\sigma_{X}^{2}$, respectively:
We see now that in order to calculate the exact error of the sample with the above expression, we would need the true means $\mu_{X_i}^{\phantom X}$ of the stochastic variables $X_i$. To calculate these requires that we know the true multivariate PDF of all the $X_i$. But this PDF is unknown to us, we have only got the measurements of one sample. The best we can do is to let the sample itself be an estimate of the PDF of each of the $X_i$, estimating all properties of $X_i$ through the measurements of the sample.
Our estimate of $\mu_{X_i}^{\phantom X}$ is then the sample mean $\bar x$ itself, in accordance with the the central limit theorem:
Using $\bar x$ in place of $\mu_{X_i}^{\phantom X}$ we can give an estimate of the covariance in Eq. (24)
resulting in
which is approximated as
Now we can calculate an estimate of the error $\mathrm{err}_X^{\phantom X}$ of the sample mean $\bar x_n$:
which is nothing but the sample covariance divided by the number of measurements in the sample.
In the special case that the measurements of the sample are uncorrelated (equivalently the stochastic variables $X_i$ are uncorrelated) we have that the off-diagonal elements of the covariance are zero. This gives the following estimate of the sample error:
resulting in
where in the second step we have used Eq. (25). The error of the sample is then just its standard deviation divided by the square root of the number of measurements the sample contains. This is a very useful formula which is easy to compute. It acts as a first approximation to the error, but in numerical experiments, we cannot overlook the always present correlations.
For computational purposes one usually splits up the estimate of $\mathrm{err}_X^2$, given by Eq. (26), into two parts
which equals
The first term is the same as the error in the uncorrelated case, Eq. (27). This means that the second term accounts for the error correction due to correlation between the measurements. For uncorrelated measurements this second term is zero.
Computationally the uncorrelated first term is much easier to treat efficiently than the second.
We just accumulate separately the values $x^2$ and $x$ for every measurement $x$ we receive. The correlation term, though, has to be calculated at the end of the experiment since we need all the measurements to calculate the cross terms. Therefore, all measurements have to be stored throughout the experiment.
Let us analyze the problem by splitting up the correlation term into partial sums of the form:
The correlation term of the error can now be rewritten in terms of $f_d$
The value of $f_d$ reflects the correlation between measurements separated by the distance $d$ in the sample samples. Notice that for $d=0$, $f$ is just the sample variance, $\mathrm{var}(x)$. If we divide $f_d$ by $\mathrm{var}(x)$, we arrive at the so called autocorrelation function
which gives us a useful measure of the correlation pair correlation starting always at $1$ for $d=0$.
The sample error (see eq. (28)) can now be written in terms of the autocorrelation function:
and we see that $\mathrm{err}_X$ can be expressed in terms the uncorrelated sample variance times a correction factor $\tau$ which accounts for the correlation between measurements. We call this correction factor the autocorrelation time:
For a correlation free experiment, $\tau$ equals 1. From the point of view of eq. (29) we can interpret a sequential correlation as an effective reduction of the number of measurements by a factor $\tau$. The effective number of measurements becomes:
To neglect the autocorrelation time $\tau$ will always cause our simple uncorrelated estimate of $\mathrm{err}_X^2\approx \mathrm{var}(x)/n$ to be less than the true sample error. The estimate of the error will be too good. On the other hand, the calculation of the full autocorrelation time poses an efficiency problem if the set of measurements is very large.
The so-called time-displacement autocorrelation $\phi(t)$ for a quantity $\mathbf{M}$ is given by
which can be rewritten as
where $\langle \mathbf{M} \rangle$ is the average value and $\mathbf{M}(t)$ its instantaneous value. We can discretize this function as follows, where we used our set of computed values $\mathbf{M}(t)$ for a set of discretized times (our Monte Carlo cycles corresponding to moving all electrons?)
One should be careful with times close to $t_{\mathrm{max}}$, the upper limit of the sums becomes small and we end up integrating over a rather small time interval. This means that the statistical error in $\phi(t)$ due to the random nature of the fluctuations in $\mathbf{M}(t)$ can become large.
One should therefore choose $t \ll t_{\mathrm{max}}$.
Note that the variable $\mathbf{M}$ can be any expectation values of interest.
The time-correlation function gives a measure of the correlation between the various values of the variable at a time $t'$ and a time $t'+t$. If we multiply the values of $\mathbf{M}$ at these two different times, we will get a positive contribution if they are fluctuating in the same direction, or a negative value if they fluctuate in the opposite direction. If we then integrate over time, or use the discretized version of, the time correlation function $\phi(t)$ should take a non-zero value if the fluctuations are correlated, else it should gradually go to zero. For times a long way apart the different values of $\mathbf{M}$ are most likely uncorrelated and $\phi(t)$ should be zero.
We can derive the correlation time by observing that our Metropolis algorithm is based on a random walk in the space of all possible spin configurations. Our probability distribution function $\mathbf{\hat{w}}(t)$ after a given number of time steps $t$ could be written as
with $\mathbf{\hat{w}}(0)$ the distribution at $t=0$ and $\mathbf{\hat{W}}$ representing the transition probability matrix. We can always expand $\mathbf{\hat{w}}(0)$ in terms of the right eigenvectors of $\mathbf{\hat{v}}$ of $\mathbf{\hat{W}}$ as
resulting in
with $\lambda_i$ the $i^{\mathrm{th}}$ eigenvalue corresponding to
the eigenvector $\mathbf{\hat{v}}_i$.
If we assume that $\lambda_0$ is the largest eigenvector we see that in the limit $t\rightarrow \infty$, $\mathbf{\hat{w}}(t)$ becomes proportional to the corresponding eigenvector $\mathbf{\hat{v}}_0$. This is our steady state or final distribution.
We can relate this property to an observable like the mean energy. With the probabilty $\mathbf{\hat{w}}(t)$ (which in our case is the squared trial wave function) we can write the expectation values as
or as the scalar of a vector product
If we define $m_i=\mathbf{\hat{v}}_i\mathbf{m}_i$ as the expectation value of $\mathbf{M}$ in the $i^{\mathrm{th}}$ eigenstate we can rewrite the last equation as
Since we have that in the limit $t\rightarrow \infty$ the mean value is dominated by the the largest eigenvalue $\lambda_0$, we can rewrite the last equation as
We define the quantity
and rewrite the last expectation value as
The quantities $\tau_i$ are the correlation times for the system. They control also the auto-correlation function discussed above. The longest correlation time is obviously given by the second largest eigenvalue $\tau_1$, which normally defines the correlation time discussed above. For large times, this is the only correlation time that survives. If higher eigenvalues of the transition matrix are well separated from $\lambda_1$ and we simulate long enough, $\tau_1$ may well define the correlation time. In other cases we may not be able to extract a reliable result for $\tau_1$. Coming back to the time correlation function $\phi(t)$ we can present a more general definition in terms of the mean magnetizations $ \langle \mathbf{M}(t) \rangle$. Recalling that the mean value is equal to $ \langle \mathbf{M}(\infty) \rangle$ we arrive at the expectation values
resulting in
then the exponential correlation time can be computed as the average
If the decay is exponential, then
which suggests another measure of correlation
where $\tau$ is the correlation time (the time between a sample and the next uncorrelated sample) and $\Delta t$ is time between each sample
Blocking.
* If $\Delta t\gg\tau$ our first estimate of $\sigma$ still holds
* Much more common that $\Delta t<\tau$
* In the method of data blocking we divide the sequence of samples into blocks
* We then take the mean $\langle \mathbf{M}_i\rangle$ of block $i=1\ldots n_{blocks}$ to calculate the total mean and variance
* The size of each block must be so large that sample $j$ of block $i$ is not correlated with sample $j$ of block $i+1$
* The correlation time $\tau$ would be a good choice
Blocking.
* Problem: We don't know $\tau$ or it is too expensive to compute
* Solution: Make a plot of std. dev. as a function of blocksize
* The estimate of std. dev. of correlated data is too low $\to$ the error will increase with increasing block size until the blocks are uncorrelated, where we reach a plateau
* When the std. dev. stops increasing the blocks are uncorrelated
* Do a Monte Carlo simulation, storing all samples to file
* Do the statistical analysis on this file, independently of your Monte Carlo program
* Read the file into an array
* Loop over various block sizes
* For each block size $n_b$, loop over the array in steps of $n_b$ taking the mean of elements $i n_b,\ldots,(i+1) n_b$
* Take the mean and variance of the resulting array
* Write the results for each block size to file for later
analysis
When the file gets large, it can be useful to write your data in binary mode instead of ascii characters. The following file reads data from a binary file with the output from every Monte Carlo cycle.
int main (int nargs, char* args[])
{
int min_block_size, max_block_size, n_block_samples;
// Read from screen a possible new vaue of n
if (nargs > 3) {
min_block_size = atoi(args[1]);
max_block_size = atoi(args[2]);
n_block_samples = atoi(args[3]);
}
else{
cerr << "usage: ./mcint_blocking.x <min_bloc_size> "
<< "<max_block_size> <n_block_samples>" << endl;
exit(1);
}
// get file size using stat
struct stat result;
int n;
// find number of data points
if(stat("result.dat", &result) == 0){
n = result.st_size/sizeof(double);
}
else{
cerr << "error in getting file size" << endl;
exit(1);
}
// get all mc results from file
double* mc_results = new double[n];
ifstream infile;
infile.open("result.dat", ios::in | ios::binary);
// additional lines omitted
infile.close();
}
double mean, sigma;
double res[2];
meanvar(mc_results, n, res);
mean = res[0]; sigma= res[1];
cout << "Value of integral = " << mean << endl;
cout << "Value of variance = " << sigma << endl;
cout << "Standard deviation = " << sqrt(sigma/(n-1.0)) << endl;
// Open file for writing, writing results in formated output for plotting:
ofstream outfile;
outfile.open("blockres.dat", ios::out);
outfile << setprecision(10);
double* block_results = new double[n_block_samples];
int block_size, block_step_length;
block_step_length = (max_block_size-min_block_size)/n_block_samples;
// loop over block sizes
for(int i=0; i<n_block_samples; i++){
block_size = min_block_size+i*block_step_length;
blocking(mc_results, n, block_size, res);
mean = res[0];
sigma = res[1];
// formated output
outfile << block_size << "\t" << sqrt(sigma/((n/block_size)-1.0)) << endl;
}
outfile.close();
return 0;
}
// find mean of values in vals
double mean(double *vals, int n_vals){
double m=0;
for(int i=0; i<n_vals; i++){
m+=vals[i];
}
return m/double(n_vals);
}
// calculate mean and variance of vals, results stored in res
void meanvar(double *vals, int n_vals, double *res){
double m2=0, m=0, val;
for(int i=0; i<n_vals; i++){
val=vals[i];
m+=val;
m2+=val*val;
}
m /= double(n_vals);
m2 /= double(n_vals);
res[0] = m;
res[1] = m2-(m*m);
}
// find mean and variance of blocks of size block_size.
// mean and variance are stored in res
void blocking(double *vals, int n_vals, int block_size, double *res){
// note: integer division will waste some values
int n_blocks = n_vals/block_size;
/*
cerr << "n_vals=" << n_vals << ", block_size=" << block_size << endl;
if(n_vals%block_size > 0)
cerr << "lost " << n_vals%block_size << " values due to integer division"
<< endl;
*/
double* block_vals = new double[n_blocks];
for(int i=0; i<n_blocks; i++){
block_vals[i] = mean(vals+i*block_size, block_size);
}
meanvar(block_vals, n_blocks, res);
delete block_vals;
}
The potentially most time-consuming part is the evaluation of the gradient and the Laplacian of an $N$-particle Slater determinant.
We have to differentiate the determinant with respect to all spatial coordinates of all particles. A brute force differentiation would involve $N\cdot d$ evaluations of the entire determinant which would even worsen the already undesirable time scaling, making it $Nd\cdot O(N^3)\sim O(d\cdot N^4)$.
This poses serious hindrances to the overall efficiency of our code.
The efficiency can be improved however if we move only one electron at the time. The Slater determinant matrix $\hat{D}$ is defined by the matrix elements
where $\phi_j(\mathbf{r}_i)$ is a single particle wave function. The columns correspond to the position of a given particle while the rows stand for the various quantum numbers.
What we need to realize is that when differentiating a Slater determinant with respect to some given coordinate, only one row of the corresponding Slater matrix is changed.
Therefore, by recalculating the whole determinant we risk producing redundant information. The solution turns out to be an algorithm that requires to keep track of the inverse of the Slater matrix.
Let the current position in phase space be represented by the $(N\cdot d)$-element vector $\mathbf{r}^{\mathrm{old}}$ and the new suggested position by the vector $\mathbf{r}^{\mathrm{new}}$.
The inverse of $\hat{D}$ can be expressed in terms of its cofactors $C_{ij}$ and its determinant (this our notation for a determinant) $\vert\hat{D}\vert$:
Notice that the interchanged indices indicate that the matrix of cofactors is to be transposed.
If $\hat{D}$ is invertible, then we must obviously have $\hat{D}^{-1}\hat{D}= \mathbf{1}$, or explicitly in terms of the individual elements of $\hat{D}$ and $\hat{D}^{-1}$:
Consider the ratio, which we shall call $R$, between $\vert\hat{D}(\mathbf{r}^{\mathrm{new}})\vert$ and $\vert\hat{D}(\mathbf{r}^{\mathrm{old}})\vert$. By definition, each of these determinants can individually be expressed in terms of the i-th row of its cofactor matrix
Suppose now that we move only one particle at a time, meaning that $\mathbf{r}^{\mathrm{new}}$ differs from $\mathbf{r}^{\mathrm{old}}$ by the position of only one, say the i-th, particle . This means that $\hat{D}(\mathbf{r}^{\mathrm{new}})$ and $\hat{D}(\mathbf{r}^{\mathrm{old}})$ differ only by the entries of the i-th row. Recall also that the i-th row of a cofactor matrix $\hat{C}$ is independent of the entries of the i-th row of its corresponding matrix $\hat{D}$. In this particular case we therefore get that the i-th row of $\hat{C}(\mathbf{r}^{\mathrm{new}})$ and $\hat{C}(\mathbf{r}^{\mathrm{old}})$ must be equal. Explicitly, we have:
Now by eq. (34) the denominator of the rightmost expression must be unity, so that we finally arrive at:
What this means is that in order to get the ratio when only the i-th particle has been moved, we only need to calculate the dot product of the vector $\left(\phi_1(\mathbf{r}_i^\mathrm{new}),\,\dots,\,\phi_N(\mathbf{r}_i^\mathrm{new})\right)$ of single particle wave functions evaluated at this new position with the i-th column of the inverse matrix $\hat{D}^{-1}$ evaluated at the original position. Such an operation has a time scaling of $O(N)$. The only extra thing we need to do is to maintain the inverse matrix $\hat{D}^{-1}(\mathbf{x}^{\mathrm{old}})$.
If the new position $\mathbf{r}^{\mathrm{new}}$ is accepted, then the inverse matrix can by suitably updated by an algorithm having a time scaling of $O(N^2)$. This algorithm goes as follows. First we update all but the i-th column of $\hat{D}^{-1}$. For each column $j\neq i$, we first calculate the quantity:
We see from these formulas that the time scaling of an update of $\hat{D}^{-1}$ after changing one row of $\hat{D}$ is $O(N^2)$.
The scheme is also applicable for the calculation of the ratios involving derivatives. It turns out that differentiating the Slater determinant with respect to the coordinates of a single particle $\mathbf{r}_i$ changes only the i-th row of the corresponding Slater matrix.
The gradient and the Laplacian can therefore be calculated as follows:
and
Thus, to calculate all the derivatives of the Slater determinant, we only need the derivatives of the single particle wave functions ($\vec\nabla_i \phi_j(\mathbf{r}_i)$ and $\nabla^2_i \phi_j(\mathbf{r}_i)$) and the elements of the corresponding inverse Slater matrix ($\hat{D}^{-1}(\mathbf{r}_i)$). A calculation of a single derivative is by the above result an $O(N)$ operation. Since there are $d\cdot N$ derivatives, the time scaling of the total evaluation becomes $O(d\cdot N^2)$. With an $O(N^2)$ updating algorithm for the inverse matrix, the total scaling is no worse, which is far better than the brute force approach yielding $O(d\cdot N^4)$.
Important note: In most cases you end with closed form expressions for the single-particle wave functions. It is then useful to calculate the various derivatives and make separate functions for them.
The Slater determinant takes the form
2 2 2
< < < ! ! M A T H _ B L O C K
2 2 3
< < < ! ! M A T H _ B L O C K
where we have defined
and
The total determinant is still zero!
We want to avoid to sum over spin variables, in particular when the interaction does not depend on spin.
It can be shown, see for example Moskowitz and Kalos, Int. J. Quantum Chem. 20 1107 (1981), that for the variational energy we can approximate the Slater determinant as
or more generally as
where we have the Slater determinant as the product of a spin up part involving the number of electrons with spin up only (2 for beryllium and 5 for neon) and a spin down part involving the electrons with spin down.
This ansatz is not antisymmetric under the exchange of electrons with opposite spins but it can be shown (show this) that it gives the same expectation value for the energy as the full Slater determinant.
As long as the Hamiltonian is spin independent, the above is correct. It is rather straightforward to see this if you go back to the equations for the energy discussed earlier this semester.
We will thus factorize the full determinant $\vert\hat{D}\vert$ into two smaller ones, where each can be identified with $\uparrow$ and $\downarrow$ respectively:
The combined dimensionality of the two smaller determinants equals the dimensionality of the full determinant. Such a factorization is advantageous in that it makes it possible to perform the calculation of the ratio $R$ and the updating of the inverse matrix separately for $\vert\hat{D}\vert_\uparrow$ and $\vert\hat{D}\vert_\downarrow$:
This reduces the calculation time by a constant factor. The maximal time reduction happens in a system of equal numbers of $\uparrow$ and $\downarrow$ particles, so that the two factorized determinants are half the size of the original one.
Consider the case of moving only one particle at a time which originally had the following time scaling for one transition:
For the factorized determinants one of the two determinants is obviously unaffected by the change so that it cancels from the ratio $R$.
Therefore, only one determinant of size $N/2$ is involved in each calculation of $R$ and update of the inverse matrix. The scaling of each transition then becomes:
and the time scaling when the transitions for all $N$ particles are put together:
which gives the same reduction as in the case of moving all particles at once.
Computing the ratios discussed above requires that we maintain the inverse of the Slater matrix evaluated at the current position. Each time a trial position is accepted, the row number $i$ of the Slater matrix changes and updating its inverse has to be carried out. Getting the inverse of an $N \times N$ matrix by Gaussian elimination has a complexity of order of $\mathcal{O}(N^3)$ operations, a luxury that we cannot afford for each time a particle move is accepted. We will use the expression
This equation scales as $O(N^2)$. The evaluation of the determinant of an $N \times N$ matrix by standard Gaussian elimination requires $\mathbf{O}(N^3)$ calculations. As there are $Nd$ independent coordinates we need to evaluate $Nd$ Slater determinants for the gradient (quantum force) and $Nd$ for the Laplacian (kinetic energy). With the updating algorithm we need only to invert the Slater determinant matrix once. This can be done by standard LU decomposition methods.
Determining a determinant of an $N \times N$ matrix by standard Gaussian elimination is of the order of $\mathbf{O}(N^3)$ calculations. As there are $N\cdot d$ independent coordinates we need to evaluate $Nd$ Slater determinants for the gradient (quantum force) and $N\cdot d$ for the Laplacian (kinetic energy)
With the updating algorithm we need only to invert the Slater determinant matrix once. This is done by calling standard LU decomposition methods.
If you choose to implement the above recipe for the computation of the Slater determinant, you need to LU decompose the Slater matrix. This is described in chapter 6 of the lecture notes from FYS3150.
You need to call the function ludcmp in lib.cpp. You need to transfer the Slater matrix and its dimension. You get back an LU decomposed matrix.
The LU decomposition method means that we can rewrite this matrix as the product of two matrices $\hat{B}$ and $\hat{C}$ where
2 3 7
< < < ! ! M A T H _ B L O C K
2 3 8
< < < ! ! M A T H _ B L O C K
2 4 1
< < < ! ! M A T H _ B L O C K
and it is easy to see that for particle $k$ we have
and $g'(r_{kj})=dg(r_{kj})/dr_{kj}$ and $g''(r_{kj})=d^2g(r_{kj})/dr_{kj}^2$ we find that for particle $k$ we have
and
the gradient needed for the quantum force and local energy is easy to compute.
We get for particle $k$
What this means is that in order to get the ratio when only the i-th particle has been moved, we only need to calculate the dot product of the vector $\left(\phi_1(\mathbf{r}_i^\mathrm{new}),\,\dots,\, \phi_N(\mathbf{r}_i^\mathrm{new})\right)$ of single particle wave functions evaluated at this new position with the i-th column of the inverse matrix $\hat{D}^{-1}$ evaluated at the original position. Such an operation has a time scaling of $O(N)$. The only extra thing we need to do is to maintain the inverse matrix $\hat{D}^{-1}(\mathbf{x}^{\mathrm{old}})$.
The $1s$ hydrogen like wave function
and the $2p$ hydrogen -like wave function is
2 5 7
< < < ! ! M A T H _ B L O C K
and
where we have used $r=\sqrt{x^2+y^2+z^2}$. It is not possible to find a separable solution of the type
However, with spherical coordinates we can find a solution of the form
with $P_l^{m_l}$ being the associated Legendre polynomials They can be rewritten as
for $l=m_l=0$,
for $l=1$ og $m_l=0$,
for $l=1$ og $m_l=\pm 1$.
A problem with the spherical harmonics is that they are complex. The introduction of solid harmonics allows the use of real orbital wave-functions for a wide range of applications. The complex solid harmonics $\mathbf{Y}_{lm_l}(\mathbf{r})$ are related to the spherical harmonics $Y_{lm_l}(\mathbf{r})$ through
By factoring out the leading $r$-dependency of the radial-function
we obtain
This transformation will not alter any physical quantities that are degenerate in the subspace consisting of opposite magnetic quantum numbers (the angular momentum $l$ is equal for both these cases). This means for example that the above transformation does not alter the energies, unless an external magnetic field is applied to the system. Henceforth, we will use the solid harmonics, and note that changing the spherical potential beyond the Coulomb potential will not alter the solid harmonics.
We have defined
The real-valued spherical harmonics are defined as
2 7 3
< < < ! ! M A T H _ B L O C K
2 7 4
< < < ! ! M A T H _ B L O C K
for $m_l> 0$.
$m_l\backslash l$ | 0 | 1 | 2 | 3 |
---|---|---|---|---|
+3 | $\frac{1}{2}\sqrt{\frac{5}{2}}(x^2-3y^2)x$ | |||
+2 | $\frac{1}{2}\sqrt{3}(x^2-y^2)$ | $\frac{1}{2}\sqrt{15}(x^2-y^2)z$ | ||
+1 | $x$ | $\sqrt{3}xz$ | $\frac{1}{2}\sqrt{\frac{3}{2}}(5z^2-r^2)x$ | |
0 | $y$ | $\frac{1}{2}(3z^2-r^2)$ | $\frac{1}{2}(5z^2-3r^2)x$ | |
-1 | $z$ | $\sqrt{3}yz$ | $\frac{1}{2}\sqrt{\frac{3}{2}}(5z^2-r^2)y$ | |
-2 | $\sqrt{3}xy$ | $\sqrt{15}xyz$ | ||
-3 | $\frac{1}{2}\sqrt{\frac{5}{2}}(3x^2-y^2)y$ |
As a starting point we may consider that each time a new position is suggested in the Metropolis algorithm, a row of the current Slater matrix experiences some kind of perturbation. Hence, the Slater matrix with its orbitals evaluated at the new position equals the old Slater matrix plus a perturbation matrix,
where
Using $$\mathbf{D}^{-1}(\mathbf{x^{old}}) = \frac{adj \mathbf{D}}{|\mathbf{D}(\mathbf{x^{old}})|} \, \quad \text{and} \, \quad \mathbf{D}^{-1}(\mathbf{x^{new}}) = \frac{adj \mathbf{D}}{|\mathbf{D}(\mathbf{x^{new}})|},$$ and dividing these two equations we get $$\frac{\mathbf{D}^{-1}(\mathbf{x^{old}})}{\mathbf{D}^{-1}(\mathbf{x^{new}})} = \frac{|\mathbf{D}(\mathbf{x^{new}})|}{|\mathbf{D}(\mathbf{x^{old}})|} = R \Rightarrow d^{-1}_{ki}(\mathbf{x^{new}}) = \frac{d^{-1}_{ki}(\mathbf{x^{old}})}{R}.$$
We have $$d^{-1}_{kj}(\mathbf{x^{new}}) = d^{-1}_{kj}(\mathbf{x^{old}}) - \frac{d^{-1}_{ki}(\mathbf{x^{old}})}{R} \sum_{l=1}^{N}[\phi_{l}(\mathbf{r_{i}^{new}}) - \phi_{l}(\mathbf{r_{i}^{old}})] d^{-1}_{lj}(\mathbf{x^{old}}),$$ or