class Coins(): """Coin tossing simulator class.""" # %% def __init__(self): title = Div(text="""<h1>Coin tossing simulation</h1>""" """<p>Simulates the effects of tossing a coin """ """many times. Heads are scored 1 and tails 0. """ """The chart shows the cumlative mean, which """ """should go to 0.5 in 'the long run'. To use """ """the software, select the number of coin """ """tosses or press go to generate a fresh """ """data set.</p>""", sizing_mode="""stretch_width""") self.tosses = 2000 self.toss_count = Spinner(step=1, value=self.tosses, title="""Number of tosses""", sizing_mode="""stretch_width""") self.go = Button(label="Button", button_type="""success""", sizing_mode="""stretch_width""") chart = Figure(title='Cumulative mean of coin tosses', x_axis_label='Number of tosses', y_axis_label='Cumulative mean') self.cds = ColumnDataSource() self.make_means() chart.line(source=self.cds, x='tosses', y='means', line_color='red', line_width=4, line_alpha=0.5) chart.title.text_font_size = '20px' chart.xaxis.axis_label_text_font_size = '15px' chart.xaxis.major_label_text_font_size = '15px' chart.yaxis.axis_label_text_font_size = '15px' chart.yaxis.major_label_text_font_size = '15px' title_bar = column(children=[title], sizing_mode="stretch_both") widget_bar = column(children=[self.toss_count, self.go], sizing_mode='fixed', width=250, height=500) chart_row = row(children=[widget_bar, chart], sizing_mode='stretch_both') self.layout = column(children=[title_bar, chart_row], sizing_mode='stretch_both') # %% def setup(self): """Setup the callbacks""" self.toss_count.on_change('value', self.callback_toss_count) self.go.on_change('clicks', self.callback_go) # %% def callback_toss_count(self, attrname, old, new): """Callback method for mean count""" self.tosses = self.toss_count.value self.make_means() # %% def callback_go(self, attrname, old, new): """Callback method for mean count""" self.make_means() # %% def make_means(self): """Create thje means be generating a random number serioes.""" heads = np.random.randint(2, size=self.toss_count.value) means = np.cumsum(heads) / np.arange(1, self.toss_count.value + 1) self.cds.data = {'tosses': range(1, self.tosses + 1), 'means': means}
if entity: ent_index = sent.index(entity) tmp = sent[:ent_index] + a_template.format(entity) + sent[ent_index + len(entity):] sent = tmp for ent in ents: try: ent_index = sent.index(ent) tmp = sent[:ent_index] + c_template.format(ent) + sent[ent_index + len(ent):] sent = tmp except: continue raw_str += sent raw_str += "</p>" return raw_str search_icon.on_change('button_type', update_ner) ner_select.on_change('value', update_ner) # inital update_ner(None, None, None) l = layout([row(column(text, ner_select, search_icon), column(cand_text))]) curdoc().add_root(l) curdoc().title = "Search Tool for Detecting Entities and Events"
###################### # Callback behaviour # ###################### sample_fun_input_f.on_change('value', sample_fun_input_modified) Wavelet_fun_input.on_change('value', Wavelet_fun_modified) Wavelet_fun_input.on_change('label', update) T0_input.on_change('value', update) T1_input.on_change('value', update) Amp_input.on_change('value', update) User_Func.on_change('value', update) Resolution.on_change('value', update) a_param.on_change('value', param_change) b_param.on_change('value', param_change) Trigonometric_radio.on_change('active', Trig_fun_modified) Frequency_Slider.on_change('value', Trig_fun_modified) Calc_button.on_change('clicks', update) ############################ # Description and warnings # ############################ description_filename = join(dirname(__file__), "description.html") loading_spinner_filename = join(dirname(__file__), "loading_spinner.html") choose_WaveLet_error_filename = join(dirname(__file__), "choose_WaveLet_error.html") choose_SampleFunc_error_filename = join(dirname(__file__), "choose_SampleFunc_error.html") user_function_error_filename = join(dirname(__file__), "user_function_error.html") description = LatexDiv(text=open(description_filename).read(), render_as_text=False,
alpha = alphaSlider.value offset = offsetSlider.value response.data['y'] = contrast**alpha + offset response_plus_noise.data['y'] = contrast**alpha + offset + (np.random.random(contrast.shape)-0.5)/CNR baseline.data['y'] = offset*np.ones(contrast.shape) baseline_plus_noise.data['y'] = offset+(np.random.random(contrast.shape)-0.5)/CNR p1.title = 'CNR = %2.1f' %CNR # sim some data data = np.zeros([nRep,3]) for iRep in range(nRep): stim = offset + np.array([0.08,0.16,0.32])**alpha + (np.random.random((1,3))-0.5)/CNR fonly = offset + (np.random.random()-0.5)/CNR data[iRep,:] = stim - fonly # and push to plots for iC,c in enumerate([0.08,0.16,0.32]): data_all[iC].data['y'] = data[:,iC] data_all[iC].data['x'] = c*np.ones([nRep]) data_means.data['y'] = np.mean(data,axis=0) for iC,c in enumerate([0.08,0.16,0.32]): data_eb[iC].data['y'] = np.mean(data[:,iC]) + np.std(data[:,iC])/np.sqrt(nRep)*np.array([-1,1]) CNRslider.on_change('value',update) nREPslider.on_change('value',update) alphaSlider.on_change('value',update) offsetSlider.on_change('value',update) redrawButton.on_change('clicks',update)