Do you have a stochastic trajectory of and need to compute or another arbitrary ? Then the function in this Python file will be useful for you. Estimating such an ensemble average from a time-trajectory are often used in soft-matter physics, e.g. to investigate diffusion of a particle .
Usage is very easy. You can run an example script (which shows a Matplotlib window) by simply running the script, i.e. >>> python ComputeStochasticMean.py
. For your own usage, you simply call the function
bins_out, result = compute_stochastic_mean(x,y,bins,func)
Here, x
is an instance of numpy.array
of N
elements and represents the time-like variable and y
is also a numpy array of N
elements and represents the coordinate-like variable ( in the above description). func
is a function which takes two arguments, namely . There are three possibilities for func
pre-defined, namely the identity (), the MSD () and the autocorrelator function ().
bins_out
and result
are a numpy array of length len(bins)-1
since the last bin in bins
does not have a right edge (and hence we cannot bin the data for the rightmost bin).
This is a single-file script. Just download and use right away!
GPL. When using, please cite C.A.Miermans.