Changeset 10832:c101ce95dd16 in orange
 Timestamp:
 04/20/12 13:07:39 (2 years ago)
 Branch:
 default
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

Orange/OrangeWidgets/Prototypes/OWPCA.py
r10812 r10832 22 22 from plot.owcurve import OWCurve 23 23 from plot import owaxis 24 24 25 25 26 class ScreePlot(OWPlot): … … 49 50 if self.is_cutoff_enabled() and event.buttons() & Qt.LeftButton: 50 51 pos = self.mapToScene(event.pos()) 51 x, _ 52 x, _ = self.map_from_graph(pos) 52 53 xmin, xmax = self.x_scale() 53 54 if x >= xmin  0.1 and x <= xmax + 0.1: … … 90 91 self.map_transform = self.transform_for_axes() 91 92 93 92 94 class CutoffCurve(OWCurve): 93 95 def __init__(self, *args, **kwargs): … … 96 98 self.setCursor(Qt.SizeHorCursor) 97 99 100 98 101 class OWPCA(OWWidget): 99 102 settingsList = ["standardize", "max_components", "variance_covered", 100 103 "use_generalized_eigenvectors", "auto_commit"] 104 101 105 def __init__(self, parent=None, signalManager=None, title="PCA"): 102 106 OWWidget.__init__(self, parent, signalManager, title, wantGraph=True) … … 127 131 grid.addWidget(label1, 1, 0) 128 132 129 sb1 = OWGUI.spin(box, self, "max_components", 1, 1000,133 sb1 = OWGUI.spin(box, self, "max_components", 0, 1000, 130 134 tooltip="Maximum number of components", 131 135 callback=self.on_update, … … 134 138 ) 135 139 self.max_components_spin = sb1.control 140 self.max_components_spin.setSpecialValueText("All") 136 141 grid.addWidget(sb1.control, 1, 1) 137 142 … … 167 172 self.variance_curve = self.scree_plot.add_curve( 168 173 "Variance", 169 Qt.red, Qt.red, 2, 174 Qt.red, Qt.red, 2, 170 175 xData=[], 171 176 yData=[], … … 180 185 self.cumulative_variance_curve = self.scree_plot.add_curve( 181 186 "Cumulative Variance", 182 Qt.darkYellow, Qt.darkYellow, 2, 187 Qt.darkYellow, Qt.darkYellow, 2, 183 188 xData=[], 184 189 yData=[], … … 285 290 self.variances_cumsum = np.cumsum(self.variances) 286 291 287 self.max_components_spin.setRange( 1, len(self.variances))292 self.max_components_spin.setRange(0, len(self.variances)) 288 293 self.update_scree_plot() 289 294 self.update_cutoff_curve() … … 295 300 else: 296 301 self.changed_flag = True 297 302 298 303 def update_components(self): 299 304 """Update the output components. 300 305 """ 301 306 if self.data is None: 302 return 307 return 303 308 304 309 scale = self.projector_full.scale … … 309 314 variance_sum = self.projector_full.variance_sum 310 315 311 # Get selected components (based on max_components and 316 # Get selected components (based on max_components and 312 317 # variance_coverd) 313 318 pca = self.construct_pca() … … 341 346 self.scree_plot.set_axis_enabled(owaxis.xBottom, True) 342 347 self.scree_plot.set_axis_enabled(owaxis.yLeft, True) 343 self.scree_plot.set_axis_labels(owaxis.xBottom, 348 self.scree_plot.set_axis_labels(owaxis.xBottom, 344 349 ["PC" + str(i + 1) for i in x_space]) 345 350 … … 365 370 """Update cutoff curve from 'Components Selection' control box. 366 371 """ 367 variance = self.variances_cumsum[self.max_components  1] * 100.0 372 if self.max_components == 0: 373 # Special "All" value 374 max_components = len(self.variances_cumsum) 375 else: 376 max_components = self.max_components 377 378 variance = self.variances_cumsum[max_components  1] * 100.0 368 379 if variance < self.variance_covered: 369 cutoff = float( self.max_components  1)380 cutoff = float(max_components  1) 370 381 else: 371 382 cutoff = np.searchsorted(self.variances_cumsum, … … 381 392 variance_components = np.searchsorted(self.variances_cumsum, 382 393 self.variance_covered / 100.0) 383 return min(variance_components + 1, self.max_components) 394 if self.max_components == 0: 395 # Special "All" value 396 max_components = len(self.variances_cumsum) 397 else: 398 max_components = self.max_components 399 return min(variance_components + 1, max_components) 384 400 385 401 def sendReport(self): … … 411 427 self.reportImage(self.scree_plot.save_to_file_direct) 412 428 429 413 430 if __name__ == "__main__": 414 431 app = QApplication(sys.argv)
Note: See TracChangeset
for help on using the changeset viewer.