Changeset 3536:2f19c1099e2e in orange
 Timestamp:
 04/16/07 10:19:15 (7 years ago)
 Branch:
 default
 Convert:
 378fa37d2fe302281b15e4586e8705af3c389279
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

orange/orngLinProj.py
r3494 r3536 52 52 self.subsetdata = subsetdata 53 53 54 55 54 def showAllAttributes(self): 56 55 self.graph.anchorData = [(0,0, a.name) for a in self.graph.rawdata.domain.attributes] … … 62 61 def radialAnchors(self): 63 62 attrList = self.getShownAttributeList() 63 if not attrList: 64 return 64 65 phi = 2*math.pi/len(attrList) 65 66 self.graph.anchorData = [(math.cos(i*phi), math.sin(i*phi), a) for i, a in enumerate(attrList)] … … 99 100 100 101 def optimizeSeparation(self, steps = 10, singleStep = False): 102 # check if we have data and a discrete class 103 if not self.rawdata or len(self.rawdata) == 0 or not self.rawdata.domain.classVar or self.rawdata.domain.classVar.varType != orange.VarTypes.Discrete: 104 return 101 105 if self.implementation == FAST_IMPLEMENTATION: 102 106 return self.optimize_FAST_Separation(steps, singleStep) … … 153 157 def optimize_LDA_Separation(self, attrIndices, anchorData, XAnchors = None, YAnchors = None): 154 158 dataSize = len(self.graph.rawdata) 159 if dataSize == 0: 160 return anchorData, (XAnchors, YAnchors) 155 161 classCount = len(self.graph.rawdata.domain.classVar.values) 156 162 validData = self.graph.getValidList(attrIndices) 157 163 selectedData = numpy.compress(validData, numpy.take(self.graph.noJitteringScaledData, attrIndices, axis = 0), axis = 1) 158 164 159 if not XAnchors: XAnchors = numpy.array([a[0] for a in anchorData], numpy.Float) 160 if not YAnchors: YAnchors = numpy.array([a[1] for a in anchorData], numpy.Float) 165 if XAnchors == None: 166 XAnchors = numpy.array([a[0] for a in anchorData], numpy.float) 167 if YAnchors == None: 168 YAnchors = numpy.array([a[1] for a in anchorData], numpy.float) 161 169 162 170 transProjData = self.graph.createProjectionAsNumericArray(attrIndices, validData = validData, XAnchors = XAnchors, YAnchors = YAnchors, scaleFactor = self.graph.scaleFactor, normalize = self.graph.normalizeExamples, useAnchorData = 1) 163 if not transProjData:164 return anchorData 171 if transProjData == None: 172 return anchorData, (XAnchors, YAnchors) 165 173 166 174 projData = numpy.transpose(transProjData) … … 207 215 meanDestinationVectors = [(x + xCenterVector, y + yCenterVector) for (x,y) in meanDestinationVectors] # center mean values 208 216 209 FXs = numpy.zeros(len(x_positions), numpy. Float) # forces210 FYs = numpy.zeros(len(x_positions), numpy. Float)217 FXs = numpy.zeros(len(x_positions), numpy.float) # forces 218 FYs = numpy.zeros(len(x_positions), numpy.float) 211 219 212 220 for c in range(classCount): … … 216 224 217 225 # compute gradient for all anchors 218 GXs = numpy.array([sum(FXs * selectedData[i]) for i in range(len(anchorData))], numpy. Float)219 GYs = numpy.array([sum(FYs * selectedData[i]) for i in range(len(anchorData))], numpy. Float)226 GXs = numpy.array([sum(FXs * selectedData[i]) for i in range(len(anchorData))], numpy.float) 227 GYs = numpy.array([sum(FYs * selectedData[i]) for i in range(len(anchorData))], numpy.float) 220 228 221 229 m = max(max(abs(GXs)), max(abs(GYs))) … … 249 257 def optimize_SLOW_Separation(self, attrIndices, anchorData, XAnchors = None, YAnchors = None): 250 258 dataSize = len(self.graph.rawdata) 259 if dataSize == 0: 260 return anchorData, (XAnchors, YAnchors) 251 261 validData = self.graph.getValidList(attrIndices) 252 262 selectedData = numpy.compress(validData, numpy.take(self.graph.noJitteringScaledData, attrIndices, axis = 0), axis = 1) 253 263 254 if not XAnchors: XAnchors = numpy.array([a[0] for a in anchorData], numpy.Float) 255 if not YAnchors: YAnchors = numpy.array([a[1] for a in anchorData], numpy.Float) 264 if XAnchors == None: 265 XAnchors = numpy.array([a[0] for a in anchorData], numpy.float) 266 if YAnchors == None: 267 YAnchors = numpy.array([a[1] for a in anchorData], numpy.float) 256 268 257 269 transProjData = self.graph.createProjectionAsNumericArray(attrIndices, validData = validData, XAnchors = XAnchors, YAnchors = YAnchors, scaleFactor = self.graph.scaleFactor, normalize = self.graph.normalizeExamples, useAnchorData = 1) 258 if not transProjData:259 return anchorData 270 if transProjData == None: 271 return anchorData, (XAnchors, YAnchors) 260 272 261 273 projData = numpy.transpose(transProjData) … … 264 276 classData = projData[2] ; classData2 = numpy.array(classData) 265 277 266 FXs = numpy.zeros(len(x_positions), numpy. Float) # forces267 FYs = numpy.zeros(len(x_positions), numpy. Float)268 GXs = numpy.zeros(len(anchorData), numpy. Float) # gradients269 GYs = numpy.zeros(len(anchorData), numpy. Float)278 FXs = numpy.zeros(len(x_positions), numpy.float) # forces 279 FYs = numpy.zeros(len(x_positions), numpy.float) 280 GXs = numpy.zeros(len(anchorData), numpy.float) # gradients 281 GYs = numpy.zeros(len(anchorData), numpy.float) 270 282 271 283 rotateArray = range(len(x_positions)); rotateArray = rotateArray[1:] + [0] … … 280 292 rs = numpy.sqrt(rs2) 281 293 282 F = numpy.zeros(len(x_positions), numpy. Float)294 F = numpy.zeros(len(x_positions), numpy.float) 283 295 classDiff = numpy.where(classData == classData2, 1, 0) 284 296 numpy.putmask(F, classDiff, 150*self.attractG*rs2) … … 288 300 289 301 # compute gradient for all anchors 290 GXs = numpy.array([sum(FXs * selectedData[i]) for i in range(len(anchorData))], numpy. Float)291 GYs = numpy.array([sum(FYs * selectedData[i]) for i in range(len(anchorData))], numpy. Float)302 GXs = numpy.array([sum(FXs * selectedData[i]) for i in range(len(anchorData))], numpy.float) 303 GYs = numpy.array([sum(FYs * selectedData[i]) for i in range(len(anchorData))], numpy.float) 292 304 293 305 m = max(max(abs(GXs)), max(abs(GYs))) … … 398 410 # if not then just use current parameters to place anchors 399 411 def s2nMixAnchorsAutoSet(self): 412 # check if we have data and a discrete class 413 if not self.rawdata or len(self.rawdata) == 0 or not self.rawdata.domain.classVar or self.rawdata.domain.classVar.varType != orange.VarTypes.Discrete: 414 return 415 400 416 if self.__class__ != FreeViz: 401 417 import qt … … 403 419 if not self.rawdata.domain.classVar or not self.rawdata.domain.classVar.varType == orange.VarTypes.Discrete: 404 420 if self.__class__ != FreeViz: 405 qt.QMessageBox.critical( None, "Error", 'This heuristic works only in data sets with a discrete class value.', QMessageBox.Ok)421 qt.QMessageBox.critical( None, "Error", 'This heuristic works only in data sets with a discrete class value.', qt.QMessageBox.Ok) 406 422 else: 407 423 print "S2N heuristic works only in data sets with a discrete class value" … … 467 483 # place a subset of attributes around the circle. this subset must contain "good" attributes for each of the class values 468 484 def s2nMixAnchors(self, setAttributeListInRadviz = 1): 485 # check if we have data and a discrete class 486 if not self.rawdata or len(self.rawdata) == 0 or not self.rawdata.domain.classVar or self.rawdata.domain.classVar.varType != orange.VarTypes.Discrete: 487 return 488 469 489 if self.__class__ != FreeViz: 470 490 import qt 471 491 if not self.rawdata.domain.classVar or not self.rawdata.domain.classVar.varType == orange.VarTypes.Discrete: 472 qt.QMessageBox.critical( None, "Error", 'This heuristic works only in data sets with a discrete class value.', QMessageBox.Ok)492 qt.QMessageBox.critical( None, "Error", 'This heuristic works only in data sets with a discrete class value.', qt.QMessageBox.Ok) 473 493 return 0 474 494
Note: See TracChangeset
for help on using the changeset viewer.