Commit a47ed321 authored by Jakob Zierk's avatar Jakob Zierk

Added TSH benchmark w/ CIs.

parent f2a29099
This diff is collapsed.
from kosmic import kosmic, percentile
import random
import numpy as np
from multiprocessing import Pool, cpu_count
from math import exp
meanlog=-5.506435e-06
sdlog=7.073083e-01
# Simulation:
n = 50000
decimals = 2
def sim(mu1, sd1, pi1):
random.seed(0)
p025s = []
p975s = []
for _ in range(100):
samples = []
for _ in range(int(n * (1-pi1))):
samples.append(round(random.lognormvariate(-5.506435e-06, 7.073083e-01), decimals))
for _ in range(int(n * pi1)):
samples.append(round(random.normalvariate(mu1, sd1/0.979982), decimals))
random.shuffle(samples)
result = kosmic(samples, decimals)
p025s.append(percentile(result, 0.025))
p975s.append(percentile(result, 0.975))
return p025s, p975s
if __name__ == "__main__":
results = {}
with Pool(processes=cpu_count()) as pool:
# Start simulations:
for mu1 in [3, 3.5, 4, 4.5, 5, 5.5, 6]:
for sd1 in [.5, 1, 1.5, 2]:
for pi1 in [0.0, 0.05, 0.1, 0.15, 0.2, 0.3]:
if pi1 == 0.0 and (mu1 != 3 or sd1 != .5):
continue
results[str(mu1) + "\t" + str(sd1) + "\t" + str(pi1)] = pool.apply_async(sim, [mu1, sd1, pi1])
# Output simulation results:
with open("results/tsh-simulation-cis.tsv", "w", encoding="utf-8") as tsh:
tsh.write("\tµ₁\tσ₁\tπ₁\tP2.5\tP97.5\n")
for task, result in results.items():
result = result.get()
tsh.write("Median\t" + task + "\t" + str(np.percentile(result[0], 50)) + "\t" + str(np.percentile(result[1], 50)) + "\n")
tsh.write("P5\t" + task + "\t" + str(np.percentile(result[0], 5)) + "\t" + str(np.percentile(result[1], 5)) + "\n")
tsh.write("P95\t" + task + "\t" + str(np.percentile(result[0], 95)) + "\t" + str(np.percentile(result[1], 95)) + "\n")
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment