Example MCMU
Workflow
Generating a correlated datastream
Consider a datastream
generated by the following code snippet:
julia> stream_length = Int(2^24)
16777216
julia> datastream = zeros(Float64, stream_length);
julia> for idx in 1:stream_length
datastream[idx] = cos( π * idx / 8 ) + (idx % 4) * sin( π * idx / (4 + idx ÷ 16) )
end
The function above is crazy and meaningless and just something I made up with correlations. Now we are going to analyze it using both a TimeSeries
and an AccumulatedSeries
.
Initialization
One can initialize both MonteCarloMeasurement
s using the following pre-allocating constructors:
julia> t_series = TimeSeries("Time Series", stream_length);
julia> a_series = AccumulatedSeries("Accumulated Series", stream_length);
Note, one does not need to specify the stream_length
, but then there is no pre-allocated memory. The first argument, a String
representing the name
of a given MonteCarloMeasurement
is optional with the default being empty: ""
. However, this name
can prove helpful as labels in later analysis or for saving the data. We can retrieve it for an arbitrary MonteCarloMeasurement
using the name
function as:
julia> name(t_series) == "Time Series"
true
julia> name(a_series) == "Accumulated Series"
true
push!
ing data into the MonteCarloMeasurement
s
At this point, we must input the data from the datastream
into each measurement. We do this using the push!
functionality:
julia> push!(t_series, datastream);
julia> push!(a_series, datastream);
We note that it's also possible to push!
single values into MonteCarloMeasurement
s rather than a whole Vector
of values.
Analyzing the datastream
Finally, we are in a position to analyze the datastream
collected by either the TimeSeries
or the AccumulatedSeries
.
To do so, we can either apply a binning_analysis
like the following for the TimeSeries
:
julia> binning_analysis(t_series)
Binning Analysis Result: Plateau Present: true Fitted Rx Plateau: 65.94278612184964 Autocorrelation time τₓ: 32.47139306092482 Effective Datastream Length: 254420 Binning Analysis Mean: -0.0022815233362555834 Binning Analysis Error: 0.0014031757854593185
Similarly, we can apply it to the AccumulatedSeries
:
julia> binning_analysis(a_series)
Binning Analysis Result: Plateau Present: true Fitted Rx Plateau: 65.94278612184964 Autocorrelation time τₓ: 32.47139306092482 Effective Datastream Length: 254420 Binning Analysis Mean: -0.0022815233362555834 Binning Analysis Error: 0.0014031757854593185
Moreover, one can choose to export either MonteCarloMeasurement
with the measurement
function extended from the Measurements.jl
package.
julia> measurement(t_series)
-0.0023 ± 0.0014
julia> measurement(a_series)
-0.0023 ± 0.0014
Importantly, this then provides an interface between this MonteCarloMeasurementUncertainty.jl
package and the utilities found in the Measurements.jl
package since the return type of measurement
is given by
julia> typeof( measurement(t_series) )
Measurements.Measurement{Float64}
The measurement
function automatically calls binning_analysis
on any MonteCarloMeasurement
argument.