From 0bf01ed801fe117ef7ed18cd78150e17a504d5a4 Mon Sep 17 00:00:00 2001
From: "Andrew E. Torda" <torda@zbh.uni-hamburg.de>
Date: Wed, 29 Dec 2021 11:27:53 +0100
Subject: [PATCH] Tidying before the experiment with plotting.

---
 ackwork/dorun.go | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

diff --git a/ackwork/dorun.go b/ackwork/dorun.go
index 4f0879d..6551354 100644
--- a/ackwork/dorun.go
+++ b/ackwork/dorun.go
@@ -32,7 +32,7 @@ type cprm struct { // parameters calculated from input
 	fOut     io.WriteCloser
 }
 
-// setupRun does things like get the cooling rate
+// setupRun does things like get the cooling rate, seed the random numbers.
 func setupRun(mcPrm *mcPrm, cprm *cprm) error {
 	var err error
 	if mcPrm.dummy == true {
@@ -40,16 +40,15 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
 	}
 	cprm.rand = rand.New(rand.NewSource(getSeed()))
 
-	if mcPrm.iniTmp != mcPrm.fnlTmp {
+	if mcPrm.iniTmp != mcPrm.fnlTmp { // cooling or constant temperature ?
 		var coolrate float64
 		cprm.coolme = true
 		if mcPrm.fnlTmp > mcPrm.iniTmp {
-			// would you like to print out a warning ?
+			return fmt.Errorf ("Final temp %g higher than initial temp %g", mcPrm.fnlTmp, mcPrm.iniTmp)
 		}
 		nStep := float64(mcPrm.nStep)
 		fnlTmp, iniTmp := float64(mcPrm.fnlTmp), float64(mcPrm.iniTmp)
-		if fnlTmp < 0.01 {
-			breaker()
+		if fnlTmp == 0 {
 			fnlTmp = math.SmallestNonzeroFloat32
 		}
 		coolrate = -1 / nStep
@@ -67,7 +66,8 @@ func setupRun(mcPrm *mcPrm, cprm *cprm) error {
 	return nil
 }
 
-// newx gets a candidate x slice
+// newx gets a candidate x slice. We have n dimensions, so a candidate
+// move is a slice of length n.
 func newx(xold []float32, xT []float32, rand *rand.Rand, xDlta float32) {
 	for i, x := range xold {
 		t := 2.*rand.Float32() - 1
@@ -76,6 +76,8 @@ func newx(xold []float32, xT []float32, rand *rand.Rand, xDlta float32) {
 	}
 }
 func breaker() {}
+// doRun does a Monte Carlo run. Although single precision is fine for the
+// coordinates and function, we use double precision for the temperature.
 func doRun(mcPrm *mcPrm) error {
 	var cprm cprm
 	if err := setupRun(mcPrm, &cprm); err != nil {
@@ -143,7 +145,7 @@ func doRun(mcPrm *mcPrm) error {
 			runAcc = runMult*runAcc + (1.0 - runMult)
 			copy(x, xT)
 			fOld = fTrial
-		} else {
+		} else { // update the running estimate of acceptance
 			runAcc = runMult * runAcc
 		}
 		if cprm.coolme {
-- 
GitLab