Compare commits
3 Commits
e0a75514b5
...
2f7924e580
| Author | SHA1 | Date | |
|---|---|---|---|
| 2f7924e580 | |||
| 35ca52fd84 | |||
| 878ca95eed |
47
infocalc.py
47
infocalc.py
@@ -18,10 +18,24 @@ print("""Axiomatic Design Information Calculator by Joseph. T. Foley<foley AT ru
|
||||
From https://gitea.cs.ru.is/AxiomaticDesign/adcalc/""")
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Axiomatic Design Information Calculator.")
|
||||
parser.add_argument('csvfile',
|
||||
subparsers = parser.add_subparsers(dest='mode')
|
||||
subparsers.required = True
|
||||
|
||||
### MODE DATA
|
||||
parser_data = subparsers.add_parser("DATA")
|
||||
parser_data.add_argument('csvfile',
|
||||
help="CSV file with data and headers")
|
||||
parser.add_argument('column',
|
||||
parser_data.add_argument('column',
|
||||
help='Which column header to take data from')
|
||||
## MODE SIM
|
||||
parser_sim = subparsers.add_parser("SIM")
|
||||
parser_sim.add_argument('samplesize', type=int,
|
||||
help="sample size")
|
||||
parser_sim.add_argument('mean', type=float,
|
||||
help="mean(average) value")
|
||||
parser_sim.add_argument('stddev', type=float,
|
||||
help="sample standard deviation")
|
||||
## General Arguments
|
||||
parser.add_argument('minvalue', type=float,
|
||||
help='Tolerance low limit')
|
||||
parser.add_argument('maxvalue', type=float,
|
||||
@@ -30,8 +44,9 @@ parser.add_argument('--normalizey', action="store_true",
|
||||
help='Set y-axis to normalized probability density')
|
||||
parser.add_argument('--log', default="INFO",
|
||||
help='Console log level: Number or DEBUG, INFO, WARNING, ERROR')
|
||||
parser.add_argument('--graphinfo',
|
||||
parser.add_argument('--graphinfo', action="store_true",
|
||||
help='Put information on the PDF graph')
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
## Set up logging
|
||||
@@ -42,7 +57,7 @@ if not isinstance(numeric_level, int):
|
||||
logger = logging.getLogger("app")
|
||||
logger.setLevel(numeric_level)
|
||||
# log everything to file
|
||||
logpath = os.path.splitext(args.csvfile)[0]+".log"
|
||||
logpath = "infocalc.log"
|
||||
fh = logging.FileHandler(logpath)
|
||||
fh.setLevel(logging.DEBUG)
|
||||
# log to console
|
||||
@@ -59,18 +74,28 @@ logger.addHandler(fh)
|
||||
|
||||
logger.info("Creating infocalc log file %s", logpath)
|
||||
|
||||
lowerbound = args.minvalue
|
||||
upperbound = args.maxvalue
|
||||
|
||||
# seed values for variable scoping
|
||||
mean = 0
|
||||
stddev = 1
|
||||
samplesize =1
|
||||
|
||||
if args.mode == "DATA":
|
||||
# filename pre-processing for output
|
||||
inpath = PurePath(args.csvfile)
|
||||
print(f"Input: {inpath}")
|
||||
|
||||
# grab the data and process
|
||||
data = np.array(pd.read_csv(inpath)[args.column])
|
||||
lowerbound = args.minvalue
|
||||
upperbound = args.maxvalue
|
||||
logger.debug(f"data:{data}, lower:{lowerbound}, upper:{upperbound}")
|
||||
|
||||
mean = data.mean()
|
||||
stddev = data.std(ddof=1)
|
||||
samplesize = len(data)
|
||||
elif args.mode == "SIM":
|
||||
mean = args.mean
|
||||
stddev = args.stddev
|
||||
samplesize = args.samplesize
|
||||
|
||||
# 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)
|
||||
@@ -78,8 +103,10 @@ 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()
|
||||
|
||||
if args.graphinfo:#put info on corner of graph
|
||||
textstr = '\n'.join((
|
||||
r'$n=%d$' % (len(data)),
|
||||
r'$n=%d$' % (samplesize),
|
||||
r'$\mu=%.2f$' % (mean, ),
|
||||
r'$\sigma=%.2f$' % (stddev, ),
|
||||
r'$P=%.2f$' % (prob, ),
|
||||
|
||||
Reference in New Issue
Block a user