Repository navigation
Expand file tree
/
Copy pathGP2.py
More file actions
43 lines (32 loc) · 1.86 KB
/
Copy pathGP2.py
File metadata and controls
43 lines (32 loc) · 1.86 KB
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
def GP2(doc):
from gaussianProcessUtils import drawContour, resample_givenX1, update_normal
from bokeh.layouts import widgetbox, gridplot
from bokeh.models import Slider
from bokeh.plotting import figure, ColumnDataSource
def resample_wrapper():
source.data=resample_givenX1(samples_slider.value,covariance_slider.value, x1_slider.value)
def update_xs():
resample_wrapper()
source3.data = update_normal(covariance_slider.value, x1_slider.value)
def update_all():
source2.data = drawContour(covariance_slider.value)
resample_wrapper()
source3.data = update_normal(covariance_slider.value, x1_slider.value)
source = ColumnDataSource(data=dict(x1=[0], x2=[0]))
source2 = ColumnDataSource(data=dict(xs=[0], ys=[0]))
source3 = ColumnDataSource(data=dict(xs=[0], ys=[0]))
plot = figure(y_range=(-3, 3), x_range=(-3, 3), plot_width=400, plot_height=400, x_axis_label='y1', y_axis_label='y2')
plot.scatter('x1', 'x2', source=source, line_width=3, line_alpha=0.6)
plot.multi_line(xs='xs', ys='ys', line_color='line_color', source=source2)
plot.line(x='xs', y='ys', source=source3, line_width=3, line_alpha=0.6, line_color='red')
covariance_slider = Slider(start=0.0, end=.99, value=0, step=.01,title="Covariance")
samples_slider = Slider(start=1, end=100, value=10, step=1,title="Number of Samples")
x1_slider = Slider(start=-2.5, end=2.5, value=0, step=.1,title="y1")
covariance_slider.on_change('value', lambda attr, old, new: update_all())
samples_slider.on_change('value', lambda attr, old, new: resample_wrapper())
x1_slider.on_change('value', lambda attr, old, new: update_xs())
controls = [covariance_slider, samples_slider, x1_slider]
inputs = widgetbox(*controls, sizing_mode='fixed')
l = gridplot([[inputs],[plot]])
update_all()
doc.add_root(l)