# Sampling simulation steps logarithmically

The common case of for instance a Monte Carlo simulation is, if we want to run our simulation for $N$ steps, we define a delta $\Delta,$ such that $N/\Delta = n$ tells us the frequency with which we measure/evaluate quantities of interest during the MC run. For instance, say $N=1000,$ and we want to measure the average of an observable $f,$ after each $n=100$ steps (so here $\Delta=10$). The average is obtained by dividing $f$ by the number of times $f$ has been measured. This is linearly sampling the time or MC steps and the simulation looks schematically like (writing in python style):

interval = N/delta
f = 0
countmeasurement = 0
for mcstep in range(1,N):
interval -= 1
.
.
.
if interval == 0:
f += computef()
.
.
interval = N/delta
countmeasurement += 1
#save or print
print "steps ", mcstep, "average f ", f/countmeasurement


Question:

With this scheme, if later we plot $f$ as a function of MC-steps, on a log-log scaled plot, we will not have sampled the same amount of datapoints for each time scale as we sampled the total steps only linearly. How do we alter our sampling scheme, thus redefining interval, such that we gather the same number of datapoints for $f$ for each part (time-scale) of the log-log plot? Is it common to sample the MC-steps logarithmically in Monte Carlo simulations?

• Values that are uniform on a log scale have a constant ratio between them. So you could e.g. sample after 1 step, 2 steps, 4 steps, 8 steps, and so on. You could also choose a different ratio, e.g. 1, 3, 9, ... – user3883 Dec 22 '17 at 2:19

## 1 Answer

If you want your sampling over the (a,b) interval to appear uniform when viewed on a log-log scale, linearly interpolate the logarithms: samples = 10.^linspace(log10(a),log10(b)). This is basically what samples=logspace(a,b) does anyway.

• Thanks a lot for your answer. Right, so logspace is already an existing function (in numpy) for python, but how does one in general do this? In other words, how should my measurement interval be changed accordingly in the above scheme? – user929304 Dec 14 '17 at 13:10
• If i understand your intention, `a:=0, b:=Delta, intervals = logspace(a,b), and interval = intervals(mcstep)'. Just compute all the sample points up front, stash them in an array, then pull them out one at a time as you iterate. – rchilton1980 Dec 14 '17 at 14:12
• To further clarify, say my MC simulation is set to perform 100000 MC steps. If I want to sample linearly some quantity, for instance measuring something about the system after each 100 steps, then after each 100 steps I stop and measure, and resume. This means we perform 100000/100=1000 number of measurements (linearly equidistant in MC steps) during the simulation. Now for the same total number of MC steps, namely the 100000, how do I set the measuring intervals logarithmically instead of linearly? so that it turns out uniform on a log scale for each time-scale. – user929304 Dec 14 '17 at 14:25
• Dear rchilton, was my added clarification helpful? – user929304 Dec 19 '17 at 11:26
• If you want your timestamps t to be logarithmically spaced, either logspace() or linspace()'ing the logarithms will get you there. When you need to know the interval dt between two consecutive timestamps t[i] and t[i+1], just subtract them. Or, use diff() to precompute all these intervals up front. – rchilton1980 Dec 19 '17 at 13:23