Skip to content

Commit 92372bd

Browse files
committed
workshop 4 files
1 parent e146c9f commit 92372bd

File tree

2 files changed

+68
-0
lines changed

2 files changed

+68
-0
lines changed

evaluation/numpy_stats.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import csv
2+
import numpy as np
3+
import matplotlib.pyplot as plt
4+
5+
# load data from csv file as a numpy array
6+
data = np.genfromtxt('evaluation/ref_data/head_size_gt.csv', delimiter=',')
7+
8+
# Broccoli head size measurements (in mm) for training vision systems for robotic harvesters
9+
# for more details see Kusumam et al., 2017: https://onlinelibrary.wiley.com/doi/full/10.1002/rob.21726
10+
11+
print('sample size {0:d}'.format(len(data)))
12+
13+
bin_nr = 20
14+
bin_range = (70,210) # None for auto
15+
16+
# calculate all stats
17+
st_mean = np.mean(data)
18+
st_std = np.std(data)
19+
st_min = np.min(data)
20+
st_max = np.max(data)
21+
st_median = np.median(data)
22+
st_qnt_05 = np.quantile(data, 0.05)
23+
st_qnt_95 = np.quantile(data, 0.95)
24+
st_loqrt = np.quantile(data, 0.25)
25+
st_upqrt = np.quantile(data, 0.75)
26+
h_count, h_range = np.histogram(data, bins=bin_nr, range=bin_range)
27+
28+
# print out the results
29+
print(f'mean {st_mean:.2f} std {st_std:.2f}')
30+
print(f'min {st_min:.2f} max {st_max:.2f} range {st_max-st_min:.2f}')
31+
32+
print(f'median {st_median:.2f}')
33+
print(f'quantile: qnt_05% {st_qnt_05:.2f} qnt_95% {st_qnt_95:.2f} range {st_qnt_95-st_qnt_05:.2f}')
34+
print(f'quartile: lower {st_loqrt:.2f} upper {st_upqrt:.2f} range {st_upqrt-st_loqrt:.2f}')
35+
36+
print('histogram:')
37+
print(' - bin counts ', h_count)
38+
print(' - bin ranges ', h_range)
39+
40+
#plotting histograms with the same settings as above
41+
plt.hist(data, bins=bin_nr, range=bin_range)
42+
43+
# plot the stats, uncomment if desired
44+
45+
# plt.axvline(st_mean, linestyle='dashed')
46+
# plt.axvline(st_min, linestyle='dashed')
47+
# plt.axvline(st_max, linestyle='dashed')
48+
49+
# plt.axvline(st_median, color='tab:orange', linestyle='dotted')
50+
# plt.axvline(st_qnt_05, color='tab:orange', linestyle='dotted')
51+
# plt.axvline(st_qnt_95, color='tab:orange', linestyle='dotted')
52+
53+
# min_ylim, max_ylim = plt.ylim()
54+
# x_offset = 1.01
55+
# y_offset = max_ylim*0.9
56+
# plt.text(st_mean*x_offset, y_offset, f'mean = {st_mean:.1f}')
57+
# plt.text(st_min*x_offset, y_offset, f'min = {st_min:.1f}')
58+
# plt.text(st_max*x_offset, y_offset, f'max = {st_max:.1f}')
59+
60+
# y_offset = max_ylim*0.7
61+
# plt.text(st_median*x_offset, y_offset, f'median = {st_median:.1f}', color='tab:orange')
62+
# plt.text(st_qnt_05*x_offset, y_offset, f'qnt_05% = {st_qnt_05:.1f}', color='tab:orange')
63+
# plt.text(st_qnt_95*x_offset, y_offset, f'qnt_95% = {st_qnt_95:.1f}', color='tab:orange')
64+
65+
plt.title(f'histogram bin_nr = {bin_nr:d}')
66+
67+
plt.show()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
138.0,168.0,163.5,170.5,149.0,150.0,156.5,136.5,127.5,177.5,145.0,154.0,140.5,165.5,178.0,129.5,148.5,122.5,149.0,140.5,141.0,169.5,110.5,93.5,173.0,167.5,135.0,178.5,203.5,176.0,178.5,173.0,97.5,160.0,163.0,173.5,151.5,92.5,152.5,155.0,150.0,168.5,136.0,142.5,149.0,143.0,141.0,152.5,133.5,130.0,125.5,157.5,155.5,163.5,145.5,81.5,76.5,191.0,139.5,101.0,94.0,133.0,178.5,174.5,110.5,162.5,101.5,155.0,163.0,146.0,172.5,137.5,154.0,142.0,143.5,178.5,169.0,154.5,129.5,165.0,169.0,149.5,105.5,167.5,153.5,166.0,167.0,167.0,177.5,145.5,133.5,150.5,141.0,168.0,147.5,109.5,157.5,167.5,127.5,141.5

0 commit comments

Comments
 (0)