def __init__(self): super().__init__() self.model = None self.forest_adapter = None self.instances = None self.clf_dataset = None # We need to store refernces to the trees and grid items self.grid_items, self.ptrees = [], [] # In some rare cases, we need to prevent commiting, the only one # that this currently helps is that when changing the size calculation # the trees are all recomputed, but we don't want to output a new tree # to keep things consistent with other ui controls. self.__prevent_commit = False self.color_palette = None # Different methods to calculate the size of squares self.SIZE_CALCULATION = [ ('Normal', lambda x: x), ('Square root', lambda x: sqrt(x)), ('Logarithmic', lambda x: log(x + 1)), ] # CONTROL AREA # Tree info area box_info = gui.widgetBox(self.controlArea, 'Forest') self.ui_info = gui.widgetLabel(box_info) # Display controls area box_display = gui.widgetBox(self.controlArea, 'Display') self.ui_depth_slider = gui.hSlider(box_display, self, 'depth_limit', label='Depth', ticks=False, callback=self.update_depth) self.ui_target_class_combo = gui.comboBox(box_display, self, 'target_class_index', label='Target class', orientation=Qt.Horizontal, items=[], contentsLength=8, callback=self.update_colors) self.ui_size_calc_combo = gui.comboBox( box_display, self, 'size_calc_idx', label='Size', orientation=Qt.Horizontal, items=list(zip(*self.SIZE_CALCULATION))[0], contentsLength=8, callback=self.update_size_calc) self.ui_zoom_slider = gui.hSlider(box_display, self, 'zoom', label='Zoom', ticks=False, minValue=20, maxValue=150, callback=self.zoom_changed, createLabel=False) # Stretch to fit the rest of the unsused area gui.rubber(self.controlArea) self.controlArea.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Expanding) # MAIN AREA self.scene = QGraphicsScene(self) self.scene.selectionChanged.connect(self.commit) self.grid = OWGrid() self.grid.geometryChanged.connect(self._update_scene_rect) self.scene.addItem(self.grid) self.view = QGraphicsView(self.scene) self.view.setRenderHint(QPainter.Antialiasing, True) self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.mainArea.layout().addWidget(self.view) self.resize(800, 500) self.clear()
def __init__(self): super().__init__() # Instance variables self.forest_type = self.CLASSIFICATION self.model = None self.forest_adapter = None self.dataset = None self.clf_dataset = None # We need to store refernces to the trees and grid items self.grid_items, self.ptrees = [], [] self.color_palette = None # Different methods to calculate the size of squares self.SIZE_CALCULATION = [ ('Normal', lambda x: x), ('Square root', lambda x: sqrt(x)), ('Logarithmic', lambda x: log(x * self.size_log_scale)), ] self.REGRESSION_COLOR_CALC = [ ('None', lambda _, __: QtGui.QColor(255, 255, 255)), ('Class mean', self._color_class_mean), ('Standard deviation', self._color_stddev), ] # CONTROL AREA # Tree info area box_info = gui.widgetBox(self.controlArea, 'Forest') self.ui_info = gui.widgetLabel(box_info, label='') # Display controls area box_display = gui.widgetBox(self.controlArea, 'Display') self.ui_depth_slider = gui.hSlider( box_display, self, 'depth_limit', label='Depth', ticks=False, callback=self.max_depth_changed) self.ui_target_class_combo = gui.comboBox( box_display, self, 'target_class_index', label='Target class', orientation='horizontal', items=[], contentsLength=8, callback=self.target_colors_changed) self.ui_size_calc_combo = gui.comboBox( box_display, self, 'size_calc_idx', label='Size', orientation='horizontal', items=list(zip(*self.SIZE_CALCULATION))[0], contentsLength=8, callback=self.size_calc_changed) self.ui_zoom_slider = gui.hSlider( box_display, self, 'zoom', label='Zoom', ticks=False, minValue=20, maxValue=150, callback=self.zoom_changed, createLabel=False) # Stretch to fit the rest of the unsused area gui.rubber(self.controlArea) self.controlArea.setSizePolicy( QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Expanding) # MAIN AREA self.scene = QtGui.QGraphicsScene(self) self.scene.selectionChanged.connect(self.commit) self.grid = OWGrid() self.grid.geometryChanged.connect(self._update_scene_rect) self.scene.addItem(self.grid) self.view = QtGui.QGraphicsView(self.scene) self.view.setRenderHint(QtGui.QPainter.Antialiasing, True) self.view.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn) self.mainArea.layout().addWidget(self.view) self.resize(800, 500) self.clear()