From c3e9d11c0f40ea15c2ce11651b250fc55d112c7b Mon Sep 17 00:00:00 2001
From: "Andrew E. Torda" <torda@zbh.uni-hamburg.de>
Date: Fri, 22 Apr 2022 20:38:37 +0200
Subject: [PATCH] Removed adaptive step code.

---
 docs/doc.go        |  3 +--
 mc_work/dorun.go   | 36 ------------------------------------
 mc_work/mc_work.go |  1 -
 mc_work/rdprm.go   |  4 ----
 ui/input_tab.go    | 11 ++---------
 5 files changed, 3 insertions(+), 52 deletions(-)

diff --git a/docs/doc.go b/docs/doc.go
index 7a7146f..4db3ff0 100644
--- a/docs/doc.go
+++ b/docs/doc.go
@@ -45,5 +45,4 @@ and they have the meaning
 If final_temp is lower than initial temperature, we will do simulated annealing. 
 
 */
-package main
-
+package ackley_doc
diff --git a/mc_work/dorun.go b/mc_work/dorun.go
index e767847..65cdcfb 100644
--- a/mc_work/dorun.go
+++ b/mc_work/dorun.go
@@ -15,8 +15,6 @@ import (
 )
 
 const (
-	accRateIdeal = 0.05 // target of 5% acceptance rate
-	nRunAccAdj   = 200  // every n steps, check acceptance rate
 	maxxDlta     = 2.   // max step size
 )
 
@@ -202,23 +200,6 @@ func saveStep(cprm *cprm, n int, tmprtr float64, x []float32, fTrial float64) {
 	}
 }
 
-// nRunAdj will try to adjust the step size, given our history of accept/reject.
-func nRunAdj(mcPrm *McPrm, nstep int, runAcc float64, xDlta float64) float64 {
-	const step = "step"
-	if runAcc < accRateIdeal-0.01 { // acceptance rate too low
-		xDlta *= 0.9
-		if mcPrm.verbose {
-			fmt.Println(step, nstep, "decrease", xDlta)
-		}
-	} else if (xDlta < maxxDlta) && (runAcc > accRateIdeal+0.01) {
-		xDlta *= 1.1
-		if mcPrm.verbose {
-			fmt.Println(step, nstep, "increase", xDlta)
-		}
-	}
-	return xDlta
-}
-
 // doRun does a Monte Carlo run.
 // We only need single precision for most things, except for function
 // values, but the interface to the plot and interface packages mostly
