From 0c735905f11e5edc060e33bea9a02e44aecd9d41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Kn=C3=BCttel?= Date: Tue, 3 Mar 2020 11:21:11 +0100 Subject: [PATCH] forgot that --- presentation/spin_chain/bootstrap.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 presentation/spin_chain/bootstrap.py diff --git a/presentation/spin_chain/bootstrap.py b/presentation/spin_chain/bootstrap.py new file mode 100644 index 0000000..71ace1d --- /dev/null +++ b/presentation/spin_chain/bootstrap.py @@ -0,0 +1,14 @@ +import numpy as np +from collections import Counter, deque + +def bootstrap(m, nsample, resample_len, nresamples, f): + whole_sample = np.zeros(nsample) + whole_sample[m:] = 1 + + results = deque() + for _ in range(nresamples): + sample = np.random.choice(whole_sample, resample_len) + results.append(f(sample)) + + results = np.array(results).astype(np.double) + return np.std(results)