Compare commits

...

4 Commits

2 changed files with 16 additions and 21 deletions

View File

@@ -105,21 +105,18 @@ elif args.mode == "SIM":
samplesize = args.samplesize
df = samplesize - 1
prob = 0
if args.upperbound != None and args.lowerbound != None:
prob_upper = 1
prob_lower = 0
if args.upperbound is not None:
prob_upper = t.cdf(df=df,x=args.upperbound, loc=mean, scale=stddev)
if args.lowerbound is not None:
prob_lower = t.cdf(df=df,x=args.lowerbound, loc=mean, scale=stddev)
prob = prob_upper - prob_lower
elif args.upperbound != None:
prob = t.cdf(df=df,x=args.upperbound, loc=mean, scale=stddev)
elif args.lowerbound != None:
prob = 1 - t.cdf(df=df,x=args.lowerbound, loc=mean, scale=stddev)
else:
prob = 1# no bounds set!
#print("probability: %f", prob)
info = -np.emath.log2(prob)
#print("information content: %f bits", info)
logger.info(f"n={samplesize},df={df},mean={mean},stddev={stddev}")
logger.info(f"P()={prob},I={info} bits")
## set default fontsize
matplotlib.rcParams['font.size']=args.fontsize
## place text on plot: https://matplotlib.org/3.3.4/gallery/recipes/placing_text_boxes.html
@@ -148,22 +145,20 @@ y = norm.pdf(x, loc=mean, scale=stddev)
if args.normalizey:
y = y * stddev#rescale back to unity area
plt.axvline(x=mean, color="green", linestyle="dashed", label="mean")
if args.lowerbound != None:
if args.lowerbound is not None:
plt.axvline(args.lowerbound, color="red")
if args.upperbound != None:
if args.upperbound is not None:
plt.axvline(args.upperbound, color="red")
plt.plot(x, y, 'b-', label='Normal distribution')
#yt = scipy.stats.t.pdf(x, len(data)-1, mean, stddev)
#plt.plot(x, yt, 'g-', label='T Distribution')
plt.plot(x, y, 'b-', label='T distribution')
# Filter for which region to fill
coloredregion = x#default fill all
if args.lowerbound and args.upperbound:
if args.lowerbound is not None and args.upperbound is not None:
coloredregion = (x >= args.lowerbound) & ( x <= args.upperbound )
elif args.upperbound:
elif args.upperbound is not None:
coloredregion = x <= args.upperbound
elif args.lowerbound:
elif args.lowerbound is not None:
coloredregion = x >= args.lowerbound
plt.fill_between(x, 0, y, where=coloredregion, color="grey", alpha=0.5, label="Design range",)

View File

@@ -3,4 +3,4 @@
echo "Loading data from file"
./infocalc.py --lowerbound 0.9 --upperbound 1.1 --graphinfo DATA testdata.csv data1
echo "Creating simulated curve from parameters"
./infocalc.py --lowerbound 0.1 --upperbound 1.5 SIM 8 1.0 0.5
./infocalc.py --lowerbound 0.0 --upperbound 1.5 SIM 8 1.0 0.5