ParaMonte Fortran 2.0.0
Parallel Monte Carlo and Machine Learning Library
See the latest version documentation.
pm_sampleACT::getACT Interface Reference

Generate and return the integrated auto-correlation time (ACT) of the discrete signal.
More...

Detailed Description

Generate and return the integrated auto-correlation time (ACT) of the discrete signal.

This generic interface a flexible wrapper for the lower-level potentially faster generic interface setACF.
See the documentation of the parent module pm_sampleACT for algorithmic details and auto-correlation definition.

Parameters
[in]seq: The input contiguous vector of arbitrary size (of minimum 2) of,
  1. type real of kind any supported by the processor (e.g., RK, RK32, RK64, or RK128),
containing the sequence auto-correlation time must be computed.
[in]weight: The input vector of type integer of default kind IK of the same size as the input seq, containing the weights of the corresponding elements of the input seq.
(optional, default = [(1, i = 1, size(seq))])
[in]method: The input scalar constant that can be:
  1. the constant batchMeans or an object of type batchMeans_type(size = size), implying that the returned ACT is computed using the BatchMeans method with the optionally specified size.
    If the size component of the input object of type batchMeans_type(size = size) is unset or 0, an appropriate default based on the length of the input sequence will be determined and used.
    This option offers a reasonable tradeoff between good estimate and computational efficiency.
    However, the results depend heavily on the specified batch size, hence, still underestimate the actual ACT.
  2. the constant batchMeansMax or an object of type batchMeans_type(smin, smax, step), implying that the returned ACT is computed as the maximum of the BatchMeans method for the specified range of batch sizes `getRange(batchMeans_type%smin, batchMeans_type%smax, batchMeans_type%step).
    If the components of the input object of type batchMeans_type(smin, smax, step) are unset (default), then smin and step will be both set to 1 and smax is set to size(seq) / 2.
    This option will likely yield the least biased results but will be computationally significantly more demanding.
  3. the constant cumSum or an object of type cumSum_type(signif), implying that the returned ACT is simply the cumulative sum of auto-correlations of the input sequence at all possible lags: act = 1 + 2 * sum(getACT(seq)).
    This option is merely provided for exploratory and education reasons.
  4. the constant cumSumMax or an object of type cumSumMax_type(smin, smax, step), implying that the returned ACT is computed as the maximum of the cumulative sum of auto-correlations of the input sequence at all possible lags.
    This option is merely provided for exploratory and education reasons.
    This option is merely provided for exploratory and education reasons.
(optional, default = batchMeans_type(size = size(seq)**0.66).)
Returns
act : The output scalar of the same type and kind as that of the input sequence, containing the estimated integrated autocorrelation time of the input sequence.


Possible calling interfaces

use pm_sampleACT, only: getACT
act = getACT(seq(:), method = method)
act = getACT(seq(:), weight, method = method)
Generate and return the integrated auto-correlation time (ACT) of the discrete signal.
This module contains classes and procedures for computing properties related to the auto correlation ...
Warning
The condition 1 < methodsmin must hold for the corresponding input arguments.
The condition 0 < methodsignif must hold for the corresponding input arguments.
The condition size(weight) == size(seq) must hold for the corresponding input arguments.
The condition methodsmin <= methodsmax <= size(seq, 1) / 2 must hold for the corresponding input arguments.
The condition methodsize * 2 < sum(weight) must hold for the corresponding input arguments, otherwise sum(weight) will be returned as the act.
The condition 1 < size(seq) must hold for the corresponding input arguments, otherwise act will be set to lenseq on return.
The condition 0 < methodstep must hold for the corresponding input arguments.
The condition 0 < methodsize must hold for the corresponding input arguments.
Remarks
The procedures under discussion are impure.
See also
getACT
getACF
setACF
getCor
setCor
getRho
setRho
getCov
setCov
setECDF
getMean
setMean
getShifted
setShifted
getVar
setVar


Example usage

1program example
2
3 use pm_kind, only: SK, IK, LK
4 use pm_io, only: getErrTableRead, TAB
9 use pm_sampleACT, only: getACT
10 use pm_io, only: display_type
11
12 implicit none
13
14 integer(IK) :: skip
15 type(display_type) :: disp
16 character(:), allocatable :: format
17 disp = display_type(file = "main.out.F90")
18
19 call disp%skip()
20 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
21 call disp%show("!Compute the cross-correlation of two samples.")
22 call disp%show("!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
23 call disp%skip()
24
25 block
26 use pm_kind, only: TKG => RKS ! All other real types are also supported.
27 real(TKG), allocatable :: table(:,:)
28 real(TKG) :: act
29 call disp%skip()
30 call disp%show("if (0 /= getErrTableRead(SK_'duluth.txt', table, sep = TAB, roff = 1_IK)) error stop 'table read failed.'")
31 if (0 /= getErrTableRead(SK_'duluth.txt', table, sep = TAB, roff = 1_IK)) error stop 'table read failed.'
32 call disp%show("act = getACT(table(:,2)) ! temperature see visualization below.")
33 act = getACT(table(:,2)) ! temperature see visualization below.
34 call disp%show("act")
35 call disp%show( act )
36 call disp%show("act = getACT(table(:,2), method = batchMeans)")
37 act = getACT(table(:,2), method = batchMeans)
38 call disp%show("act")
39 call disp%show( act )
40 call disp%show("act = getACT(table(:,2), method = batchMeans_type(size = 365_IK))")
41 act = getACT(table(:,2), method = batchMeans_type(size = 365_IK))
42 call disp%show("act")
43 call disp%show( act )
44 call disp%show("act = getACT(table(:,2), method = batchMeansMax_type())")
45 act = getACT(table(:,2), method = batchMeansMax_type())
46 skip = int(act, IK)
47 call disp%show("act")
48 call disp%show( act )
49 call disp%show("act = getACT(table(:,2), method = batchMeansMax_type(step = 10_IK))")
50 act = getACT(table(:,2), method = batchMeansMax_type(step = 10_IK))
51 call disp%show("act")
52 call disp%show( act )
53 call disp%show("act = getACT(table(:,2), method = cumSum)")
54 act = getACT(table(:,2), method = cumSum)
55 call disp%show("act")
56 call disp%show( act )
57 call disp%show("act = getACT(table(:,2), method = cumSum_type(signif = 5_IK))")
58 act = getACT(table(:,2), method = cumSum_type(signif = 5_IK))
59 call disp%show("act")
60 call disp%show( act )
61 call disp%show("act = getACT(table(:,2), method = cumSum_type(signif = 0_IK))")
62 act = getACT(table(:,2), method = cumSum_type(signif = 0_IK))
63 call disp%show("act")
64 call disp%show( act )
65 call disp%show("act = getACT(table(:,2), method = cumSumMax)")
66 act = getACT(table(:,2), method = cumSumMax)
67 call disp%show("act")
68 call disp%show( act )
69 call disp%skip()
70 end block
71
72 block
73 use pm_arrayResize, only: setResized
74 use pm_io, only: getErrTableWrite, trans
75 use pm_arrayRange, only: getRange
76 use pm_kind, only: TKG => RKS ! All other real types are also supported.
77 character(:, SK), allocatable :: header
78 integer(IK), allocatable :: sbatch(:)
79 real(TKG), allocatable :: output(:,:)
80 real(TKG), allocatable :: table(:,:)
81 integer(IK) :: ibatch
82 if (0 /= getErrTableRead(SK_'duluth.txt', table, header, sep = TAB)) error stop 'table read failed.'
83 sbatch = getRange(2_IK, size(table, 1, IK) / 2_IK)
84 call setResized(output, [size(sbatch, 1, IK), 2_IK])
85 do ibatch = 1, size(sbatch, 1, IK)
86 output(ibatch, 1) = sbatch(ibatch)
87 output(ibatch, 2) = getACT(table(:, 2), batchMeans_type(sbatch(ibatch)))
88 end do
89 if (0 /= getErrTableWrite(SK_'getACT.duluth.batchMeans.txt', output, header = SK_"batchSize"//TAB//SK_"ACT", sep = TAB)) error stop 'table read failed.'
90 ! Write the thinned sample.
91 table = table(1 : size(table, 1, IK) : skip, :)
92 if (0 /= getErrTableWrite(SK_'getACT.duluth.thinned.txt', table, header//SK_" (BMM-thinned)", sep = TAB)) error stop 'table read failed.'
93 end block
94
95end program example
Generate minimally-spaced character, integer, real sequences or sequences at fixed intervals of size ...
Allocate or resize (shrink or expand) an input allocatable scalar string or array of rank 1....
Generate and return the iostat code resulting from reading the contents of the specified file or unit...
Definition: pm_io.F90:2390
Generate and return the iostat code resulting from writing the input table of rank 1 or 2 to the spec...
Definition: pm_io.F90:5940
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11726
This is a generic method of the derived type display_type with pass attribute.
Definition: pm_io.F90:11508
This module contains procedures and generic interfaces for generating ranges of discrete character,...
This module contains procedures and generic interfaces for resizing allocatable arrays of various typ...
This module contains classes and procedures for input/output (IO) or generic display operations on st...
Definition: pm_io.F90:252
character(1, SK), parameter TAB
The scalar character of default kind SK of len = 4 representing representing ASCII character: Horizon...
Definition: pm_io.F90:336
type(display_type) disp
This is a scalar module variable an object of type display_type for general display.
Definition: pm_io.F90:11393
This module defines the relevant Fortran kind type-parameters frequently used in the ParaMonte librar...
Definition: pm_kind.F90:268
integer, parameter LK
The default logical kind in the ParaMonte library: kind(.true.) in Fortran, kind(....
Definition: pm_kind.F90:541
integer, parameter IK
The default integer kind in the ParaMonte library: int32 in Fortran, c_int32_t in C-Fortran Interoper...
Definition: pm_kind.F90:540
integer, parameter SK
The default character kind in the ParaMonte library: kind("a") in Fortran, c_char in C-Fortran Intero...
Definition: pm_kind.F90:539
integer, parameter RKS
The single-precision real kind in Fortran mode. On most platforms, this is an 32-bit real kind.
Definition: pm_kind.F90:567
type(batchMeansMax_type), parameter batchMeansMax
type(batchMeans_type), parameter batchMeans
type(cumSumMax_type), parameter cumSumMax
type(cumSum_type), parameter cumSum
Generate and return an object of type display_type.
Definition: pm_io.F90:10282

Example Unix compile command via Intel ifort compiler
1#!/usr/bin/env sh
2rm main.exe
3ifort -fpp -standard-semantics -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example Windows Batch compile command via Intel ifort compiler
1del main.exe
2set PATH=..\..\..\lib;%PATH%
3ifort /fpp /standard-semantics /O3 /I:..\..\..\include main.F90 ..\..\..\lib\libparamonte*.lib /exe:main.exe
4main.exe

Example Unix / MinGW compile command via GNU gfortran compiler
1#!/usr/bin/env sh
2rm main.exe
3gfortran -cpp -ffree-line-length-none -O3 -Wl,-rpath,../../../lib -I../../../inc main.F90 ../../../lib/libparamonte* -o main.exe
4./main.exe

Example output
1
2!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3!Compute the cross-correlation of two samples.
4!%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5
6
7if (0 /= getErrTableRead(SK_'duluth.txt', table, sep = TAB, roff = 1_IK)) error stop 'table read failed.'
8act = getACT(table(:,2)) ! temperature see visualization below.
9act
10+12.7669811
11act = getACT(table(:,2), method = batchMeans)
12act
13+12.7669811
14act = getACT(table(:,2), method = batchMeans_type(size = 365_IK))
15act
16+3.07212925
17act = getACT(table(:,2), method = batchMeansMax_type())
18act
19+87.1719818
20act = getACT(table(:,2), method = batchMeansMax_type(step = 10_IK))
21act
22+74.3042755
23act = getACT(table(:,2), method = cumSum)
24act
25+99.3170776
26act = getACT(table(:,2), method = cumSum_type(signif = 5_IK))
27act
28+99.0806656
29act = getACT(table(:,2), method = cumSum_type(signif = 0_IK))
30act
31+99.3170776
32act = getACT(table(:,2), method = cumSumMax)
33act
34+99.3170776
35
36

Postprocessing of the example output
1#!/usr/bin/env python
2
3import matplotlib.pyplot as plt
4import pandas as pd
5import numpy as np
6import glob
7import sys
8import os
9
10linewidth = 2
11fontsize = 17
12
13parent = os.path.basename(os.path.dirname(__file__))
14pattern = parent + "*.txt"
15files = glob.glob(pattern)
16
17for file in files:
18
19 df = pd.read_csv(file, delimiter = "\t")
20
21 #print(df.values)
22 fig = plt.figure(figsize = (8, 6))
23 ax = plt.subplot(1,1,1)
24 ax.plot ( df.values[:, 0]
25 , df.values[:, 1]
26 , zorder = 1000
27 )
28 #ax.scatter ( df.values[:, 0]
29 # , df.values[:, 1]
30 # , zorder = 1000
31 # , s = 1
32 # )
33 plt.minorticks_on()
34 ax.set_xlabel(df.columns.values[0], fontsize = 17)
35 ax.set_ylabel(df.columns.values[1], fontsize = 17)
36 ax.tick_params(axis = "x", which = "minor")
37 ax.tick_params(axis = "y", which = "minor")
38 plt.grid(visible = True, which = "both", axis = "both", color = "0.85", linestyle = "-")
39 ax.legend(["Duluth, MN"], fontsize = fontsize)
40 plt.tight_layout()
41 plt.savefig(file.replace(".txt",".png"))

Visualization of the example output
Test:
test_pm_sampleACT
Internal naming convention:
The following illustrates the internal naming convention used for the procedures within this generic interface.
getACT_CSD_WTI_D1_CK5()
||| ||| ||| || |||
||| ||| ||| || The type and kind parameters of the input sequence.
||| ||| ||| The dimension of the input sequence `seq`.
||| ||| Weight type: WTTI => integer weight, ONE => no weight.
||| The method: BMD => BatchMeans Default, BMM => BatchMeans Maximum, CSD => CumSum Default, CSM => CumSum Maximum
ACF: Cross-Correlation Function.
Todo:
High Priority: The performance of the implementations of this generic interface can be improved by minimizing allocations and converting function calls to subroutine calls.


Final Remarks


If you believe this algorithm or its documentation can be improved, we appreciate your contribution and help to edit this page's documentation and source file on GitHub.
For details on the naming abbreviations, see this page.
For details on the naming conventions, see this page.
This software is distributed under the MIT license with additional terms outlined below.

  1. If you use any parts or concepts from this library to any extent, please acknowledge the usage by citing the relevant publications of the ParaMonte library.
  2. If you regenerate any parts/ideas from this library in a programming environment other than those currently supported by this ParaMonte library (i.e., other than C, C++, Fortran, MATLAB, Python, R), please also ask the end users to cite this original ParaMonte library.

This software is available to the public under a highly permissive license.
Help us justify its continued development and maintenance by acknowledging its benefit to society, distributing it, and contributing to it.

Author:
Fatemeh Bagheri, Monday 02:15 AM, September 27, 2021, Dallas, TX

Definition at line 220 of file pm_sampleACT.F90.


The documentation for this interface was generated from the following file: