forked from expeditionary-robotics/informative-path-planning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstar_eval.py
116 lines (88 loc) · 4.03 KB
/
star_eval.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# !/usr/bin/python
''' Script for running myopic experiments using the run_sim bash script. Generally a function of convenience in the event of parallelizing simulation runs. Note: some of the parameters may need to be set prior to running the bash script.
License: MIT
Maintainers: Genevieve Flaspohler and Victoria Preston
'''
import os
import time
import sys
import logging
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
import pdb
import aq_library as aqlib
import mcts_library as mctslib
import gpmodel_library as gplib
import evaluation_library as evalib
import paths_library as pathlib
import envmodel_library as envlib
import robot_library as roblib
import obstacles as obslib
import bag_utils as baglib
import matplotlib.colors as mcolors
from scipy.spatial import distance
prefix = '/home/genevieve/mit-whoi/temp/informative-path-planning/figures/'
samp_filename = 'sampled_maxes.csv'
max_filename = 'true_maxes.csv'
maxima_files = [prefix + 'mes_plumes/' + max_filename,
prefix + 'mes_lawn/' + max_filename]
sample_files = [prefix + 'mes_plumes/' + samp_filename,
prefix + 'mes_lawn/' + samp_filename]
labels = ['PLUMES',
'LAWNMOWER']
NBINS = 50
RANGE = np.array([(0, 50), (0, 50)])
# st2d(xval, yval, bins=1000, range=np.array([(-6, 6), (-4.5, 4.5)]))
# xlim([-6, 6])
# ylim([-4.5, 4.5])
# fig, axes = plt.subplots(nrows=1, ncols=2, figsize=(16, 8))
for i, (label, max_file, samp_file) in enumerate(zip(labels, maxima_files, sample_files)):
print "Analyzing", label
sampled_maxes = np.loadtxt(samp_file).T
true_maxes = np.loadtxt(max_file).T
max_locs = sampled_maxes[:, 0:2].reshape((-1, 2))
max_vals = sampled_maxes[:, 2].reshape((-1, 1))
true_loc = true_maxes[0:2].reshape((-1, 2))
true_val = true_maxes[2].reshape((-1, 1))
dist_loc = distance.cdist(max_locs, true_loc, 'euclidean')
dist_val = distance.cdist(max_vals, true_val, 'euclidean')
print "Distance mean location:", np.mean(dist_loc), "\t Value:", np.mean(dist_val)
plt.figure(figsize=(8,8))
plt.hist2d(max_locs[:, 0], max_locs[:, 1], bins = NBINS, normed = True, range = RANGE, cmap = 'magma', norm=mcolors.LogNorm())
# plt.hist2d(max_locs[:, 0], max_locs[:, 1], bins = NBINS, normed = True, range = RANGE, cmap = 'Greys' )
# plt.hist2d(max_locs[:, 0], max_locs[:, 1], bins = NBINS, normed = True, range = RANGE, cmap = 'Greys', norm=mcolors.PowerNorm(0.01))
# plt.hist2d(max_locs[:, 0], max_locs[:, 1], bins = NBINS, normed = True, cmap = 'plasma')
# plt.xlim([0, 50])
# plt.ylim([0, 50])
plt.colorbar()
plt.show()
hist, xbins, ybins, _ = plt.hist2d(max_locs[:, 0], max_locs[:, 1], bins = NBINS, normed = True, range = RANGE)
entropy_x = -np.mean(np.log(hist[hist > 0.0]))
print "Entropy of star x-value distribution:", entropy_x
hist_z, xbins_z, _ = plt.hist(max_vals, bins = NBINS, density = True)
entropy_z = -np.mean(np.log(hist_z[hist_z > 0.0]))
print "Entropy of star z-value distribution:", entropy_z
# Uniform santiy check
uniform = np.ones(hist.shape) / np.sum(np.ones(hist.shape))
unifrom_entropy = -np.mean(np.log(uniform[uniform > 0.0]))
print "Entropy of a uniform distribution:", unifrom_entropy
# axes[i].set_title(label)
# axes[i].hist2d(max_locs[:, 0], max_locs[:, 1], bins = NBINS)
# # axes[i].imshow(hist)
# axes[i].set_xlim(0, 50)
# axes[i].set_ylim(0, 50)
plt.show()
# loc_kernel = sp.stats.gaussian_kde(max_locs.T)
# loc_kernel.set_bandwidth(bw_method=4.0)
# density_loc = loc_kernel(max_locs.T)
# density_loc = density_loc / np.sum(density_loc)
# entropy_loc = -np.mean(np.log(density_loc))
# print density_loc
# print "Entropy of star location:", entropy_loc
# val_kernel = sp.stats.gaussian_kde(max_vals.T)
# val_kernel.set_bandwidth(bw_method='silverman')
# density_val = val_kernel(max_vals.T)
# density_val = density_val / np.sum(density_val)
# entropy_val = -np.mean(np.log(density_val))
# print "Entropy of star value:", entropy_val