westpa 2022.10__cp312-cp312-macosx_10_9_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of westpa might be problematic. Click here for more details.
- westpa/__init__.py +14 -0
- westpa/_version.py +21 -0
- westpa/analysis/__init__.py +5 -0
- westpa/analysis/core.py +746 -0
- westpa/analysis/statistics.py +27 -0
- westpa/analysis/trajectories.py +360 -0
- westpa/cli/__init__.py +0 -0
- westpa/cli/core/__init__.py +0 -0
- westpa/cli/core/w_fork.py +152 -0
- westpa/cli/core/w_init.py +230 -0
- westpa/cli/core/w_run.py +77 -0
- westpa/cli/core/w_states.py +212 -0
- westpa/cli/core/w_succ.py +99 -0
- westpa/cli/core/w_truncate.py +59 -0
- westpa/cli/tools/__init__.py +0 -0
- westpa/cli/tools/ploterr.py +506 -0
- westpa/cli/tools/plothist.py +706 -0
- westpa/cli/tools/w_assign.py +596 -0
- westpa/cli/tools/w_bins.py +166 -0
- westpa/cli/tools/w_crawl.py +119 -0
- westpa/cli/tools/w_direct.py +547 -0
- westpa/cli/tools/w_dumpsegs.py +94 -0
- westpa/cli/tools/w_eddist.py +506 -0
- westpa/cli/tools/w_fluxanl.py +378 -0
- westpa/cli/tools/w_ipa.py +833 -0
- westpa/cli/tools/w_kinavg.py +127 -0
- westpa/cli/tools/w_kinetics.py +96 -0
- westpa/cli/tools/w_multi_west.py +414 -0
- westpa/cli/tools/w_ntop.py +213 -0
- westpa/cli/tools/w_pdist.py +515 -0
- westpa/cli/tools/w_postanalysis_matrix.py +82 -0
- westpa/cli/tools/w_postanalysis_reweight.py +53 -0
- westpa/cli/tools/w_red.py +486 -0
- westpa/cli/tools/w_reweight.py +780 -0
- westpa/cli/tools/w_select.py +226 -0
- westpa/cli/tools/w_stateprobs.py +111 -0
- westpa/cli/tools/w_trace.py +599 -0
- westpa/core/__init__.py +0 -0
- westpa/core/_rc.py +673 -0
- westpa/core/binning/__init__.py +55 -0
- westpa/core/binning/_assign.cpython-312-darwin.so +0 -0
- westpa/core/binning/assign.py +449 -0
- westpa/core/binning/binless.py +96 -0
- westpa/core/binning/binless_driver.py +54 -0
- westpa/core/binning/binless_manager.py +190 -0
- westpa/core/binning/bins.py +47 -0
- westpa/core/binning/mab.py +427 -0
- westpa/core/binning/mab_driver.py +54 -0
- westpa/core/binning/mab_manager.py +198 -0
- westpa/core/data_manager.py +1694 -0
- westpa/core/extloader.py +74 -0
- westpa/core/h5io.py +995 -0
- westpa/core/kinetics/__init__.py +24 -0
- westpa/core/kinetics/_kinetics.cpython-312-darwin.so +0 -0
- westpa/core/kinetics/events.py +147 -0
- westpa/core/kinetics/matrates.py +156 -0
- westpa/core/kinetics/rate_averaging.py +266 -0
- westpa/core/progress.py +218 -0
- westpa/core/propagators/__init__.py +54 -0
- westpa/core/propagators/executable.py +715 -0
- westpa/core/reweight/__init__.py +14 -0
- westpa/core/reweight/_reweight.cpython-312-darwin.so +0 -0
- westpa/core/reweight/matrix.py +126 -0
- westpa/core/segment.py +119 -0
- westpa/core/sim_manager.py +830 -0
- westpa/core/states.py +359 -0
- westpa/core/systems.py +93 -0
- westpa/core/textio.py +74 -0
- westpa/core/trajectory.py +330 -0
- westpa/core/we_driver.py +908 -0
- westpa/core/wm_ops.py +43 -0
- westpa/core/yamlcfg.py +391 -0
- westpa/fasthist/__init__.py +34 -0
- westpa/fasthist/__main__.py +110 -0
- westpa/fasthist/_fasthist.cpython-312-darwin.so +0 -0
- westpa/mclib/__init__.py +264 -0
- westpa/mclib/__main__.py +28 -0
- westpa/mclib/_mclib.cpython-312-darwin.so +0 -0
- westpa/oldtools/__init__.py +4 -0
- westpa/oldtools/aframe/__init__.py +35 -0
- westpa/oldtools/aframe/atool.py +75 -0
- westpa/oldtools/aframe/base_mixin.py +26 -0
- westpa/oldtools/aframe/binning.py +178 -0
- westpa/oldtools/aframe/data_reader.py +560 -0
- westpa/oldtools/aframe/iter_range.py +200 -0
- westpa/oldtools/aframe/kinetics.py +117 -0
- westpa/oldtools/aframe/mcbs.py +146 -0
- westpa/oldtools/aframe/output.py +39 -0
- westpa/oldtools/aframe/plotting.py +90 -0
- westpa/oldtools/aframe/trajwalker.py +126 -0
- westpa/oldtools/aframe/transitions.py +469 -0
- westpa/oldtools/cmds/__init__.py +0 -0
- westpa/oldtools/cmds/w_ttimes.py +358 -0
- westpa/oldtools/files.py +34 -0
- westpa/oldtools/miscfn.py +23 -0
- westpa/oldtools/stats/__init__.py +4 -0
- westpa/oldtools/stats/accumulator.py +35 -0
- westpa/oldtools/stats/edfs.py +129 -0
- westpa/oldtools/stats/mcbs.py +89 -0
- westpa/tools/__init__.py +33 -0
- westpa/tools/binning.py +472 -0
- westpa/tools/core.py +340 -0
- westpa/tools/data_reader.py +159 -0
- westpa/tools/dtypes.py +31 -0
- westpa/tools/iter_range.py +198 -0
- westpa/tools/kinetics_tool.py +340 -0
- westpa/tools/plot.py +283 -0
- westpa/tools/progress.py +17 -0
- westpa/tools/selected_segs.py +154 -0
- westpa/tools/wipi.py +751 -0
- westpa/trajtree/__init__.py +4 -0
- westpa/trajtree/_trajtree.cpython-312-darwin.so +0 -0
- westpa/trajtree/trajtree.py +117 -0
- westpa/westext/__init__.py +0 -0
- westpa/westext/adaptvoronoi/__init__.py +3 -0
- westpa/westext/adaptvoronoi/adaptVor_driver.py +214 -0
- westpa/westext/hamsm_restarting/__init__.py +3 -0
- westpa/westext/hamsm_restarting/example_overrides.py +35 -0
- westpa/westext/hamsm_restarting/restart_driver.py +1165 -0
- westpa/westext/stringmethod/__init__.py +11 -0
- westpa/westext/stringmethod/fourier_fitting.py +69 -0
- westpa/westext/stringmethod/string_driver.py +253 -0
- westpa/westext/stringmethod/string_method.py +306 -0
- westpa/westext/weed/BinCluster.py +180 -0
- westpa/westext/weed/ProbAdjustEquil.py +100 -0
- westpa/westext/weed/UncertMath.py +247 -0
- westpa/westext/weed/__init__.py +10 -0
- westpa/westext/weed/weed_driver.py +182 -0
- westpa/westext/wess/ProbAdjust.py +101 -0
- westpa/westext/wess/__init__.py +6 -0
- westpa/westext/wess/wess_driver.py +207 -0
- westpa/work_managers/__init__.py +57 -0
- westpa/work_managers/core.py +396 -0
- westpa/work_managers/environment.py +134 -0
- westpa/work_managers/mpi.py +318 -0
- westpa/work_managers/processes.py +187 -0
- westpa/work_managers/serial.py +28 -0
- westpa/work_managers/threads.py +79 -0
- westpa/work_managers/zeromq/__init__.py +20 -0
- westpa/work_managers/zeromq/core.py +641 -0
- westpa/work_managers/zeromq/node.py +131 -0
- westpa/work_managers/zeromq/work_manager.py +526 -0
- westpa/work_managers/zeromq/worker.py +320 -0
- westpa-2022.10.dist-info/AUTHORS +22 -0
- westpa-2022.10.dist-info/LICENSE +21 -0
- westpa-2022.10.dist-info/METADATA +183 -0
- westpa-2022.10.dist-info/RECORD +150 -0
- westpa-2022.10.dist-info/WHEEL +5 -0
- westpa-2022.10.dist-info/entry_points.txt +29 -0
- westpa-2022.10.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import h5py
|
|
2
|
+
import numpy as np
|
|
3
|
+
from scipy.signal import fftconvolve
|
|
4
|
+
from warnings import warn
|
|
5
|
+
|
|
6
|
+
import westpa
|
|
7
|
+
|
|
8
|
+
from westpa.core.data_manager import weight_dtype, n_iter_dtype, vstr_dtype
|
|
9
|
+
from westpa.core.we_driver import NewWeightEntry
|
|
10
|
+
from westpa.core import h5io
|
|
11
|
+
from westpa.tools import WESTTool, WESTDataReader, IterRangeSelection
|
|
12
|
+
from westpa.tools.dtypes import iter_block_ci_dtype as ci_dtype
|
|
13
|
+
import westpa.mclib as mclib
|
|
14
|
+
|
|
15
|
+
fluxentry_dtype = np.dtype([('n_iter', n_iter_dtype), ('flux', weight_dtype), ('count', np.uint)])
|
|
16
|
+
|
|
17
|
+
target_index_dtype = np.dtype(
|
|
18
|
+
[
|
|
19
|
+
('target_label', vstr_dtype),
|
|
20
|
+
('mean_flux', weight_dtype),
|
|
21
|
+
('mean_flux_ci_lb', weight_dtype),
|
|
22
|
+
('mean_flux_ci_ub', weight_dtype),
|
|
23
|
+
('mean_flux_correl_len', np.uintc),
|
|
24
|
+
]
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _extract_fluxes_fileversion_lt_7(iter_start, iter_stop, data_manager):
|
|
29
|
+
'''Extract fluxes from old format, where groups for iterations where recyling
|
|
30
|
+
occurs contain a 'recycling' table.'''
|
|
31
|
+
|
|
32
|
+
assert data_manager.we_h5file_version < 7
|
|
33
|
+
|
|
34
|
+
iter_count = iter_stop - iter_start
|
|
35
|
+
target_count = data_manager.get_iter_group(iter_start)['recycling'].shape[0]
|
|
36
|
+
fluxdata = np.zeros((iter_count,), dtype=fluxentry_dtype)
|
|
37
|
+
|
|
38
|
+
if data_manager.we_h5file_version < 5:
|
|
39
|
+
flux_field = 'weight'
|
|
40
|
+
else:
|
|
41
|
+
flux_field = 'flux'
|
|
42
|
+
|
|
43
|
+
fluxdata = {itarget: np.zeros((iter_count,), dtype=fluxentry_dtype) for itarget in range(target_count)}
|
|
44
|
+
|
|
45
|
+
for iiter, n_iter in enumerate(range(iter_start, iter_stop)):
|
|
46
|
+
rdata = data_manager.get_iter_group(n_iter)['recycling']
|
|
47
|
+
for itarget in range(target_count):
|
|
48
|
+
fluxdata[itarget][iiter]['n_iter'] = n_iter
|
|
49
|
+
fluxdata[itarget][iiter]['flux'] = rdata[itarget][flux_field]
|
|
50
|
+
fluxdata[itarget][iiter]['count'] = rdata[itarget]['count']
|
|
51
|
+
del rdata
|
|
52
|
+
|
|
53
|
+
return fluxdata
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _extract_fluxes_fileversion_7(iter_start, iter_stop, data_manager):
|
|
57
|
+
'''Extract fluxes from HDF5 file version 7, where recycling information is
|
|
58
|
+
stored in the "new_weights" group of the iteration *following* recycling
|
|
59
|
+
events.'''
|
|
60
|
+
|
|
61
|
+
assert data_manager.we_h5file_version >= 7
|
|
62
|
+
|
|
63
|
+
iter_count = iter_stop - iter_start
|
|
64
|
+
iters = np.arange(iter_start, iter_stop, dtype=n_iter_dtype)
|
|
65
|
+
|
|
66
|
+
# for each target by name, collect the iterations, fluxes, and counts
|
|
67
|
+
# This is not the most foolproof way to do this, but it's good enough, and fast.
|
|
68
|
+
# The most correct way to do this is tracing trajectories,
|
|
69
|
+
# and warning if the boundary conditions change during the trace,
|
|
70
|
+
# but that's for another tool.
|
|
71
|
+
by_target = {}
|
|
72
|
+
|
|
73
|
+
for iiter, n_iter in enumerate(range(iter_start, iter_stop)):
|
|
74
|
+
target_states = data_manager.get_target_states(n_iter)
|
|
75
|
+
try:
|
|
76
|
+
new_weight_index = data_manager.get_iter_group(n_iter + 1)['new_weights']['index']
|
|
77
|
+
except KeyError:
|
|
78
|
+
# no recycling data available
|
|
79
|
+
continue
|
|
80
|
+
|
|
81
|
+
for tstate in target_states:
|
|
82
|
+
try:
|
|
83
|
+
target_info = by_target[tstate.label]
|
|
84
|
+
except KeyError:
|
|
85
|
+
# State not seen before
|
|
86
|
+
target_info = by_target[tstate.label] = np.zeros((iter_count,), dtype=fluxentry_dtype)
|
|
87
|
+
# If the target happens not to exist in an iteration (for whatever reason),
|
|
88
|
+
# store a count of -1 as a sentinel
|
|
89
|
+
target_info['count'][:] = -1
|
|
90
|
+
target_info['n_iter'][:] = iters[:]
|
|
91
|
+
|
|
92
|
+
recycled_from_tstate = (new_weight_index['source_type'] == NewWeightEntry.NW_SOURCE_RECYCLED) & (
|
|
93
|
+
new_weight_index['target_state_id'] == tstate.state_id
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
recycle_count = recycled_from_tstate.sum()
|
|
97
|
+
target_info['count'][iiter] = recycle_count
|
|
98
|
+
if recycle_count:
|
|
99
|
+
# flux is in units of per tau
|
|
100
|
+
target_info['flux'][iiter] = new_weight_index[recycled_from_tstate]['weight'].sum()
|
|
101
|
+
|
|
102
|
+
del new_weight_index, target_states
|
|
103
|
+
|
|
104
|
+
# Find the last contiguous run where target is available
|
|
105
|
+
for target_label in by_target:
|
|
106
|
+
fluxdata = by_target[target_label]
|
|
107
|
+
by_target[target_label] = fluxdata[np.searchsorted(fluxdata['count'], [0])[0] :]
|
|
108
|
+
|
|
109
|
+
return by_target
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def extract_fluxes(iter_start=None, iter_stop=None, data_manager=None):
|
|
113
|
+
'''Extract flux values from the WEST HDF5 file for iterations >= iter_start
|
|
114
|
+
and < iter_stop, optionally using another data manager instance instead of the
|
|
115
|
+
global one returned by ``westpa.rc.get_data_manager()``.
|
|
116
|
+
|
|
117
|
+
Returns a dictionary mapping target names (if available, target index otherwise)
|
|
118
|
+
to a 1-D array of type ``fluxentry_dtype``, which contains columns for iteration
|
|
119
|
+
number, flux, and count.
|
|
120
|
+
'''
|
|
121
|
+
|
|
122
|
+
data_manager = data_manager or westpa.rc.get_data_manager()
|
|
123
|
+
iter_start = iter_start or 1
|
|
124
|
+
iter_stop = iter_stop or data_manager.current_iteration
|
|
125
|
+
|
|
126
|
+
if data_manager.we_h5file_version < 7:
|
|
127
|
+
return _extract_fluxes_fileversion_lt_7(iter_start, iter_stop, data_manager)
|
|
128
|
+
else:
|
|
129
|
+
return _extract_fluxes_fileversion_7(iter_start, iter_stop, data_manager)
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
class WFluxanlTool(WESTTool):
|
|
133
|
+
prog = 'w_fluxanl'
|
|
134
|
+
description = '''\
|
|
135
|
+
Extract fluxes into pre-defined target states from WEST data,
|
|
136
|
+
average, and construct confidence intervals. Monte Carlo bootstrapping
|
|
137
|
+
is used to account for the correlated and possibly non-Gaussian statistical
|
|
138
|
+
error in flux measurements.
|
|
139
|
+
|
|
140
|
+
All non-graphical output (including that to the terminal and HDF5) assumes that
|
|
141
|
+
the propagation/resampling period ``tau`` is equal to unity; to obtain results
|
|
142
|
+
in familiar units, divide all fluxes and multiply all correlation lengths by
|
|
143
|
+
the true value of ``tau``.
|
|
144
|
+
'''
|
|
145
|
+
|
|
146
|
+
output_format_version = 2
|
|
147
|
+
|
|
148
|
+
def __init__(self):
|
|
149
|
+
super().__init__()
|
|
150
|
+
self.data_reader = WESTDataReader()
|
|
151
|
+
self.iter_range = IterRangeSelection()
|
|
152
|
+
self.output_h5file = None
|
|
153
|
+
self.output_group = None
|
|
154
|
+
self.target_groups = {}
|
|
155
|
+
|
|
156
|
+
self.fluxdata = {}
|
|
157
|
+
|
|
158
|
+
self.alpha = None
|
|
159
|
+
self.autocorrel_alpha = None
|
|
160
|
+
self.n_sets = None
|
|
161
|
+
self.do_evol = False
|
|
162
|
+
self.evol_step = 1
|
|
163
|
+
|
|
164
|
+
def add_args(self, parser):
|
|
165
|
+
self.data_reader.add_args(parser)
|
|
166
|
+
self.iter_range.add_args(parser)
|
|
167
|
+
ogroup = parser.add_argument_group('output options')
|
|
168
|
+
ogroup.add_argument(
|
|
169
|
+
'-o',
|
|
170
|
+
'--output',
|
|
171
|
+
default='fluxanl.h5',
|
|
172
|
+
help='Store intermediate data and analysis results to OUTPUT (default: %(default)s).',
|
|
173
|
+
)
|
|
174
|
+
cgroup = parser.add_argument_group('calculation options')
|
|
175
|
+
cgroup.add_argument(
|
|
176
|
+
'--disable-bootstrap',
|
|
177
|
+
'-db',
|
|
178
|
+
dest='bootstrap',
|
|
179
|
+
action='store_const',
|
|
180
|
+
const=False,
|
|
181
|
+
help='''Enable the use of Monte Carlo Block Bootstrapping.''',
|
|
182
|
+
)
|
|
183
|
+
cgroup.add_argument(
|
|
184
|
+
'--disable-correl',
|
|
185
|
+
'-dc',
|
|
186
|
+
dest='correl',
|
|
187
|
+
action='store_const',
|
|
188
|
+
const=False,
|
|
189
|
+
help='''Disable the correlation analysis.''',
|
|
190
|
+
)
|
|
191
|
+
cgroup.add_argument(
|
|
192
|
+
'-a',
|
|
193
|
+
'--alpha',
|
|
194
|
+
type=float,
|
|
195
|
+
default=0.05,
|
|
196
|
+
help='''Calculate a (1-ALPHA) confidence interval on the average flux'
|
|
197
|
+
(default: %(default)s)''',
|
|
198
|
+
)
|
|
199
|
+
cgroup.add_argument(
|
|
200
|
+
'--autocorrel-alpha',
|
|
201
|
+
type=float,
|
|
202
|
+
dest='acalpha',
|
|
203
|
+
metavar='ACALPHA',
|
|
204
|
+
help='''Evaluate autocorrelation of flux to (1-ACALPHA) significance.
|
|
205
|
+
Note that too small an ACALPHA will result in failure to detect autocorrelation
|
|
206
|
+
in a noisy flux signal. (Default: same as ALPHA.)''',
|
|
207
|
+
)
|
|
208
|
+
cgroup.add_argument(
|
|
209
|
+
'-N', '--nsets', type=int, help='''Use NSETS samples for bootstrapping (default: chosen based on ALPHA)'''
|
|
210
|
+
)
|
|
211
|
+
cgroup.add_argument(
|
|
212
|
+
'--evol',
|
|
213
|
+
action='store_true',
|
|
214
|
+
dest='do_evol',
|
|
215
|
+
help='''Calculate time evolution of flux confidence intervals (expensive).''',
|
|
216
|
+
)
|
|
217
|
+
cgroup.add_argument(
|
|
218
|
+
'--evol-step',
|
|
219
|
+
type=int,
|
|
220
|
+
default=1,
|
|
221
|
+
metavar='ESTEP',
|
|
222
|
+
help='''Calculate time evolution of flux confidence intervals every ESTEP
|
|
223
|
+
iterations (default: %(default)s)''',
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
def process_args(self, args):
|
|
227
|
+
self.data_reader.process_args(args)
|
|
228
|
+
self.data_reader.open()
|
|
229
|
+
self.iter_range.data_manager = self.data_reader
|
|
230
|
+
self.iter_range.process_args(args)
|
|
231
|
+
|
|
232
|
+
self.output_h5file = h5py.File(args.output, 'w')
|
|
233
|
+
|
|
234
|
+
self.alpha = args.alpha
|
|
235
|
+
# Disable the bootstrap or the correlation analysis.
|
|
236
|
+
self.mcbs_enable = args.bootstrap if args.bootstrap is not None else True
|
|
237
|
+
self.do_correl = args.correl if args.correl is not None else True
|
|
238
|
+
self.autocorrel_alpha = args.acalpha or self.alpha
|
|
239
|
+
self.n_sets = args.nsets or mclib.get_bssize(self.alpha)
|
|
240
|
+
|
|
241
|
+
self.do_evol = args.do_evol
|
|
242
|
+
self.evol_step = args.evol_step or 1
|
|
243
|
+
|
|
244
|
+
def calc_store_flux_data(self):
|
|
245
|
+
westpa.rc.pstatus(
|
|
246
|
+
'Calculating mean flux and confidence intervals for iterations [{},{})'.format(
|
|
247
|
+
self.iter_range.iter_start, self.iter_range.iter_stop
|
|
248
|
+
)
|
|
249
|
+
)
|
|
250
|
+
|
|
251
|
+
fluxdata = extract_fluxes(self.iter_range.iter_start, self.iter_range.iter_stop, self.data_reader)
|
|
252
|
+
|
|
253
|
+
# Create a group to store data in
|
|
254
|
+
output_group = h5io.create_hdf5_group(self.output_h5file, 'target_flux', replace=False, creating_program=self.prog)
|
|
255
|
+
self.output_group = output_group
|
|
256
|
+
output_group.attrs['version_code'] = self.output_format_version
|
|
257
|
+
self.iter_range.record_data_iter_range(output_group)
|
|
258
|
+
|
|
259
|
+
n_targets = len(fluxdata)
|
|
260
|
+
index = np.empty((len(fluxdata),), dtype=target_index_dtype)
|
|
261
|
+
avg_fluxdata = np.empty((n_targets,), dtype=ci_dtype)
|
|
262
|
+
|
|
263
|
+
for itarget, (target_label, target_fluxdata) in enumerate(fluxdata.items()):
|
|
264
|
+
# Create group and index entry
|
|
265
|
+
index[itarget]['target_label'] = str(target_label)
|
|
266
|
+
target_group = output_group.create_group('target_{}'.format(itarget))
|
|
267
|
+
|
|
268
|
+
self.target_groups[target_label] = target_group
|
|
269
|
+
|
|
270
|
+
# Store per-iteration values
|
|
271
|
+
target_group['n_iter'] = target_fluxdata['n_iter']
|
|
272
|
+
target_group['count'] = target_fluxdata['count']
|
|
273
|
+
target_group['flux'] = target_fluxdata['flux']
|
|
274
|
+
h5io.label_axes(target_group['flux'], ['n_iter'], units=['tau^-1'])
|
|
275
|
+
|
|
276
|
+
# Calculate flux autocorrelation
|
|
277
|
+
fluxes = target_fluxdata['flux']
|
|
278
|
+
mean_flux = fluxes.mean()
|
|
279
|
+
fmm = fluxes - mean_flux
|
|
280
|
+
acorr = fftconvolve(fmm, fmm[::-1])
|
|
281
|
+
acorr = acorr[len(acorr) // 2 :]
|
|
282
|
+
acorr /= acorr[0]
|
|
283
|
+
acorr_ds = target_group.create_dataset('flux_autocorrel', data=acorr)
|
|
284
|
+
h5io.label_axes(acorr_ds, ['lag'], ['tau'])
|
|
285
|
+
|
|
286
|
+
# Calculate overall averages and CIs
|
|
287
|
+
# avg, lb_ci, ub_ci, correl_len = mclib.mcbs_ci_correl(fluxes, np.mean, self.alpha, self.n_sets,
|
|
288
|
+
# autocorrel_alpha=self.autocorrel_alpha, subsample=np.mean)
|
|
289
|
+
avg, lb_ci, ub_ci, sterr, correl_len = mclib.mcbs_ci_correl(
|
|
290
|
+
{'dataset': fluxes},
|
|
291
|
+
estimator=(lambda stride, dataset: np.mean(dataset)),
|
|
292
|
+
alpha=self.alpha,
|
|
293
|
+
n_sets=self.n_sets,
|
|
294
|
+
autocorrel_alpha=self.autocorrel_alpha,
|
|
295
|
+
subsample=np.mean,
|
|
296
|
+
do_correl=self.do_correl,
|
|
297
|
+
mcbs_enable=self.mcbs_enable,
|
|
298
|
+
)
|
|
299
|
+
avg_fluxdata[itarget] = (self.iter_range.iter_start, self.iter_range.iter_stop, avg, lb_ci, ub_ci, sterr, correl_len)
|
|
300
|
+
westpa.rc.pstatus('target {!r}:'.format(target_label))
|
|
301
|
+
westpa.rc.pstatus(' correlation length = {} tau'.format(correl_len))
|
|
302
|
+
westpa.rc.pstatus(' mean flux and CI = {:e} ({:e},{:e}) tau^(-1)'.format(avg, lb_ci, ub_ci))
|
|
303
|
+
index[itarget]['mean_flux'] = avg
|
|
304
|
+
index[itarget]['mean_flux_ci_lb'] = lb_ci
|
|
305
|
+
index[itarget]['mean_flux_ci_ub'] = ub_ci
|
|
306
|
+
index[itarget]['mean_flux_correl_len'] = correl_len
|
|
307
|
+
|
|
308
|
+
# Write index and summary
|
|
309
|
+
index_ds = output_group.create_dataset('index', data=index)
|
|
310
|
+
index_ds.attrs['mcbs_alpha'] = self.alpha
|
|
311
|
+
index_ds.attrs['mcbs_autocorrel_alpha'] = self.autocorrel_alpha
|
|
312
|
+
index_ds.attrs['mcbs_n_sets'] = self.n_sets
|
|
313
|
+
|
|
314
|
+
self.fluxdata = fluxdata
|
|
315
|
+
self.output_h5file['avg_flux'] = avg_fluxdata
|
|
316
|
+
|
|
317
|
+
def calc_evol_flux(self):
|
|
318
|
+
westpa.rc.pstatus(
|
|
319
|
+
'Calculating cumulative evolution of flux confidence intervals every {} iteration(s)'.format(self.evol_step)
|
|
320
|
+
)
|
|
321
|
+
|
|
322
|
+
for itarget, (target_label, target_fluxdata) in enumerate(self.fluxdata.items()):
|
|
323
|
+
fluxes = target_fluxdata['flux']
|
|
324
|
+
target_group = self.target_groups[target_label]
|
|
325
|
+
iter_start = target_group['n_iter'][0]
|
|
326
|
+
iter_stop = target_group['n_iter'][-1]
|
|
327
|
+
iter_count = iter_stop - iter_start
|
|
328
|
+
n_blocks = iter_count // self.evol_step
|
|
329
|
+
if iter_count % self.evol_step > 0:
|
|
330
|
+
n_blocks += 1
|
|
331
|
+
|
|
332
|
+
cis = np.empty((n_blocks,), dtype=ci_dtype)
|
|
333
|
+
|
|
334
|
+
for iblock in range(n_blocks):
|
|
335
|
+
block_iter_stop = min(iter_start + (iblock + 1) * self.evol_step, iter_stop)
|
|
336
|
+
istop = min((iblock + 1) * self.evol_step, len(target_fluxdata['flux']))
|
|
337
|
+
fluxes = target_fluxdata['flux'][:istop]
|
|
338
|
+
|
|
339
|
+
# avg, ci_lb, ci_ub, correl_len = mclib.mcbs_ci_correl(fluxes, np.mean, self.alpha, self.n_sets,
|
|
340
|
+
# autocorrel_alpha = self.autocorrel_alpha,
|
|
341
|
+
# subsample=np.mean)
|
|
342
|
+
avg, ci_lb, ci_ub, sterr, correl_len = mclib.mcbs_ci_correl(
|
|
343
|
+
{'dataset': fluxes},
|
|
344
|
+
estimator=(lambda stride, dataset: np.mean(dataset)),
|
|
345
|
+
alpha=self.alpha,
|
|
346
|
+
n_sets=self.n_sets,
|
|
347
|
+
autocorrel_alpha=self.autocorrel_alpha,
|
|
348
|
+
subsample=np.mean,
|
|
349
|
+
do_correl=self.do_correl,
|
|
350
|
+
mcbs_enable=self.mcbs_enable,
|
|
351
|
+
)
|
|
352
|
+
cis[iblock]['iter_start'] = iter_start
|
|
353
|
+
cis[iblock]['iter_stop'] = block_iter_stop
|
|
354
|
+
cis[iblock]['expected'], cis[iblock]['ci_lbound'], cis[iblock]['ci_ubound'] = avg, ci_lb, ci_ub
|
|
355
|
+
cis[iblock]['corr_len'] = correl_len
|
|
356
|
+
cis[iblock]['sterr'] = sterr
|
|
357
|
+
|
|
358
|
+
del fluxes
|
|
359
|
+
|
|
360
|
+
cis_ds = target_group.create_dataset('flux_evolution', data=cis)
|
|
361
|
+
cis_ds.attrs['iter_step'] = self.evol_step
|
|
362
|
+
cis_ds.attrs['mcbs_alpha'] = self.alpha
|
|
363
|
+
cis_ds.attrs['mcbs_autocorrel_alpha'] = self.autocorrel_alpha
|
|
364
|
+
cis_ds.attrs['mcbs_n_sets'] = self.n_sets
|
|
365
|
+
|
|
366
|
+
def go(self):
|
|
367
|
+
self.calc_store_flux_data()
|
|
368
|
+
if self.do_evol:
|
|
369
|
+
self.calc_evol_flux()
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
def entry_point():
|
|
373
|
+
warn('w_fluxanl is being deprecated. Please use w_assign and w_direct instead.')
|
|
374
|
+
WFluxanlTool().main()
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
if __name__ == '__main__':
|
|
378
|
+
entry_point()
|