Skip to content

Instantly share code, notes, and snippets.

@martin-ueding
Created May 3, 2020 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martin-ueding/2fcb40f8b12e859864996d4296ac2b98 to your computer and use it in GitHub Desktop.
Save martin-ueding/2fcb40f8b12e859864996d4296ac2b98 to your computer and use it in GitHub Desktop.
Standard deviation and standard error
#!/usr/bin/python3
# -*- coding: utf-8 -*-
# Copyright © 2016 Martin Ueding <mu@martin-ueding.de>
import argparse
import random
import time
import matplotlib.pyplot as pl
import numpy as np
import scipy.optimize as op
def get_measurement():
new = random.gauss(0, 1)
#new = random.triangular(0, 1, 0.7)
return new
def main():
options = _parse_args()
measurements = []
measurements.append(get_measurement())
pl.ion()
bins = 40
while True:
for i in range(20):
measurements.append(get_measurement())
pl.clf()
pl.hist(measurements, color='0.8', bins=bins)
count = len(measurements)
mean = np.mean(measurements)
std = np.std(measurements)
err = std / np.sqrt(count)
max_height = count / bins
pl.plot([mean - err, mean + err], [max_height, max_height], color='red', marker='o')
pl.plot([mean], [max_height], color='green', marker='o')
max_height *= 0.9
pl.plot([mean - std, mean + std], [max_height, max_height], color='green', marker='o')
#time.sleep(0.5)
pl.pause(0.1)
def _parse_args():
'''
Parses the command line arguments.
:return: Namespace with arguments.
:rtype: Namespace
'''
parser = argparse.ArgumentParser(description='')
options = parser.parse_args()
return options
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment