diff --git a/Makefile b/Makefile index e3b5e3f5e95eb79b86a8d89953419b4b4ba4859f..1dee0922d8e504b4f45e4bed3745123550001dba 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -# Use the normal go build system for everything, but we want to automate some simple -# commands. - +# Use the normal go build system for everything, but we want to automate some +# simple commands. Unlike most makefiles, there are no dependencies for the +# executables. We let go's build commands take care of that. .POSIX: GO=go @@ -9,12 +9,16 @@ GOFMT=gofmt # The lint target only makes sense for Andrew's setup. LINTER=~/go/bin/linux_amd64/golangci-lint + all: - $(GO) build -o bin . - $(GO) build -o bin/ackley_nogfx -tags no_gfx -- . + GOOS=linux GOARCH=amd64 $(GO) build -o bin/ . + GOOS=linux GOARCH=amd64 $(GO) build -o bin/ackley_nogfx -tags no_gfx -- . GOOS=darwin GOARCH=amd64 $(GO) build -o bin/ackley_darwinamd64_nogfx -tags no_gfx -- . GOOS=darwin GOARCH=arm64 $(GO) build -o bin/ackley_darwinarm64_nogfx -tags no_gfx -- . - GOOS=windows GOARCH=amd64 $(GO) build -o bin/ackley_win_nogfx -tags no_gfx -- . + GOOS=windows GOARCH=amd64 $(GO) build -o bin/ackley_nogfx.exe -tags no_gfx -- . + +win: + GOOS=windows GOARCH=amd64 $(GO) build -o bin -- . test: $(GO) test ./... @@ -29,6 +33,7 @@ lint: clean: $(GO) clean rm -rf bin/* + rm -rf examples/*.csv rm -rf */*_delme.* rm -rf */test_tmp* rm -rf /tmp/go-build[0-9]* diff --git a/bin/.gitignore b/bin/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..2dbade41a02fe228b771ecc7247986e8650360fd --- /dev/null +++ b/bin/.gitignore @@ -0,0 +1,2 @@ +ackley* + diff --git a/docs/doc.go b/docs/doc.go index 9ca73c14d55523a8c5af3d11993d42b4fcb68c38..f6462337c5abae1fd1d6877127e70ef7158a96ac 100644 --- a/docs/doc.go +++ b/docs/doc.go @@ -1,23 +1,27 @@ // Dec 2021 /* -ackley is for teaching. We use Monte Carlo to sample Ackley's function +ackley_mc is for teaching. We use Monte Carlo to sample Ackley's function in N dimensions or perhaps with simulated annealing to optimise it. + +# Running + To run it - ackley input_file -where input_file contains a set of name-value pairs described below or perhaps - ackley -If compiled with the graphical interface, it will run the program, load some default values and let you play with it. + ackley_mc [ input_file ] +or + ackley_mc input_file +if it was not compiled with the graphical interface. The difference is that the input_file is not optional when there is no graphical interface. +If you are running with the graphical interface, you do not need an input file and some default values will be loaded. -Input parameters + +# Input parameters These are defined in rdprm.go. The defaults look like ini_temp 1 final_temp "" n_step 1000 n_equil 0 - n_run 1 x_ini 3,4,5 x_delta 0.5 seed 1637 @@ -29,11 +33,10 @@ These are defined in rdprm.go. The defaults look like and they have the meaning ini_temp initial temperature - final_temp final temperature + final_temp final temperature. If this is set, we are doing annealing. If it is not set, it will be the same as ini_temp, and this will be a constant temperature run. n_step number of steps - n_equil number of steps of equilibration - n_run number of runs. This does not do anything and should be deleted - x_ini 3,4,5 initial values for x. It is a comma separated list with no spaces allowed + n_equil number of steps of equilibration. The Monte Carlo routine is called twice. The first time, with this many steps. The results are then thrown away, since they were only there for equilibration. + x_ini initial values for x. It is a comma separated list with no spaces allowed. It is used to determine the number of dimension. A value like "1" would give you one dimension whose initial value is 1. A value like "-1,0,1,2" would give you a four dimensional system with initial values at -1, 0, 1 and 2. x_delta 0.5 used to decide on the maximum step size seed 1637 seed for the random number generator foutname "" @@ -44,6 +47,31 @@ and they have the meaning If a final_temp is not specified, set the final temp to be the same as the initial temperature and do a run at constant temperature. If final_temp is lower than initial temperature, we will do simulated annealing. -Adaptive step sizes have been removed. They might come back later, but they made the main loop hard to read and the aim is just to provide a model for teaching. +foutname is where a csv file will be written with values for plotting. + +xpltname is where a png file will be written with a plot of coordinates. + +Anything in the file after a hash (#) symbol will be treated as a comment. + +Any items which are mis-spelled will provoke an error. + +# Output + +If you are running with the graphical interface, the emphasis is on quickly playing with parameters. There are buttons which let you dump a plot to a file in .png format. + +Running without the graphical interface, you should specify `foutname.csv` and you will get a .csv file that you can feed into almost any plotting program. The format on each line looks like + + 0,0.1,5.8874,-1.5,0.5,1 + 1,0.1,5.9918,-1.73,0.5,1 + 2,0.1,5.9968,-1.73,0.514,1 + +which is + - step number + - temperature + - function value + - x1, x2, x3, ... + +So if you want to plot the function value as a function of step, you would plot column 1 on the x-axis and column 3 on the y-axis. To plot the coordinates in the example above, you would plot columns 4, 5 and 6 on the y-axis. + */ package ackley_doc diff --git a/examples/q1 b/examples/q1 new file mode 100644 index 0000000000000000000000000000000000000000..c34ce4d7a7635b65f6284711daed9e1fa0a454a9 --- /dev/null +++ b/examples/q1 @@ -0,0 +1,7 @@ +# For the Uebung +ini_temp 0.1 +n_step 500000 +x_ini -1.5,0.5,1 +x_delta 0.5 +seed 1699 +foutname q1.csv diff --git a/examples/q_2dlong b/examples/q_2dlong new file mode 100644 index 0000000000000000000000000000000000000000..e74a8f4a8f8aac0ea25125b11f592a04e23b2b0b --- /dev/null +++ b/examples/q_2dlong @@ -0,0 +1,6 @@ +vini_temp 0.1 +n_step 100000 +x_ini -0.5,0.5 +x_delta 0.5 +seed 1699 +foutname q2d.csv diff --git a/examples/q_2dlongbigstep b/examples/q_2dlongbigstep new file mode 100644 index 0000000000000000000000000000000000000000..a920699f52d8d2e678ff1ea1c9b541e8184e63c2 --- /dev/null +++ b/examples/q_2dlongbigstep @@ -0,0 +1,6 @@ +ini_temp 0.1 +n_step 100000 +x_ini -0.5,0.5 +x_delta 2 +seed 1699 +foutname q2dbigstep.csv diff --git a/examples/q_cold b/examples/q_cold new file mode 100644 index 0000000000000000000000000000000000000000..ebc2d32eaf984ac4760bd6f852e1f0995c4d2c68 --- /dev/null +++ b/examples/q_cold @@ -0,0 +1,7 @@ +# For the Uebung +ini_temp 0.01 +n_step 50000 +x_ini -5,-4,-3,-2,-1,0,1,2,3,4,5 +x_delta 0.5 +seed 1699 +foutname q1.csv diff --git a/examples/q_distribution b/examples/q_distribution new file mode 100644 index 0000000000000000000000000000000000000000..063b6eeeb7fc45eb7bb579a82a8cda1ae84a298f --- /dev/null +++ b/examples/q_distribution @@ -0,0 +1,6 @@ +ini_temp 0.1 +n_step 10000 +x_ini -1,1 +x_delta 0.5 +seed 1699 +foutname q_dist.csv diff --git a/examples/q_entropy b/examples/q_entropy new file mode 100644 index 0000000000000000000000000000000000000000..c08ef8d6168412e53908af1e43dda2e38ad995a8 --- /dev/null +++ b/examples/q_entropy @@ -0,0 +1,6 @@ +ini_temp 5 +n_step 50000 +x_ini -1,0,1 +x_delta 0.5 +seed 1699 +foutname q_dist.csv diff --git a/examples/q_equil b/examples/q_equil new file mode 100644 index 0000000000000000000000000000000000000000..57c1aa434765e221701ce34de194c87bb74a448c --- /dev/null +++ b/examples/q_equil @@ -0,0 +1,7 @@ +# For the Uebung +ini_temp 0.1 +n_step 5000 +x_ini -5,-4,-3,-2,-1,0,1,2,3,4,5 +x_delta 0.5 +seed 1699 +foutname q1.csv