Compare commits
6 Commits
dda8587dd8
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 93a6d8683f | |||
| bd93399700 | |||
| 0887a9effa | |||
| 16327adb58 | |||
| f4711640da | |||
| 6efdb3e241 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,2 +1,5 @@
|
|||||||
*~
|
*~
|
||||||
*.log
|
*.log
|
||||||
|
flycheck_*.py
|
||||||
|
\#*#
|
||||||
|
test.pdf
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
# ad-calc
|
# ad-calc
|
||||||
|
|
||||||
Tools to help calculating values for Axiomatic Design analysis
|
Tools to help calculating values for Axiomatic Design analysis
|
||||||
|
|
||||||
|
`infocalc.py` calculates information content based upon a csv file or statistical parameters and upper/lower limits
|
||||||
|
|||||||
15
infocalc.py
15
infocalc.py
@@ -11,7 +11,8 @@ from pathlib import PurePath##https://docs.python.org/3/library/pathlib.html#mod
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import matplotlib
|
import matplotlib
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from scipy.stats import norm
|
from scipy.stats import norm,t
|
||||||
|
import scipy.stats
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
|
|
||||||
#Main program loop
|
#Main program loop
|
||||||
@@ -96,25 +97,23 @@ if args.mode == "DATA":
|
|||||||
data = np.array(pd.read_csv(inpath)[args.column])
|
data = np.array(pd.read_csv(inpath)[args.column])
|
||||||
mean = data.mean()
|
mean = data.mean()
|
||||||
stddev = data.std(ddof=1)
|
stddev = data.std(ddof=1)
|
||||||
|
# Delta Degrees of Freedom: ddof=0 for population, ddof=1 for sample std dev
|
||||||
samplesize = len(data)
|
samplesize = len(data)
|
||||||
elif args.mode == "SIM":
|
elif args.mode == "SIM":
|
||||||
mean = args.mean
|
mean = args.mean
|
||||||
stddev = args.stddev
|
stddev = args.stddev
|
||||||
samplesize = args.samplesize
|
samplesize = args.samplesize
|
||||||
|
df = samplesize - 1
|
||||||
|
|
||||||
# time to deal with the bounds
|
|
||||||
|
|
||||||
# Delta Degrees of Freedom: ddof=0 for population, ddof=1 for sample std dev
|
|
||||||
prob = 0
|
prob = 0
|
||||||
if args.upperbound and args.lowerbound:
|
if args.upperbound and args.lowerbound:
|
||||||
prob = norm.cdf(args.upperbound, mean, stddev) - norm.cdf(args.lowerbound, mean, stddev)
|
prob = t.cdf(df,args.upperbound, mean, stddev) - t.cdf(df,args.lowerbound, mean, stddev)
|
||||||
elif args.upperbound:
|
elif args.upperbound:
|
||||||
prob = norm.cdf(args.upperbound, mean, stddev)
|
prob = t.cdf(df,args.upperbound, mean, stddev)
|
||||||
elif args.lowerbound:
|
elif args.lowerbound:
|
||||||
prob = 1 - norm.cdf(args.lowerbound, mean, stddev)
|
prob = 1 - t.cdf(df,args.lowerbound, mean, stddev)
|
||||||
else:
|
else:
|
||||||
prob = 1# no bounds set!
|
prob = 1# no bounds set!
|
||||||
##TODO!!!!
|
|
||||||
#print("probability: %f", prob)
|
#print("probability: %f", prob)
|
||||||
info = -np.emath.log2(prob)
|
info = -np.emath.log2(prob)
|
||||||
#print("information content: %f bits", info)
|
#print("information content: %f bits", info)
|
||||||
|
|||||||
57
normdist.py
57
normdist.py
@@ -1,57 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
import numpy as np
|
|
||||||
import matplotlib.pyplot as plt
|
|
||||||
from scipy.stats import norm
|
|
||||||
|
|
||||||
## Data goes here for now --foley
|
|
||||||
data = np.array([1, 1.1, 0.9, 1, 1, 0.9, 0.9])
|
|
||||||
lowerbound = 0.9
|
|
||||||
upperbound = 1.0
|
|
||||||
|
|
||||||
mean = data.mean()
|
|
||||||
stddev = data.std(ddof=1)
|
|
||||||
# Delta Degrees of Freedom: ddof=0 for population, ddof=1 for sample std dev
|
|
||||||
prob = norm.cdf(upperbound, mean, stddev) - norm.cdf(lowerbound, mean, stddev)
|
|
||||||
#print("probability: %f", prob)
|
|
||||||
info = -np.emath.log2(prob)
|
|
||||||
#print("information content: %f bits", info)
|
|
||||||
## place text on plot: https://matplotlib.org/3.3.4/gallery/recipes/placing_text_boxes.html
|
|
||||||
fig, ax = plt.subplots()
|
|
||||||
textstr = '\n'.join((
|
|
||||||
r'$n=%d$' % (len(data)),
|
|
||||||
r'$\mu=%.2f$' % (mean, ),
|
|
||||||
r'$\sigma=%.2f$' % (stddev, ),
|
|
||||||
r'$P=%.2f$' % (prob, ),
|
|
||||||
r'$I=%.2f$ bits' % (info, )))
|
|
||||||
# these are matplotlib.patch.Patch properties
|
|
||||||
props = dict(boxstyle='round', facecolor='wheat', alpha=0.5)
|
|
||||||
|
|
||||||
# place a text box in upper left in axes coords
|
|
||||||
ax.text(0.05, 0.95, textstr, transform=ax.transAxes, fontsize=14,
|
|
||||||
verticalalignment='top', bbox=props)
|
|
||||||
|
|
||||||
x = np.linspace(mean-3*stddev, mean+3*stddev, 500)
|
|
||||||
y = norm.pdf(x, loc=mean, scale=stddev) * stddev#rescale back to unity area
|
|
||||||
plt.axvline(x=mean, color="green", linestyle="dashed", label="mean")
|
|
||||||
plt.axvline(lowerbound, color="red")
|
|
||||||
plt.axvline(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')
|
|
||||||
coloredregion = (x >= lowerbound) & ( x <= upperbound ) #select x values
|
|
||||||
plt.fill_between(x, 0, y, where=coloredregion, color="grey", alpha=0.5, label="Design range")
|
|
||||||
plt.xlabel('X')
|
|
||||||
plt.ylabel('Probability density')
|
|
||||||
plt.legend()
|
|
||||||
plt.grid(True)
|
|
||||||
|
|
||||||
top = plt.ylim()[1]
|
|
||||||
|
|
||||||
|
|
||||||
plt.show()
|
|
||||||
# annotate values on X after drawing the graphs
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
import pandas as pd
|
|
||||||
|
|
||||||
df = pd.DataFrame(
|
|
||||||
{
|
|
||||||
"Name": [
|
|
||||||
"Braund, Mr. Owen Harris",
|
|
||||||
"Allen, Mr. William Hentry",
|
|
||||||
"Bonnell, Miss. Elizabeth",
|
|
||||||
],
|
|
||||||
"Age": [22, 35, 58],
|
|
||||||
"Sex": ["male", "male", "female"],
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
print(df.describe())
|
|
||||||
|
|
||||||
titanic = pd.read_csv("titanic.csv")
|
|
||||||
print(titanic.head(8))
|
|
||||||
titanic.to_excel("titanic.xlsx", sheet_name="passengers", index=False)
|
|
||||||
titanic_xltest = pd.read_excel("titanic.xlsx", sheet_name="passengers")
|
|
||||||
print("INFO")
|
|
||||||
print(titanic.info())
|
|
||||||
4
tests.sh
4
tests.sh
@@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
# Get infocalc.py from https://gitea.cs.ru.is/AxiomaticDesign/adcalc
|
# Get infocalc.py from https://gitea.cs.ru.is/AxiomaticDesign/adcalc
|
||||||
echo "Loading data from file"
|
echo "Loading data from file"
|
||||||
./infocalc.py DATA testdata.csv data1 0.9 1.1 --graphinfo
|
./infocalc.py --lowerbound 0.9 --upperbound 1.1 --graphinfo DATA testdata.csv data1
|
||||||
echo "Creating simulated curve from parameters"
|
echo "Creating simulated curve from parameters"
|
||||||
./infocalc.py SIM 8 1.0 0.5 0.9 1.1
|
./infocalc.py --lowerbound 0.9 --upperbound 1.1 SIM 8 1.0 0.5
|
||||||
|
|||||||
Reference in New Issue
Block a user