def _create_resizable_view(self): # resizable_view factory, as I need to compute the height of the plot # from the number of annotations, and I couldn't find any other way to # do that # "touch" posterior_plot to have it initialize self.plot_container if is_display_small(): height = 760 else: height = 800 resizable_plot_item = ( Item( 'plot_container', editor=ComponentEditor(), resizable=True, show_label=False, width = self.plot_width, height = self.plot_height, ) ) resizable_view = View( VGroup( Include('instructions_group'), resizable_plot_item, ), width = 450, height = height, resizable = True ) return resizable_view
def _traits_plot_item_default(self): height = -220 if is_display_small() else -280 return Item('theta_plot', editor=ComponentEditor(), resizable=False, show_label=False, height=height)
def _theta_plot_default(self): theta = self.theta nclasses = theta.shape[0] # create a plot data object and give it this data plot_data = ArrayPlotData() plot_data.set_data('classes', range(nclasses)) # create the plot plot = Plot(plot_data) # --- plot theta samples if self.theta_samples is not None: self._plot_samples(plot, plot_data) # --- plot values of theta plots = self._plot_theta_values(plot, plot_data) # --- adjust plot appearance plot.aspect_ratio = 1.6 if is_display_small() else 1.7 # adjust axis bounds y_high = theta.max() if self.theta_samples is not None: y_high = max(y_high, self.theta_samples.max()) plot.range2d = DataRange2D( low = (-0.2, 0.0), high = (nclasses-1+0.2, y_high*1.1) ) # create new horizontal axis label_axis = self._create_increment_one_axis( plot, 0., nclasses, 'bottom') label_axis.title = 'True classes' self._add_index_axis(plot, label_axis) # label vertical axis plot.value_axis.title = 'Probability' # add legend legend = Legend(component=plot, plots=plots, align="ur", border_padding=10) legend.tools.append(LegendTool(legend, drag_button="left")) legend.padding_right = -100 plot.overlays.append(legend) container = VPlotContainer(width=plot.width + 100, halign='left') plot.padding_bottom = 50 plot.padding_top = 10 plot.padding_left = 0 container.add(plot) container.bgcolor = 0xFFFFFF self.decorate_plot(container, theta) return container
def _theta_plot_default(self): theta = self.theta nclasses = theta.shape[0] # create a plot data object and give it this data plot_data = ArrayPlotData() plot_data.set_data('classes', list(range(nclasses))) # create the plot plot = Plot(plot_data) # --- plot theta samples if self.theta_samples is not None: self._plot_samples(plot, plot_data) # --- plot values of theta plots = self._plot_theta_values(plot, plot_data) # --- adjust plot appearance plot.aspect_ratio = 1.6 if is_display_small() else 1.7 # adjust axis bounds y_high = theta.max() if self.theta_samples is not None: y_high = max(y_high, self.theta_samples.max()) plot.range2d = DataRange2D(low=(-0.2, 0.0), high=(nclasses - 1 + 0.2, y_high * 1.1)) # create new horizontal axis label_axis = self._create_increment_one_axis(plot, 0., nclasses, 'bottom') label_axis.title = 'True classes' self._add_index_axis(plot, label_axis) # label vertical axis plot.value_axis.title = 'Probability' # add legend legend = Legend(component=plot, plots=plots, align="ur", border_padding=10) legend.tools.append(LegendTool(legend, drag_button="left")) legend.padding_right = -100 plot.overlays.append(legend) container = VPlotContainer(width=plot.width + 100, halign='left') plot.padding_bottom = 50 plot.padding_top = 10 plot.padding_left = 0 container.add(plot) container.bgcolor = 0xFFFFFF self.decorate_plot(container, theta) return container
def traits_view(self): w_view = 350 if is_display_small() else 480 parameters_group = VGroup( Item('_'), HGroup( VGroup( Spring(), Item('handler.omega_hinton_diagram', style='custom', resizable=False, show_label=False, width=w_view), Spring()), Spring(), VGroup(Spring(), Item('handler.view_omega', show_label=False), Spring())), Spring(), Item('_'), Spring(), HGroup( VGroup( UItem('handler.theta_views'), UItem('handler.theta_view', style='custom', resizable=False, width=w_view), Spring()), Spring(), VGroup(Spring(), UItem('handler.view_theta'), Spring()))) body = VGroup(Include('info_group'), parameters_group) traits_view = View(body, buttons=[OKButton], resizable=True) return traits_view
def _create_resizable_view(self): # resizable_view factory, as I need to compute the height of the plot # from the number of annotations, and I couldn't find any other way to # do that # "touch" posterior_plot to have it initialize self.plot_container if is_display_small(): height = 760 else: height = 800 resizable_plot_item = (Item( 'plot_container', editor=ComponentEditor(), resizable=True, show_label=False, width=self.plot_width, height=self.plot_height, )) resizable_view = View(VGroup( Include('instructions_group'), resizable_plot_item, ), width=450, height=height, resizable=True) return resizable_view
def _traits_plot_item_default(self): height = -220 if is_display_small() else -280 return Item('theta_plot', editor=ComponentEditor(), resizable=False, show_label=False, height=height )
def traits_view(self): if is_display_small(): w_view = 350 else: w_view = 480 parameters_group = VGroup( Item('_'), HGroup( VGroup( Spring(), Item('handler.gamma_hinton', style='custom', resizable=False, show_label=False, width=w_view ), Spring() ), Spring(), VGroup( Spring(), Item('handler.view_gamma', show_label=False), Spring() ) ), Spring(), Item('_'), Spring(), HGroup( VGroup( UItem('handler.theta_views'), UItem('handler.theta_view', style='custom', resizable=False, width=w_view ), Spring() ), Spring(), VGroup( Spring(), UItem('handler.view_theta'), Spring() ) ) ) body = VGroup( Include('info_group'), parameters_group, ) traits_view = View(body, buttons=[OKButton], resizable=True) return traits_view
def traits_view(self): if is_display_small(): w_view = 350 else: w_view = 450 info_group = VGroup(Item('_name', label='Annotations name:', style='readonly', padding=0), VGrid(Item('_nclasses', label='Number of classes:', style='readonly', width=10), Item('_labels', label='Labels:', style='readonly'), Item('_nannotators', label='Number of annotators:', style='readonly', width=10), Item('_nitems', label='Number of items:', style='readonly'), padding=0), padding=0) body = VGroup( info_group, Item('_'), HGroup( VGroup( Spring(), Item('frequency_plot', style='custom', resizable=False, show_label=False, width=w_view), Spring()), Spring(), VGroup( Spring(), Item('edit_data', enabled_when='annotations_are_defined', show_label=False), Item('save_data', enabled_when='annotations_are_defined', show_label=False), Spring())), Spring(), Item('_'), ) traits_view = View(body) return traits_view
def traits_view(self): height = 760 if is_display_small() else 900 traits_view = View(VGroup(VGroup( Item('show_maximum', label='Show MAP estimate (circle)'), Item('show_majority_vote', label='Show majority vote (triangle)'), ), VGroup( Item('posterior_plot', editor=InstanceEditor(), style='custom', show_label=False), ), padding=0), height=height, scrollable=True, resizable=True) return traits_view
def traits_view(self): height = 760 if is_display_small() else 900 traits_view = View( VGroup( VGroup( Item('show_maximum', label='Show MAP estimate (circle)'), Item('show_majority_vote', label='Show majority vote (triangle)'), ), VGroup( Item('posterior_plot', editor=InstanceEditor(), style='custom', show_label=False), ), padding=0 ), height = height, scrollable=True, resizable=True ) return traits_view
def _plot_width_default(self): return 450 if is_display_small() else 500
def traits_view(self): if is_display_small(): w_view = 350 else: w_view = 450 info_group = VGroup( Item('_name', label='Annotations name:', style='readonly', padding=0), VGrid( Item('_nclasses', label='Number of classes:', style='readonly', width=10), Item('_labels', label='Labels:', style='readonly'), Item('_nannotators', label='Number of annotators:', style='readonly', width=10), Item('_nitems', label='Number of items:', style='readonly'), padding=0 ), padding=0 ) body = VGroup( info_group, Item('_'), HGroup( VGroup( Spring(), Item('frequency_plot', style='custom', resizable=False, show_label=False, width=w_view ), Spring() ), Spring(), VGroup( Spring(), Item('edit_data', enabled_when='annotations_are_defined', show_label=False), Item('save_data', enabled_when='annotations_are_defined', show_label=False), Spring() ) ), Spring(), Item('_'), ) traits_view = View(body) return traits_view
def traits_view(self): ## Model view # adjust sizes to display size if is_display_small(): # full view size w_view, h_view = 1024, 768 w_data_create_group = 350 w_data_info_group = 500 h_annotations_stats = 270 else: w_view, h_view = 1300, 850 w_data_create_group = 400 w_data_info_group = 700 h_annotations_stats = 330 model_create_group = ( VGroup( HGroup( UItem(name='model_name',width=200), UItem(name='new_model', width=100), UItem(name='get_info_on_model', width=100, height=25), ), label = 'Create new model' ) ) model_group = ( VGroup ( model_create_group, VGroup( Item( 'model_view', style='custom', show_label=False, width=400 ), label = 'Model view', ), ), ) ## Data view data_create_group = VGroup( #Label('Open annotation file:', width=800), HGroup( Item('annotations_file', style='simple', label='Open file:', width=w_data_create_group, height=25), UItem('new_annotations', height=25) ), label = 'Load/create annotations', show_border = False, ) data_info_group = VGroup( Item('annotations_view', style='custom', show_label=False, visible_when='annotations_are_defined', width=w_data_info_group, ), Item('annotations_stats_view', style='custom', show_label=False, visible_when='annotations_are_defined', height=h_annotations_stats), label = 'Data view', ) data_group = ( VGroup ( data_create_group, data_info_group, ), ) ## (Model,Data) view model_data_group = ( VGroup( #Item('info_string', show_label=False, style='readonly'), Item('log_likelihood', label='Log likelihood', style='readonly'), HGroup( Item('ml_estimate', enabled_when='annotations_are_defined'), Item('map_estimate', enabled_when='annotations_are_defined'), Item('sample_posterior_over_accuracy', enabled_when='annotations_are_defined'), Item('estimate_labels', enabled_when='annotations_are_defined'), Spring(), Item('add_to_database', enabled_when='annotations_are_defined'), Item('open_database'), show_labels=False, ), label = 'Model-data view', ) ) ## Full view full_view = View( VGroup( HGroup( model_group, data_group ), model_data_group, ), title='PyAnno - Models of data annotations by multiple curators', width = w_view, height = h_view, resizable = False ) return full_view
def traits_view(self): if is_display_small(): w_view = 400 else: w_view = 510 parameters_group = VGroup( Item('_'), HGroup( Item('handler.edit_prior', show_label=False, width=100), Spring(), ), Item('_'), HGroup( VGroup( Spring(), Item('handler.pi_hinton_diagram', style='custom', resizable=False, show_label=False, width=w_view), Spring(), ), Spring(), VGroup( Spring(), Item('handler.view_pi', show_label=False), Spring() ), ), Item('_'), HGroup( VGroup( Item('handler.theta_views', show_label=False), Item('handler.theta_view', style='custom', resizable=False, show_label=False, width = w_view), Spring() ), VGroup( Spring(), Item('handler.view_theta', show_label=False), Spring() ) ), ) body = VGroup( Include('info_group'), parameters_group ) traits_view = View(body, buttons=[OKButton], resizable=True) return traits_view
def _theta_plot_default(self): theta = self.theta nannotators = theta.shape[0] samples = self.theta_samples # plot data object plot_data = ArrayPlotData() # create the plot plot = Plot(plot_data) # --- plot theta as vertical dashed lines # add vertical lines extremes plot_data.set_data('line_extr', [0., 1.]) for k in range(nannotators): name = self._theta_name(k) plot_data.set_data(name, [theta[k], theta[k]]) plots = {} for k in range(nannotators): name = self._theta_name(k) line_plot = plot.plot( (name, 'line_extr'), line_width = 2., color = get_annotator_color(k), line_style = 'dash', name = name ) plots[name] = line_plot # --- plot samples as distributions if samples is not None: bins = np.linspace(0., 1., 100) max_hist = 0. for k in range(nannotators): name = self._theta_name(k) + '_distr_' hist, x = np.histogram(samples[:,k], bins=bins) hist = hist / float(hist.sum()) max_hist = max(max_hist, hist.max()) # make "bars" out of histogram values y = np.concatenate(([0], np.repeat(hist, 2), [0])) plot_data.set_data(name+'x', np.repeat(x, 2)) plot_data.set_data(name+'y', y) for k in range(nannotators): name = self._theta_name(k) + '_distr_' plot.plot((name+'x', name+'y'), line_width = 2., color = get_annotator_color(k) ) # --- adjust plot appearance plot.aspect_ratio = 1.6 if is_display_small() else 1.7 plot.padding = [20,0,10,40] # adjust axis bounds x_low, x_high = theta.min(), theta.max() y_low, y_high = 0., 1. if samples is not None: x_high = max(x_high, samples.max()) x_low = min(x_low, samples.min()) y_high = max_hist plot.range2d = DataRange2D( low = (max(x_low-0.05, 0.), y_low), high = (min(x_high*1.1, 1.), min(y_high*1.1, 1.)) ) # label axes plot.value_axis.title = 'Probability' plot.index_axis.title = 'Theta' # add legend legend = Legend(component=plot, plots=plots, align="ul", padding=5) legend.tools.append(LegendTool(legend, drag_button="left")) plot.overlays.append(legend) container = VPlotContainer() container.add(plot) container.bgcolor = 0xFFFFFF self.decorate_plot(container, theta) self._set_title(plot) return container
def _plot_height_default(self): return 600 if is_display_small() else 750
def traits_view(self): ## Model view # adjust sizes to display size if is_display_small(): # full view size w_view, h_view = 1024, 768 w_data_create_group = 350 w_data_info_group = 500 h_annotations_stats = 270 else: w_view, h_view = 1300, 850 w_data_create_group = 400 w_data_info_group = 700 h_annotations_stats = 330 model_create_group = (VGroup(HGroup( UItem(name='model_name', width=200), UItem(name='new_model', width=100), UItem(name='get_info_on_model', width=100, height=25), ), label='Create new model')) model_group = (VGroup( model_create_group, VGroup( Item('model_view', style='custom', show_label=False, width=400), label='Model view', ), ), ) ## Data view data_create_group = VGroup( #Label('Open annotation file:', width=800), HGroup( Item('annotations_file', style='simple', label='Open file:', width=w_data_create_group, height=25), UItem('new_annotations', height=25)), label='Load/create annotations', show_border=False, ) data_info_group = VGroup( Item( 'annotations_view', style='custom', show_label=False, visible_when='annotations_are_defined', width=w_data_info_group, ), Item('annotations_stats_view', style='custom', show_label=False, visible_when='annotations_are_defined', height=h_annotations_stats), label='Data view', ) data_group = (VGroup( data_create_group, data_info_group, ), ) ## (Model,Data) view model_data_group = ( VGroup( #Item('info_string', show_label=False, style='readonly'), Item('log_likelihood', label='Log likelihood', style='readonly'), HGroup( Item('ml_estimate', enabled_when='annotations_are_defined'), Item('map_estimate', enabled_when='annotations_are_defined'), Item('sample_posterior_over_accuracy', enabled_when='annotations_are_defined'), Item('estimate_labels', enabled_when='annotations_are_defined'), Spring(), Item('add_to_database', enabled_when='annotations_are_defined'), Item('open_database'), show_labels=False, ), label='Model-data view', )) ## Full view full_view = View( VGroup( HGroup(model_group, data_group), model_data_group, ), title='PyAnno - Models of data annotations by multiple curators', width=w_view, height=h_view, resizable=False) return full_view