In [2]:
%matplotlib
import matplotlib.pyplot as plt
import numpy as np
import scipy.io as sio
import measurement
import echo
import distance
import image
In [2]:
# choose dataset
fname = 'datasets/set_fs_32000_1.mat'
dataset = sio.loadmat(fname)
In [9]:
fs = float(dataset['fs'])
M = int(dataset['M'])
N = int(dataset['N'])
h = float(dataset['h'])
l = float(dataset['l'])
w = float(dataset['w'])
r = dataset['receivers']
s = dataset['sources']
data = dataset['data'].T
c = float(dataset['c'])
maxsize = np.sqrt(w**2+l**2+h**2) #m
max_delay = maxsize / float(c)
maxlength = int(2 * max_delay * fs)
room = np.array([[ [0,0], [0,l], [w,l], [w,0]]])
measurements = [measurement.MeasurementData(data=np.hstack(source_data).T,
receivers=r,
sources=s[i],
room_dimensions=(w,l,h),
c=c,
fs=fs)
for i,source_data in enumerate(data)]
In [10]:
echo_data = [echo.EchoData(m.find_echoes(crop=maxlength, interpolate=10)) for m in measurements]
In [11]:
D = measurement.squared_distance_matrix(r, augmented=True)
N = 8
S, E = zip(*[e.find_labels(D,threshold=0.005, parallel=True, verbose=True) for e in echo_data[:N]])
E = [e for e in E if len(e) > 0]
S = np.vstack(S)
In [16]:
distancedata = distance.DistanceData(S,E)
results = distancedata.find_images(r)
print(sorted(results.keys())[0:10])
In [17]:
if len(results) > 0:
imagedata = image.ImageSourceData(results, N, r, (w,l,h))
wall_points,vertices = imagedata.find_walls(threshold=0.1, bestN=10)
if len(vertices) == 4:
im = np.vstack(imagedata.images)
plt.scatter(im[:,0], im[:,1])
wp = np.vstack(wall_points)
plt.scatter(wp[:,0], wp[:,1], color=(1,0,0,1))
plt.scatter(vertices[:,0], vertices[:,1], color=(0,1,0,1))
In [41]:
results = np.load('results_dictionary.npy')
In [42]:
results
Out[42]:
In [43]:
type(results)
Out[43]:
In [44]:
len(results)
In [36]:
collections.defaultdict(results)
In [3]:
import collections
In [4]:
import pickle
In [88]:
y = []
x = []
with open('fs_1x_results', 'rb') as f:
results = pickle.load(f)
for k in sorted(results.keys()):
if k < 40000:
x.append(k)
y.append(np.mean(results[k]))
with open('fs_mc_1x_results', 'rb') as f:
results = pickle.load(f)
for k in sorted(results.keys()):
if k > 40000:
x.append(k)
y.append(np.mean(results[k]))
plt.plot(x, y)
Out[88]:
In [87]:
y = []
x = []
with open('fs_10x_results', 'rb') as f:
results = pickle.load(f)
for k in sorted(results.keys()):
if k < 40000:
x.append(k)
y.append(np.mean(results[k]))
with open('fs_mc_10x_results', 'rb') as f:
results = pickle.load(f)
for k in sorted(results.keys()):
if k > 40000:
x.append(k)
y.append(np.mean(results[k]))
plt.plot(x, y)
Out[87]:
In [113]:
def plot_fs(ax, d1, d2, label=None, color=None):
y = []
x = []
with open(d1, 'rb') as f:
results = pickle.load(f)
for k in sorted(results.keys()):
if k < 40000:
x.append(k)
y.append(np.mean(results[k]))
with open(d2, 'rb') as f:
results = pickle.load(f)
for k in sorted(results.keys()):
if k > 40000:
x.append(k)
y.append(np.mean(results[k]))
ax.plot(x, y, 'o-', linewidth=2, label=label, color=color)
plt.legend(loc='best')
In [130]:
fig = plt.figure()
ax = fig.gca()
plot_fs(ax, 'fs_1x_results', 'fs_mc_1x_results', color=tudelft_cyan, label="No upsampling")
plot_fs(ax, 'fs_10x_results', 'fs_mc_10x_results', color=tudelft_orange, label="10x upsampling")
plot_fs(ax, 'fs_100x_results', 'fs_mc_100x_results', color=tudelft_purple, label="100x upsampling")
plt.xlabel('Sample Frequency [Hz]')
plt.ylabel('Room estimation error [m]')
plt.grid('on')
plt.xticks((16000, 32000, 48000, 96000, 2*96000), ('16k', '32k', '48k', '96k', '192k'), color=tudelft_black)
plt.show()
In [126]:
help(plt.xticks)
In [28]:
from matplotlib.colors import ColorConverter
cc = ColorConverter()
# colors
tudelft_cyan = cc.to_rgba("#00ADEF")
tudelft_black = cc.to_rgba("#231F20")
tudelft_white = cc.to_rgba("#FFFFFF")
tudelft_sea_green = cc.to_rgba("#70C8BB")
tudelft_green = cc.to_rgba("#0097A1")
tudelft_dark_blue = cc.to_rgba("#1B1464")
tudelft_purple = cc.to_rgba("#211869")
tudelft_turquoise = cc.to_rgba("#00A9BD")
tudelft_sky_blue = cc.to_rgba("#7AC6DC")
tudelft_lavender = cc.to_rgba("#7FA7D0")
tudelft_orange = cc.to_rgba("#F0883F" )
tudelft_warm_purple = cc.to_rgba("#80268C")
tudelft_fuchsia = cc.to_rgba("#A70576")
tudelft_bright_green = cc.to_rgba("#AFD135")
tudelft_yellow = cc.to_rgba("#FDF391")
In [309]:
#'N5_w5l7h3.5', 'N5_w8l7h3.5',
# 'N5_w9l10h5', 'N5_w11l13h5', 'N5_w9l8h5', 'N5_w19l18h9',
# 'N5_w15l15h6_',
files = ['N5_w5l7h3.5', 'N5_w8l7h3.5', 'N5_w5l5h5', 'N5_w6l5h5', 'N5_w6l6h5', 'N5_w7l6h5', 'N5_w7l7h5',
'N5_w8l7h5', 'N5_w8l8h5', 'N5_w9l9h5', 'N5_w10l10h5', 'N5_w8l10h5'] #, 'N5_w8l7h5', 'N5_w9l8h5', 'N5_w9l10h5', 'N5_w11l13h5']
x = []
y = []
z = []
for file in files:
with open(file, 'rb') as f:
results = pickle.load(f)
volume = sorted(results.keys())[0]
results = results[volume]
errors, times = zip(*results)
print(volume,len(errors), len(errors)/50)
y.append(np.array(errors))
x.append(volume)
z.append(np.array(times))
#i = np.argsort(x)
#x = np.array(x)[i]
#y = np.array(y)[i]
#z = np.array(z)[i]
x = np.array(x)
y = np.hstack(y)
z = np.hstack(z)
In [312]:
(len(y)-23-25)/500
Out[312]:
In [292]:
np.mean(y)
Out[292]:
In [302]:
np.sqrt(np.var(y))
Out[302]:
In [295]:
np.min(y)
Out[295]:
In [299]:
np.mean(z)
Out[299]:
In [300]:
np.var(z)
Out[300]:
In [301]:
np.min(z)
Out[301]:
In [53]:
with open('N_2-16', 'rb') as f:
results = pickle.load(f)
NN = sorted(results.keys())
mean_err = []
mean_time = []
for N in NN:
res = results[N]
errors, times = zip(*res)
mean_err.append(np.mean(errors))
mean_time.append(np.mean(times))
In [54]:
plt.figure(1)
plt.plot(NN, mean_err/mean_err[0], 'o-', linewidth=2, color=tudelft_cyan)
plt.grid('on')
In [55]:
plt.figure(2)
plt.plot(NN, mean_time, 'o-', linewidth=2, color=tudelft_orange)
plt.grid('on')
In [48]:
with open('N_2-16-1', 'rb') as f:
results = pickle.load(f)
NN = sorted(results.keys())
mean_err = []
mean_time = []
for N in NN:
res = results[N]
errors, times = zip(*res)
mean_err.append(np.mean(errors))
mean_time.append(np.mean(times))
In [ ]: