*** Wartungsfenster jeden ersten Mittwoch vormittag im Monat ***

Skip to content
Snippets Groups Projects
Commit 799290ca authored by Patrick Kappl's avatar Patrick Kappl
Browse files

Make the number of samples an input parameter

parent 44f71dd4
No related branches found
No related tags found
No related merge requests found
import numpy as np
def do_jackknife_estimation(input_sample_generator, transformation_function):
def do_jackknife_estimation(input_sample_generator, n_samples,
transformation_function):
"""Do a jackknife estimation for the transformed sample.
Estimate and return the sample mean, variance and standard deviation
......@@ -13,9 +14,7 @@ def do_jackknife_estimation(input_sample_generator, transformation_function):
"""
gen = input_sample_generator
f = transformation_function
samples = gen()
n_samples = sum(1 for i in samples)
samples = gen()
input_mean = sum(i for i in samples) / n_samples
transformed_mean = f(input_mean)
......
......@@ -27,7 +27,7 @@ y_generator = jackknife.get_sample_generator(y_list)
#%%
# Do a Jackknife estimation with the x-values and f() and print the
# results
output = jackknife.do_jackknife_estimation(x_generator, f)
output = jackknife.do_jackknife_estimation(x_generator, n, f)
x_mean = sum(i for i in x_list) / n
print("{}{}".format("f(mean(x)) = ", f(x_mean)))
print("{}{}".format("mean(y') = ", output[0]))
......@@ -38,7 +38,7 @@ print("{}{}".format("standard deviation(y') = ", output[2]))
# Do a Jackknife estimation with the y-values and the identity function
# and print the results. This means that statistics are done on a
# transformed sample set y, that is not bias corrected.
output = jackknife.do_jackknife_estimation(y_generator, lambda x: x)
output = jackknife.do_jackknife_estimation(y_generator, n, lambda x: x)
print("{}{}".format("mean(y) = ", output[0]))
print("{}{}".format("variance(y) = ", output[1]))
print("{}{}".format("standard deviation(y) = ", output[2]))
......@@ -79,7 +79,7 @@ y_generator = jackknife.get_sample_generator(y_list)
#%%
output = jackknife.do_jackknife_estimation(x_generator, f2)
output = jackknife.do_jackknife_estimation(x_generator, n2, f2)
x_mean = sum(i for i in m_2_and_4) / n2
print("{}{}".format("f2(mean(x)) = ", f2(x_mean)))
print("{}{}".format("mean(y') = ", output[0]))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment