Here are the examples of the python api bokeh.io.push_notebook taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
5 Examples
3
View Source File : plotting.py
License : MIT License
Project Creator : andyljones
License : MIT License
Project Creator : andyljones
def refresh(self):
reinit = self.refresh_groups()
if reinit:
self.initialize(rule=self.rule)
for subplot, plotter in self.plotters.items():
plotter.refresh()
if self.handle:
boi.push_notebook(handle=self.handle)
def review(run=-1, **kwargs):
3
View Source File : classes.py
License : GNU General Public License v3.0
Project Creator : lucasbellinaso
License : GNU General Public License v3.0
Project Creator : lucasbellinaso
def updateBokeh(self):
self.updateBodeData()
self.updateRLocusData()
self.updateStepResponse()
self.updateDistResponse({'new':'success'})
bokeh.io.push_notebook(handle = self.Bknb_handle);
def updateTransferFunction(self):
3
View Source File : classes.py
License : GNU General Public License v3.0
Project Creator : lucasbellinaso
License : GNU General Public License v3.0
Project Creator : lucasbellinaso
def updateRequirements(self,b):
max_overshot = 0.01*self.CtrAnWgt.OShotIn.value+1
self.shadowsource.data['overshot'] = [max_overshot, max_overshot]
self.shadowsource.data['risetime'] = [self.CtrAnWgt.RTimeIn.value, 1e4]
self.shadowsource.data['settlingtime'] = [self.CtrAnWgt.STimeIn.value, 1e4]
bokeh.io.push_notebook(handle = self.Bknb_handle)
def updateDistResponse(self,button_style):
3
View Source File : classes.py
License : GNU General Public License v3.0
Project Creator : lucasbellinaso
License : GNU General Public License v3.0
Project Creator : lucasbellinaso
def updateDistResponse(self,button_style):
if button_style['new']=='success' and len(self.CtrAnWgt.waveVec_dict['t_s']>90):
from control.matlab import lsim
t,r,du,dy,dm = map(self.CtrAnWgt.waveVec_dict.get, ('t_s','r','du','dy','dm'))
y, u = np.zeros_like(t), np.zeros_like(t)
yu,_,_ = lsim(self.sysMF, U=np.column_stack((r,du,dy,dm)), T=t)
ymf, umf = yu[:,0], yu[:,1]
self.tRespsource.data = {'t_s':t,'r':r,'du':du,'dy':dy,'dm':dm,'y':ymf,'u':umf}
ymin, ymax, umin, umax = np.min(ymf), np.max(ymf), np.min(umf), np.max(umf)
self.figTResp2.y_range.update(start = ymin - 0.05*(ymax-ymin),
end = ymax + 0.05*(ymax-ymin))
self.figTResp2.extra_y_ranges['u_range'].update(start = umin - 0.05*(umax-umin),
end = umax + 0.05*(umax-umin))
bokeh.io.push_notebook(handle = self.Bknb_handle)
0
View Source File : notears.py
License : BSD 3-Clause "New" or "Revised" License
Project Creator : cornell-zhang
License : BSD 3-Clause "New" or "Revised" License
Project Creator : cornell-zhang
def notears_live(G: nx.DiGraph,
X: np.ndarray,
lambda1: float,
max_iter: int = 100,
h_tol: float = 1e-8,
w_threshold: float = 0.3) -> np.ndarray:
"""Monitor the optimization progress live in notebook.
Args:
G: ground truth graph
X: [n,d] sample matrix
lambda1: l1 regularization parameter
max_iter: max number of dual ascent steps
h_tol: exit if |h(w)| < = h_tol
w_threshold: fixed threshold for edge weights
Returns:
W_est: [d,d] estimate
"""
# initialization
n, d = X.shape
w_est, w_new = np.zeros(d * d), np.zeros(d * d)
rho, alpha, h, h_new = 1.0, 0.0, np.inf, np.inf
# ground truth
w_true = nx.to_numpy_array(G).flatten()
# progress, stream
progress_data = {key:[] for key in ['step', 'F', 'h',
'rho', 'alpha', 'l2_dist']}
progress_source = ColumnDataSource(data=progress_data)
# heatmap, patch
ids = [str(i) for i in range(d)]
all_ids = np.tile(ids, [d, 1])
row = all_ids.T.flatten()
col = all_ids.flatten()
heatmap_data = {'row': row, 'col': col,
'w_true': w_true, 'w_est': w_est, 'w_diff': w_true - w_est}
heatmap_source = ColumnDataSource(data=heatmap_data)
mapper = LinearColorMapper(palette=Palette, low=-2, high=2)
# common tools
tools = 'crosshair,save,reset'
# F(w_est) vs step
F_true = cppext.F_func(w_true, X, lambda1)
fig0 = figure(plot_width=270, plot_height=240,
y_axis_type='log', tools=tools)
fig0.ray(0, F_true, length=0, angle=0, color='green',
line_dash='dashed', line_width=2, legend='F(w_true)')
fig0.line('step', 'F', source=progress_source,
color='red', line_width=2, legend='F(w_est)')
fig0.title.text = "Objective"
fig0.xaxis.axis_label = "step"
fig0.legend.location = "bottom_left"
fig0.legend.background_fill_alpha = 0.5
fig0.add_tools(HoverTool(tooltips=[("step", "@step"),
("F", "@F"),
("F_true", '%.6g' % F_true)],
mode='vline'))
# h(w_est) vs step
fig1 = figure(plot_width=280, plot_height=240,
y_axis_type='log', tools=tools)
fig1.line('step', 'h', source=progress_source,
color='magenta', line_width=2, legend='h(w_est)')
fig1.title.text = "Constraint"
fig1.xaxis.axis_label = "step"
fig1.legend.location = "bottom_left"
fig1.legend.background_fill_alpha = 0.5
fig1.add_tools(HoverTool(tooltips=[("step", "@step"),
("h", "@h"),
("rho", "@rho"),
("alpha", "@alpha")],
mode='vline'))
# ||w_true - w_est|| vs step
fig2 = figure(plot_width=270, plot_height=240,
y_axis_type='log', tools=tools)
fig2.line('step', 'l2_dist', source=progress_source,
color='blue', line_width=2)
fig2.title.text = "L2 distance to W_true"
fig2.xaxis.axis_label = "step"
fig2.add_tools(HoverTool(tooltips=[("step", "@step"),
("w_est", "@l2_dist")],
mode='vline'))
# heatmap of w_true
fig3 = figure(plot_width=270, plot_height=240,
x_range=ids, y_range=list(reversed(ids)), tools=tools)
fig3.rect(x='col', y='row', width=1, height=1, source=heatmap_source,
line_color=None, fill_color=transform('w_true', mapper))
fig3.title.text = 'W_true'
fig3.axis.visible = False
fig3.add_tools(HoverTool(tooltips=[("row, col", "@row, @col"),
("w_true", "@w_true")]))
# heatmap of w_est
fig4 = figure(plot_width=280, plot_height=240,
x_range=ids, y_range=list(reversed(ids)), tools=tools)
fig4.rect(x='col', y='row', width=1, height=1, source=heatmap_source,
line_color=None, fill_color=transform('w_est', mapper))
fig4.title.text = 'W_est'
fig4.axis.visible = False
fig4.add_tools(HoverTool(tooltips=[("row, col", "@row, @col"),
("w_est", "@w_est")]))
# heatmap of w_true - w_est
fig5 = figure(plot_width=270, plot_height=240,
x_range=ids, y_range=list(reversed(ids)), tools=tools)
fig5.rect(x='col', y='row', width=1, height=1, source=heatmap_source,
line_color=None, fill_color=transform('w_diff', mapper))
fig5.title.text = 'W_true - W_est'
fig5.axis.visible = False
fig5.add_tools(HoverTool(tooltips=[("row, col", "@row, @col"),
("w_diff", "@w_diff")]))
# display figures as grid
grid = gridplot([[fig0, fig1, fig2],
[fig3, fig4, fig5]], merge_tools=False)
handle = show(grid, notebook_handle=True)
# enter main loop
for it in range(max_iter):
while rho < 1e+20:
w_new = cppext.minimize_subproblem(w_est, X, rho, alpha, lambda1)
h_new = cppext.h_func(w_new)
if h_new > 0.25 * h:
rho *= 10
else:
break
w_est, h = w_new, h_new
alpha += rho * h
# update figures
progress_source.stream({'step': [it],
'F': [cppext.F_func(w_est, X, lambda1)],
'h': [h],
'rho': [rho],
'alpha': [alpha],
'l2_dist': [np.linalg.norm(w_est - w_true)],})
heatmap_source.patch({'w_est': [(slice(d * d), w_est)],
'w_diff': [(slice(d * d), w_true - w_est)]})
push_notebook(handle=handle)
# check termination of main loop
if h < = h_tol:
break
# final threshold
w_est[np.abs(w_est) < w_threshold] = 0
return w_est.reshape([d, d])