def cb(y, active_set, counter, current): solution = np.empty(len(y)) for v, w, f, l in active_set: solution[f:f + l] = max(v, 0) / w * g**np.arange(l) plt.figure(figsize=(3, 3)) color = y.copy() plt.plot(solution, c='k', zorder=-11, lw=1.2) plt.scatter(np.arange(len(y)), solution, s=60, cmap=plt.cm.Spectral, c=color, clip_on=False, zorder=11) plt.scatter([np.arange(len(y))[current]], [solution[current]], s=200, lw=2.5, marker='+', color='b', clip_on=False, zorder=11) for a in active_set[::2]: plt.axvspan(a[2], a[2] + a[3], alpha=0.1, color='k', zorder=-11) for x in np.where(trueSpikes)[0]: plt.plot([x, x], [0, 1.65], lw=1.5, c='r', zorder=-12) plt.xlim((0, len(y) - .5)) plt.ylim((0, 1.65)) simpleaxis(plt.gca()) plt.xticks([]) plt.yticks([]) # plt.tight_layout() if save_figs: plt.savefig('fig/%d.pdf' % counter) plt.show()
def plot_trace(n=0, lg=False): plt.plot(trueC[n], c=col[2], clip_on=False, zorder=5, label='Truth') plt.plot(solution, c=col[0], clip_on=False, zorder=7, label='Estimate') plt.plot(y, c=col[7], alpha=.7, lw=1, clip_on=False, zorder=-10, label='Data') if lg: plt.legend(frameon=False, ncol=3, loc=(.1, .62), columnspacing=.8) spks = np.append(0, solution[1:] - g * solution[:-1]) plt.text(800, 2.2, 'Correlation: %.3f' % (np.corrcoef(trueSpikes[n], spks)[0, 1]), size=24) plt.gca().set_xticklabels([]) simpleaxis(plt.gca()) plt.ylim(0, 2.85) plt.xlim(0, 1500) plt.yticks([0, 2], [0, 2]) plt.xticks([300, 600, 900, 1200], ['', ''])
def plotTrace(lg=False): fig = plt.figure(figsize=(10, 9)) fig.add_axes([.13, .7, .86, .29]) plt.plot(c, c=col[0], label='L1') plt.plot(c_t, c=col[1], label='Thresh.') plt.plot(trueC[0], c=col[2], lw=3, label='Truth', zorder=-5) plt.plot(y, c=col[7], lw=1.5, alpha=.7, zorder=-10, label='Data') if lg: plt.legend(frameon=False, ncol=4, loc=(.05, .82)) plt.gca().set_xticklabels([]) simpleaxis(plt.gca()) plt.yticks([0, int(y.max())], [0, int(y.max())]) plt.xticks(range(150, 500, 150), [''] * 3) plt.ylabel('Fluor.') plt.xlim(0, 452) fig.add_axes([.13, .39, .86, .29]) for i, ss in enumerate(s[:500]): if ss > 1e-2: plt.plot([i, i], [2.5, 2.5 + ss], c=col[0], zorder=10) plt.plot([0, 450], [2.5, 2.5], c=col[0], zorder=10) for i, ss in enumerate(s_t[:500]): if ss > 1e-2: plt.plot([i, i], [1.25, 1.25 + ss], c=col[1], zorder=10) plt.plot([0, 450], [1.25, 1.25], c=col[1], zorder=10) for i, ss in enumerate(trueSpikes[0, :500]): if ss > 1e-2: plt.plot([i, i], [0, ss], c=col[2], clip_on=False, zorder=10) plt.plot([0, 450], [0, 0], c=col[2], clip_on=False, zorder=10) plt.gca().set_xticklabels([]) simpleaxis(plt.gca()) plt.yticks([0, 1.25, 2.5], ['Truth', 'Thresh.', 'L1']) for tick in plt.gca().yaxis.get_major_ticks(): tick.label1.set_verticalalignment('bottom') plt.xticks(range(150, 500, 150), [''] * 3) plt.ylim(0, 3.5) plt.xlim(0, 452) fig.add_axes([.13, .08, .86, .29]) for i, r in enumerate(res): for rr in r: plt.plot([rr, rr], [.1 * i - .04, .1 * i + .04], c='k') for rr in np.where(trueSpikes[0])[0]: plt.plot([rr, rr], [-.08, -.16], c='r') plt.gca().set_xticklabels([]) simpleaxis(plt.gca()) plt.yticks([0, .5, 1], [0, 0.5, 1.0]) plt.xticks(range(0, 500, 150), [0, 5, 10, '']) plt.ylim(-.2, 1.1) plt.xlim(0, 452) plt.ylabel(r'$s_{\min}$') plt.xlabel('Time [s]', labelpad=-10) plt.show()
a[0] -= lam * (1 - g**len(a[2])) a_s_tmp[-1][0] -= lam for v, w, idx in a_s_tmp: solution[idx] = v / w * g**np.arange(len(idx)) # plot to illustrate updating lambda ax = fig.add_axes([ax0, .73, .08, .12]) plt.plot(np.linspace(0, 1.7), [(res - x * tmp).dot(res - x * tmp) for x in np.linspace(0, 1.7)], c=col[1]) plt.plot([-.1, ll], [sn**2 * T, sn**2 * T], c='k') plt.plot([ll, ll], [100, sn**2 * T], c='k') plt.scatter([0], [RSS], s=50, c=col[0], zorder=11, clip_on=False) plt.text(.007, 3 + RSS, '$\lambda^-$', color=col[0]) plt.xticks([0, ll], [0, '$\lambda^*$']) plt.yticks([sn**2 * T], ['$\sigma^2 T$']) simpleaxis(plt.gca()) plt.xlim(0, 1.6) plt.ylim(114, 138) plt.xlabel('$\lambda$', labelpad=-40, x=1.1) plt.ylabel('RSS', labelpad=-30, y=.42) # plot result after updating lambda, but before rerunning oasis to fix violations ax = fig.add_axes([ax1, .73, 1 - ax1, .12]) plot_trace(n) # plot result after rerunning oasis to fix violations solution, active_set = foo(active_set, g, ll) ax = fig.add_axes([ax1, .59, 1 - ax1, .12]) plot_trace(n) plt.ylabel('Fluorescence', y=0) # solve for gamma
def cb(y, active_set, counter, current): solution = np.empty(len(y)) for i, (v, w, f, l) in enumerate(active_set): solution[f:f + l] = (v if i else max(v, 0)) / w * g**np.arange(l) color = y.copy() ax1.plot(solution, c='k', zorder=-11, lw=1.3, clip_on=False) ax1.scatter(np.arange(len(y)), solution, s=40, cmap=plt.cm.Spectral, c=color, clip_on=False, zorder=11) ax1.scatter([np.arange(len(y))[current]], [solution[current]], s=120, lw=2.5, marker='+', color='b', clip_on=False, zorder=11) for a in active_set[::2]: ax1.axvspan(a[2], a[2] + a[3], alpha=0.1, color='k', zorder=-11) for x in np.where(trueSpikes)[0]: ax1.plot([x, x], [0, 2.3], lw=1.5, c='r', zorder=-12) ax1.set_xlim((0, len(y) - .5)) ax1.set_ylim((0, 2.3)) simpleaxis(ax1) ax1.set_xticks([]) ax1.set_yticks([]) ax1.set_ylabel('Fluorescence') for i, s in enumerate(np.r_[[0], solution[1:] - g * solution[:-1]]): ax2.plot([i, i], [0, s], c='k', zorder=-11, lw=1.4, clip_on=False) ax2.scatter(np.arange(len(y)), np.r_[[0], solution[1:] - g * solution[:-1]], s=40, cmap=plt.cm.Spectral, c=color, clip_on=False, zorder=11) ax2.scatter([np.arange(len(y))[current]], [np.r_[[0], solution[1:] - g * solution[:-1]][current]], s=120, lw=2.5, marker='+', color='b', clip_on=False, zorder=11) for a in active_set[::2]: ax2.axvspan(a[2], a[2] + a[3], alpha=0.1, color='k', zorder=-11) for x in np.where(trueSpikes)[0]: ax2.plot([x, x], [0, 1.55], lw=1.5, c='r', zorder=-12) ax2.set_xlim((0, len(y) - .5)) ax2.set_ylim((0, 1.55)) simpleaxis(ax2) ax2.set_xticks([]) ax2.set_yticks([]) ax2.set_xlabel('Time', labelpad=35, x=.5) ax2.set_ylabel('Spikes') plt.subplots_adjust(left=0.032, right=.995, top=.995, bottom=0.19, hspace=0.22) # fig.canvas.draw() if save_figs: plt.savefig('video/%03d.pdf' % counter) plt.pause(1e-9) ax1.clear() ax2.clear()