def plot_estimate_chart_3(): with figsize(y=2.5): plt.figure() ax = plt.axes() ax.annotate('', xy=[1,159], xytext=[0,158], arrowprops=dict(arrowstyle='->', ec='r', lw=3, shrinkA=6, shrinkB=5)) ax.annotate('', xy=[1,159], xytext=[1,164.2], arrowprops=dict(arrowstyle='-', ec='k', lw=3, shrinkA=8, shrinkB=8)) est_y = (158 + .4*(164.2-158)) plt.scatter ([0,1], [158.0,est_y], c='k',s=128) plt.scatter ([1], [164.2], c='b',s=128) plt.scatter ([1], [159], c='r', s=128) plt.text (1.0, 158.8, "prediction ($x_t)$", ha='center',va='top',fontsize=18,color='red') plt.text (1.0, 164.4, "measurement ($z$)",ha='center',va='bottom',fontsize=18,color='blue') plt.text (0, 159.8, "last estimate ($\hat{x}_{t-1}$)", ha='left', va='top',fontsize=18) plt.text (0.95, est_y, "estimate ($\hat{x}_{t}$)", ha='right', va='center',fontsize=18) plt.xlabel('day') plt.ylabel('weight (lbs)') ax.xaxis.grid(True, which="major", linestyle='dotted') ax.yaxis.grid(True, which="major", linestyle='dotted') plt.ylim(157, 164.5)
def plot_residual_resample(a): N = len(a) a_norm = np.asarray(a) / np.sum(a) cumsum = np.cumsum(a_norm) cumsum = np.insert(cumsum, 0, 0) cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], [1., .8, 0.], [1., .4, 0.]]*(int(N/4) + 1)) with figsize(y=2): fig = plt.figure() ax = plt.gcf().add_axes([0.05, 0.475, 0.9, 0.15]) norm = mpl.colors.BoundaryNorm(cumsum, cmap.N) bar = mpl.colorbar.ColorbarBase(ax, cmap=cmap, norm=norm, drawedges=False, spacing='proportional', orientation='horizontal') indexes = residual_resample(a_norm) bins = np.bincount(indexes) for i in range(1, N): n = bins[i-1] # number particles in this sample if n > 0: b = np.linspace(cumsum[i-1], cumsum[i], n+2)[1:-1] plt.scatter(b, [.5]*len(b), s=60, facecolor='k', edgecolor='k') bar.set_ticks([]) plt.title('residual resampling') end_interactive(fig)
def plot_hypothesis5(): weights = [ 158.0, 164.2, 160.3, 159.9, 162.1, 164.6, 169.6, 167.4, 166.4, 171.0, 171.2, 172.6 ] xs = range(1, len(weights) + 1) line = np.poly1d(np.polyfit(xs, weights, 1)) with figsize(y=2.5): plt.figure() plt.errorbar(range(1, 13), weights, label='weights', yerr=5, fmt='o', capthick=2, capsize=10) plt.plot(xs, line(xs), c='r', label='hypothesis') plt.xlim(0, 13) plt.ylim(145, 185) plt.xlabel('day') plt.ylabel('weight (lbs)') book_plots.show_legend() plt.grid(False)
def plot_cumsum(a): with figsize(y=2): fig = plt.figure() N = len(a) cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], [1., .8, 0.], [1., .4, 0.]]*(int(N/4) + 1)) cumsum = np.cumsum(np.asarray(a) / np.sum(a)) cumsum = np.insert(cumsum, 0, 0) #fig = plt.figure(figsize=(6,3)) fig=plt.gcf() ax = fig.add_axes([0.05, 0.475, 0.9, 0.15]) norm = mpl.colors.BoundaryNorm(cumsum, cmap.N) bar = mpl.colorbar.ColorbarBase(ax, cmap=cmap, norm=norm, drawedges=False, spacing='proportional', orientation='horizontal') if N > 10: bar.set_ticks([]) end_interactive(fig)
def plot_multinomial_resample(a): N = len(a) cmap = mpl.colors.ListedColormap([[0., .4, 1.], [0., .8, 1.], [1., .8, 0.], [1., .4, 0.]]*(int(N/4) + 1)) cumsum = np.cumsum(np.asarray(a) / np.sum(a)) cumsum = np.insert(cumsum, 0, 0) with figsize(y=2): fig = plt.figure() ax = plt.gcf().add_axes([0.05, 0.475, 0.9, 0.15]) norm = mpl.colors.BoundaryNorm(cumsum, cmap.N) bar = mpl.colorbar.ColorbarBase(ax, cmap=cmap, norm=norm, drawedges=False, spacing='proportional', orientation='horizontal') # make N subdivisions, and chose a random position within each one b = random(N) plt.scatter(b, [.5]*len(b), s=60, facecolor='k', edgecolor='k') bar.set_ticks([]) plt.title('multinomial resampling') end_interactive(fig)
def plot_estimate_chart_3(): with figsize(y=2.5): plt.figure() ax = plt.axes() ax.annotate('', xy=[1,159], xytext=[0,158], arrowprops=dict(arrowstyle='->', ec='r', lw=3, shrinkA=6, shrinkB=5)) ax.annotate('', xy=[1,159], xytext=[1,164.2], arrowprops=dict(arrowstyle='-', ec='k', lw=3, shrinkA=8, shrinkB=8)) est_y = (158 + .4*(164.2-158)) plt.scatter ([0,1], [158.0,est_y], c='k',s=128) plt.scatter ([1], [164.2], c='b',s=128) plt.scatter ([1], [159], c='r', s=128) plt.text (1.0, 158.8, "prediction ($x_t)$", ha='center',va='top',fontsize=18,color='red') plt.text (1.0, 164.4, "measurement ($z$)",ha='center',va='bottom',fontsize=18,color='blue') plt.text (0, 159.8, "last estimate ($\hat{x}_{t-1}$)", ha='left', va='top',fontsize=18) plt.text (0.95, est_y, "estimate ($\hat{x}_{t}$)", ha='right', va='center',fontsize=18) plt.xlabel('day') plt.ylabel('weight (lbs)') ax.xaxis.grid(True, which="major", linestyle='dotted') ax.yaxis.grid(True, which="major", linestyle='dotted') plt.ylim(157, 164.5)
def plot_hypothesis2(): with book_plots.figsize(y=2.5): plt.figure() plt.errorbar(range(1, 11), [169, 170, 169,171, 170, 171, 169, 170, 169, 170], xerr=0, yerr=6, fmt='bo', capthick=2, capsize=10) plt.plot([1, 10], [169, 170.5], color='g', ls='--') plt.xlim(0, 11) plt.ylim(150, 185) plt.xlabel('day') plt.ylabel('lbs')
def plot_hypothesis2(): with book_plots.figsize(y=2.5): plt.figure() plt.errorbar(range(1, 11), [169, 170, 169,171, 170, 171, 169, 170, 169, 170], xerr=0, yerr=6, fmt='bo', capthick=2, capsize=10) plt.plot([1, 10], [169, 170.5], color='g', ls='--') plt.xlim(0, 11) plt.ylim(150, 185) plt.xlabel('day') plt.ylabel('lbs') plt.grid(False)
def plot_estimate_chart_1(): with figsize(y=2.5): plt.figure() ax = plt.axes() ax.annotate('', xy=[1,159], xytext=[0,158], arrowprops=dict(arrowstyle='->', ec='r',shrinkA=6, lw=3,shrinkB=5)) plt.scatter ([0], [158], c='b') plt.scatter ([1], [159], c='r') plt.xlabel('day') plt.ylabel('weight (lbs)') ax.xaxis.grid(True, which="major", linestyle='dotted') ax.yaxis.grid(True, which="major", linestyle='dotted') plt.tight_layout()
def plot_estimate_chart_1(): with figsize(y=2.5): plt.figure() ax = plt.axes() ax.annotate('', xy=[1,159], xytext=[0,158], arrowprops=dict(arrowstyle='->', ec='r',shrinkA=6, lw=3,shrinkB=5)) plt.scatter ([0], [158], c='b') plt.scatter ([1], [159], c='r') plt.xlabel('day') plt.ylabel('weight (lbs)') ax.xaxis.grid(True, which="major", linestyle='dotted') ax.yaxis.grid(True, which="major", linestyle='dotted') plt.tight_layout()
def plot_hypothesis3(): weights = [158.0, 164.2, 160.3, 159.9, 162.1, 164.6, 169.6, 167.4, 166.4, 171.0, 171.2, 172.6] with book_plots.figsize(y=2.5): plt.figure() plt.errorbar(range(1, 13), weights, xerr=0, yerr=6, fmt='o', capthick=2, capsize=10) plt.xlim(0, 13) plt.ylim(145, 185) plt.xlabel('day') plt.ylabel('weight (lbs)')
def plot_hypothesis1(): with figsize(y=3.5): plt.figure() plt.errorbar([1, 2, 3], [170, 161, 169], xerr=0, yerr=10, fmt='bo', capthick=2, capsize=10) plt.plot([1, 3], [180, 160], color='g', ls='--') plt.plot([1, 3], [170, 170], color='g', ls='--') plt.plot([1, 3], [160, 175], color='g', ls='--') plt.plot([1, 2, 3], [180, 152, 179], color='g', ls='--') plt.xlim(0,4) plt.ylim(150, 185) plt.xlabel('day') plt.ylabel('lbs') plt.tight_layout()
def plot_hypothesis4(): weights = [158.0, 164.2, 160.3, 159.9, 162.1, 164.6, 169.6, 167.4, 166.4, 171.0, 171.2, 172.6] with book_plots.figsize(y=2.5): plt.figure() ave = np.sum(weights) / len(weights) plt.errorbar(range(1,13), weights, label='weights', yerr=6, fmt='o', capthick=2, capsize=10) plt.plot([1, 12], [ave,ave], c='r', label='hypothesis') plt.xlim(0, 13) plt.ylim(145, 185) plt.xlabel('day') plt.ylabel('weight (lbs)') book_plots.show_legend()
def plot_hypothesis3(): weights = [158.0, 164.2, 160.3, 159.9, 162.1, 164.6, 169.6, 167.4, 166.4, 171.0, 171.2, 172.6] with book_plots.figsize(y=2.5): plt.figure() plt.errorbar(range(1, 13), weights, xerr=0, yerr=6, fmt='o', capthick=2, capsize=10) plt.xlim(0, 13) plt.ylim(145, 185) plt.xlabel('day') plt.ylabel('weight (lbs)') plt.grid(False)
def plot_hypothesis4(): weights = [158.0, 164.2, 160.3, 159.9, 162.1, 164.6, 169.6, 167.4, 166.4, 171.0, 171.2, 172.6] with book_plots.figsize(y=2.5): plt.figure() ave = np.sum(weights) / len(weights) plt.errorbar(range(1,13), weights, label='weights', yerr=6, fmt='o', capthick=2, capsize=10) plt.plot([1, 12], [ave,ave], c='r', label='hypothesis') plt.xlim(0, 13) plt.ylim(145, 185) plt.xlabel('day') plt.ylabel('weight (lbs)') book_plots.show_legend() plt.grid(False)
def plot_hypothesis1(): with figsize(y=3.5): plt.figure() plt.errorbar([1, 2, 3], [170, 161, 169], xerr=0, yerr=10, fmt='bo', capthick=2, capsize=10) plt.plot([1, 3], [180, 160], color='g', ls='--') plt.plot([1, 3], [170, 170], color='g', ls='--') plt.plot([1, 3], [160, 175], color='g', ls='--') plt.plot([1, 2, 3], [180, 152, 179], color='g', ls='--') plt.xlim(0,4) plt.ylim(150, 185) plt.xlabel('day') plt.ylabel('lbs') plt.grid(False) plt.tight_layout()
def plot_hypothesis5(): weights = [158.0, 164.2, 160.3, 159.9, 162.1, 164.6, 169.6, 167.4, 166.4, 171.0, 171.2, 172.6] xs = range(1, len(weights)+1) line = np.poly1d(np.polyfit(xs, weights, 1)) with figsize(y=2.5): plt.figure() plt.errorbar(range(1, 13), weights, label='weights', yerr=5, fmt='o', capthick=2, capsize=10) plt.plot (xs, line(xs), c='r', label='hypothesis') plt.xlim(0, 13) plt.ylim(145, 185) plt.xlabel('day') plt.ylabel('weight (lbs)') book_plots.show_legend()
plt.bar(x,prior,width,label='Previsão') if do_print: print() print('final position is', robot.pos) index = np.argmax(posterior) print('''Estimated position is {} with ''' '''confidence {:.4f}%:'''.format( index, posterior[index]*100)) return m index = [1,2] index.extend([1,2,3,4]*3) #index = [1,2,3,4]*3 with figsize(y=5.5): j=1 flag = False for indice,i in enumerate(index): random.seed(3) if i == 1: plt.figure() elif indice == 14: break if indice == 0 or indice == 1: a = plt.subplot(1,2,i) else: a = plt.subplot(2,2,i) m = train_filter(indice, kernel=[.05,.1, .7, .1 ,.05], sensor_accuracy=.7,
dx = 5 count = 50 x0 = 5 dt = 1 h = 0.01 #re-seed the generation np.random.seed(100) vector = gen_data(x0=x0, dx=dx, count=count, noise_factor=noise_factor) data = range(3 * len(vector)) data = np.reshape(data, (3, len(vector))) for i in range(len(g)): data[i] = filter(data=vector, x0=0., dx=5., dt=1., g=g[i], h=0.01) with book_plots.figsize(y=4): book_plots.plot_measurements(vector, color='k') book_plots.plot_filter(data[0], label='g=0.1', marker='s', c='C0') book_plots.plot_filter(data[1], label='g=0.4', marker='v', c='C1') book_plots.plot_filter(data[2], label='g=0.8', c='C2') plt.legend(loc=4) book_plots.set_limits([20, 40], [50, 250]) plt.grid() plt.show() zs = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14] for i in range(50): zs.append(14) data1 = filter(data=zs, x0=4., dx=1., dt=1., g=0.1, h=0.01) data2 = filter(data=zs, x0=4., dx=1., dt=1., g=0.5, h=0.01)