Skip to content
Snippets Groups Projects
Commit 0bf01ed8 authored by Andrew E. Torda's avatar Andrew E. Torda
Browse files

Tidying before the experiment with plotting.

parent 839b0bcd
No related branches found
No related tags found
No related merge requests found
......@@ -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 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment