diff --git a/ackwork/ToDo b/ackwork/ToDo
index 44f87a0ee1f3db91050a5d95c10972f9f1c68a4d..f19bad745e1e6311a67027a178ca2ff465d819f7 100644
--- a/ackwork/ToDo
+++ b/ackwork/ToDo
@@ -1,3 +1,5 @@
In dorun.go
* make the csv files optional
+
+Note.. Benchmarking suggests that most of the time is spent in Ackley function, and, to be exact, in the cosine and exp() function.
\ No newline at end of file
diff --git a/ackwork/dorun.go b/ackwork/dorun.go
index 94c5630dde70063bcd967fe06f955ae83981d28e..9bae7669b15d4eb6c3a962bfb6dfb31ecba643b3 100644
--- a/ackwork/dorun.go
+++ b/ackwork/dorun.go
@@ -177,16 +177,15 @@ func doRun(mcPrm *mcPrm) error {
if err := setupRun(mcPrm, &cprm); err != nil {
return err
}
- if cprm.fOut != nil {
- defer cprm.fOut.Flush()
+ if cprm.fOut != nil { // The text file documenting the run
defer cprm.fOutRaw.Close()
+ defer cprm.fOut.Flush()
}
- var nAcc int // Counter of number of accepted moves
+ var nAcc int // Counter, number of accepted moves
x := make([]float32, len(mcPrm.xIni)) // current position
xT := make([]float32, len(mcPrm.xIni)) // trial position
- // nout := uint32(1) // counter for printing output
- runAcc := accRateIdeal // Running acceptance rate, exponentially weighted
+ runAcc := accRateIdeal // Running acceptance rate, exponentially weighted
copy(x, mcPrm.xIni)
fOld := ackley.Ackley(x) // Initial function value
fTrial := fOld
@@ -194,13 +193,10 @@ func doRun(mcPrm *mcPrm) error {
nRunAcc := nRunAccAdj // Every nRunAccAdj, try adjusting the step size.
const runMult = 0.99
xDlta := mcPrm.xDlta // Adaptable step size
- if mcPrm.fOutName == "test9d.csv" {
- breaker()
- }
saveStep(&cprm, 0, tmprtr, x, fOld)
for n := uint32(0); n < mcPrm.nStep; n++ {
- var acc bool
+ var accept bool
nRunAcc--
if nRunAcc == 0 { // Do we want to try adjusting the step size ?
xDlta = nRunAdj(mcPrm, n, runAcc, xDlta)
@@ -209,17 +205,16 @@ func doRun(mcPrm *mcPrm) error {
newx(x, xT, cprm.rand, xDlta)
fTrial = ackley.Ackley(xT)
- if fOld < fTrial {
- r := cprm.rand.Float64() // Make the decision as to whether to
- delta := fTrial - fOld // accept or reject the trial
- t := math.Exp(-delta / tmprtr)
- if r < t {
- acc = true
- }
+ if fTrial <= fOld {
+ accept = true
} else {
- acc = true
+ delta := fTrial - fOld // Make the decision as to whether to
+ t := math.Exp(-delta / tmprtr) // accept or reject the trial
+ if cprm.rand.Float64() < t {
+ accept = true
+ }
}
- if acc == true {
+ if accept == true {
nAcc++
runAcc = runMult*runAcc + (1.0 - runMult)
copy(x, xT)
@@ -227,26 +222,23 @@ func doRun(mcPrm *mcPrm) error {
saveStep(&cprm, n+1, tmprtr, x, fTrial)
} else { // update the running estimate of acceptance
runAcc = runMult * runAcc
- // saveStep(&cprm, n+1, tmprtr, x, fTrial) // debugging delete me
}
if cprm.coolme {
tmprtr *= cprm.coolMult
}
}
- if mcPrm.fOutName == "test9d.csv" {
- breaker()
- }
// On plots, we want the last step, even if nothing changed. Print me. Fix.
if fTrial != fOld { // last move was not accepted, so we have to add last step
saveStep(&cprm, mcPrm.nStep, tmprtr, x, fOld)
}
- err := plotfWrt(cprm.plotnstp, cprm.plotf, cprm.plotTmprtr, mcPrm.fPltName, cprm.fplotme)
- if err != nil {
+ defer fmt.Println("n accepted:", nAcc, "of", mcPrm.nStep+1)
+ if err := plotfWrt(&cprm, mcPrm.fPltName); err != nil {
+ return err
+ }
+ if err := plotxWrt(&cprm, mcPrm.xPltName, len(mcPrm.xIni)); err != nil {
return err
}
- err = plotxWrt(&cprm, mcPrm.xPltName, len(mcPrm.xIni))
- fmt.Println("n accepted:", nAcc, "of", mcPrm.nStep+1)
- return err
+ return nil
}
diff --git a/ackwork/plot.go b/ackwork/plot.go
index 6de74fbd0e00e62186692484de9942f04ad56769..2b7590808e1b5c5f07b5f57119dd60506501473f 100644
--- a/ackwork/plot.go
+++ b/ackwork/plot.go
@@ -59,13 +59,14 @@ func (rng *range2) GetTicks(r chart.Renderer, cs chart.Style, vf chart.ValueForm
}
// plotfWrt writes out a plot of function values to the given
-// io.writer. We do not close the file. The caller opened it,
-// so he should close it.
-func plotfWrt(xdata, ydata []float64, tmprtrData []float64,
- fname string, plotme bool) error {
- if !plotme {
+// filename
+func plotfWrt(cprm *cprm, fname string) error {
+ if !cprm.fplotme {
return nil
}
+ xdata := cprm.plotnstp // We just unpack for readability
+ ydata := cprm.plotf
+ tmprtrData := cprm.plotTmprtr
xaxis := chart.XAxis{
Name: "step",
@@ -127,7 +128,6 @@ func plotfWrt(xdata, ydata []float64, tmprtrData []float64,
return nil
}
-func breaker() {}
// plotxWrt
// For each dimension, allocate space. Copy elements over from the long array.
diff --git a/ackwork/set_suffix.go b/ackwork/set_suffix.go
index d10f0010632f904e7c9a3a7ced9948e2a4e6478c..b8387e5ee8664abebc8e2e5c88b512221a491f45 100644
--- a/ackwork/set_suffix.go
+++ b/ackwork/set_suffix.go
@@ -3,7 +3,7 @@ package ackwork
import (
"errors"
- "path/filepath"
+ "path/filepath"
)
// setSuffix takes a name and makes sure the desired suffix is at the end
diff --git a/doc.go b/doc.go
index 8f71b5503aca8c7703be79995e6cfd4f983538a7..94a075547ee5f8e565bf446357854e17b4a78679 100644
--- a/doc.go
+++ b/doc.go
@@ -12,7 +12,6 @@ package main
{"final_temp", "1"},
{"n_step", "1000"},
{"n_run", "1"},
- {"n_output", "500"},
{"x_ini", "3,4,5"},
{"x_delta", "0.5"},
{"seed", "1637"},