@@ -245,7 +226,6 @@ func singleRun(mcPrm *McPrm) (MCresult, error) {
 	var nAcc int                           // Counter, number of accepted moves
 	x := make([]float32, len(mcPrm.XIni))  // current position
 	xT := make([]float32, len(mcPrm.XIni)) // trial position
-	runAcc := accRateIdeal                 // Running acceptance rate, exponentially weighted
 
 	for i := range mcPrm.XIni { // Initial coordinates from
 		x[i] = float32(mcPrm.XIni[i]) // the control structure
@@ -254,20 +234,12 @@ func singleRun(mcPrm *McPrm) (MCresult, error) {
 	fOld := ackley.Ackley(x) // Initial function value
 	fTrial := fOld
 	tmprtr := float64(mcPrm.IniTmp)
-	nRunAcc := nRunAccAdj // Every nRunAccAdj, try adjusting the step size.
 	const runMult = 0.99
 	xDlta := mcPrm.XDlta // Step size which might be adjusted on the fly
 	saveStep(&cprm, 0, tmprtr, x, fOld)
 	
 	for n := 0; n < mcPrm.NStep; n++ {
 		var accept bool
-		if mcPrm.AdaptStep { // Are we trying adaptive steps ?
-			nRunAcc--
-			if nRunAcc == 0 { // Do we want to try adjusting the step size ?
-				xDlta = nRunAdj(mcPrm, n, runAcc, xDlta)
-				nRunAcc = nRunAccAdj // Reset the counter
-			}
-		}
 		newx(x, xT, cprm.rand, xDlta)
 		fTrial = ackley.Ackley(xT)
 		if fTrial <= fOld {
@@ -284,19 +256,11 @@ func singleRun(mcPrm *McPrm) (MCresult, error) {
 			copy(x, xT)
 			fOld = fTrial
 			saveStep(&cprm, n+1, tmprtr, x, fTrial)
-			if mcPrm.AdaptStep {
-				runAcc = runMult*runAcc + (1.0 - runMult)
-			}
-		} else { // else don't really have to do anything, but update statistics
-			if mcPrm.AdaptStep {
-				runAcc = runMult * runAcc // update the running estimate of acceptance
-			}
 		}
 		if cprm.coolme {
 			tmprtr *= cprm.coolMult
 		}
 	}
-
 	// On plots, we want the last step, even if nothing changed.
 	if fTrial != fOld { // last move was not accepted, so we have to add last step
 		saveStep(&cprm, mcPrm.NStep, tmprtr, x, fOld)
diff --git a/mc_work/mc_work.go b/mc_work/mc_work.go
index 8c30fe8..57948f3 100644
--- a/mc_work/mc_work.go
+++ b/mc_work/mc_work.go
@@ -16,7 +16,6 @@ type McPrm struct {
 	fOutName       string    // where we write output to
 	fPltName       string    // where we plot to (function values)
 	xPltName       string    // where we plot x trajectories to
-	AdaptStep      bool      // Adaptive step sizes
 	verbose        bool
 }
 
diff --git a/mc_work/rdprm.go b/mc_work/rdprm.go
index fd4e05f..1be0d54 100644
--- a/mc_work/rdprm.go
+++ b/mc_work/rdprm.go
@@ -30,7 +30,6 @@ var cmdDflt = []struct {
 	{"foutname", ""},
 	{"fpltname", ""}, // empty means no plots of function
 	{"xpltname", ""},
-	{"adaptstep", ""},
 	{"verbose", ""},
 }
 
@@ -90,9 +89,6 @@ func digest(prmMap map[string]string, mcPrm *McPrm) error {
 	if prmMap["verbose"] != "" {
 		mcPrm.verbose = true
 	}
-	if prmMap["adaptstep"] != "" {
-		mcPrm.AdaptStep = true
-	}
 	return nil
 }
 
diff --git a/ui/input_tab.go b/ui/input_tab.go
index 4b8f97c..101b5eb 100644
--- a/ui/input_tab.go
+++ b/ui/input_tab.go
@@ -117,12 +117,6 @@ func paramForm(genParams genParams) *widget.Form {
 	nEqulItem, nEqulReload := intItem(&mcPrm.NEquil, "N equilibration", "number of steps for equilibration")
 	seedItem, seedReload := intItem(&mcwork.Seed, "seed random numbers", "seed for random number generator")
 
-	adaptbind := binding.BindBool(&mcPrm.AdaptStep) // checkbox for adaptive stepsize
-	adaptEntry := widget.NewCheckWithData("adaptive step size", adaptbind)
-	adaptItem := widget.NewFormItem("use adaptive step size", adaptEntry)
-	adaptItem.HintText = "Turn on adaptive moves to try to keep acceptance near 5%"
-	adaptReload := func() { _ = adaptbind.Reload() }
-
 	reloadPTab := func() {
 		iniTmpReload() // The values linked to in the the various fields can
 		fnlTmpReload() // change outside of this function, so reloadPTab
@@ -131,16 +125,15 @@ func paramForm(genParams genParams) *widget.Form {
 		nStepReload()
 		nEqulReload()
 		seedReload()
-		adaptReload()
 	}
 
 	rdfile := func() { rdwork(genParams, reloadPTab) }
 	rdfileBtn := widget.NewButton("get file       ", rdfile)
 	rdFileItem := widget.NewFormItem("read from a file", rdfileBtn)
-
+    // puke-oh-rama, Can we tidy up the next three lines ?
 	r := widget.NewForm( // Lays out the items in the form
 		iniTmpItem, fnlTmpItem, xDltaItem, xIniItem,
-		nStepItem, nEqulItem, seedItem, adaptItem, rdFileItem)
+		nStepItem, nEqulItem, seedItem, rdFileItem)
 	r.SubmitText = "start calculation"
 	r.OnSubmit = func() { startrun(genParams, r, mcPrm) }
 	reloadPTab() // does this help ? sometimes the form pops up with entries not ready
-- 
GitLab