Changeset 3536:2f19c1099e2e in orange


Ignore:
Timestamp:
04/16/07 10:19:15 (7 years ago)
Author:
Gregor <Gregor@…>
Branch:
default
Convert:
378fa37d2fe302281b15e4586e8705af3c389279
Message:
  • several bug fixes
File:
1 edited

Legend:

Unmodified
Added
Removed
  • orange/orngLinProj.py

    r3494 r3536  
    5252        self.subsetdata = subsetdata 
    5353 
    54  
    5554    def showAllAttributes(self): 
    5655        self.graph.anchorData = [(0,0, a.name) for a in self.graph.rawdata.domain.attributes] 
     
    6261    def radialAnchors(self): 
    6362        attrList = self.getShownAttributeList() 
     63        if not attrList: 
     64            return 
    6465        phi = 2*math.pi/len(attrList) 
    6566        self.graph.anchorData = [(math.cos(i*phi), math.sin(i*phi), a) for i, a in enumerate(attrList)] 
     
    99100 
    100101    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 
    101105        if self.implementation == FAST_IMPLEMENTATION: 
    102106            return self.optimize_FAST_Separation(steps, singleStep) 
     
    153157    def optimize_LDA_Separation(self, attrIndices, anchorData, XAnchors = None, YAnchors = None): 
    154158        dataSize = len(self.graph.rawdata) 
     159        if dataSize == 0: 
     160            return anchorData, (XAnchors, YAnchors) 
    155161        classCount = len(self.graph.rawdata.domain.classVar.values) 
    156162        validData = self.graph.getValidList(attrIndices) 
    157163        selectedData = numpy.compress(validData, numpy.take(self.graph.noJitteringScaledData, attrIndices, axis = 0), axis = 1) 
    158164 
    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) 
    161169 
    162170        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) 
    165173 
    166174        projData = numpy.transpose(transProjData) 
     
    207215        meanDestinationVectors = [(x + xCenterVector, y + yCenterVector) for (x,y) in meanDestinationVectors]   # center mean values 
    208216 
    209         FXs = numpy.zeros(len(x_positions), numpy.Float)        # forces 
    210         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) 
    211219 
    212220        for c in range(classCount): 
     
    216224 
    217225        # 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) 
    220228 
    221229        m = max(max(abs(GXs)), max(abs(GYs))) 
     
    249257    def optimize_SLOW_Separation(self, attrIndices, anchorData, XAnchors = None, YAnchors = None): 
    250258        dataSize = len(self.graph.rawdata) 
     259        if dataSize == 0: 
     260            return anchorData, (XAnchors, YAnchors) 
    251261        validData = self.graph.getValidList(attrIndices) 
    252262        selectedData = numpy.compress(validData, numpy.take(self.graph.noJitteringScaledData, attrIndices, axis = 0), axis = 1) 
    253263 
    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) 
    256268 
    257269        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) 
    260272 
    261273        projData = numpy.transpose(transProjData) 
     
    264276        classData = projData[2]  ; classData2 = numpy.array(classData) 
    265277 
    266         FXs = numpy.zeros(len(x_positions), numpy.Float)        # forces 
    267         FYs = numpy.zeros(len(x_positions), numpy.Float) 
    268         GXs = numpy.zeros(len(anchorData), numpy.Float)        # gradients 
    269         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) 
    270282 
    271283        rotateArray = range(len(x_positions)); rotateArray = rotateArray[1:] + [0] 
     
    280292            rs = numpy.sqrt(rs2) 
    281293 
    282             F = numpy.zeros(len(x_positions), numpy.Float) 
     294            F = numpy.zeros(len(x_positions), numpy.float) 
    283295            classDiff = numpy.where(classData == classData2, 1, 0) 
    284296            numpy.putmask(F, classDiff, 150*self.attractG*rs2) 
     
    288300 
    289301        # 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) 
    292304 
    293305        m = max(max(abs(GXs)), max(abs(GYs))) 
     
    398410    # if not then just use current parameters to place anchors 
    399411    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 
    400416        if self.__class__ != FreeViz: 
    401417            import qt 
     
    403419        if not self.rawdata.domain.classVar or not self.rawdata.domain.classVar.varType == orange.VarTypes.Discrete: 
    404420            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) 
    406422            else: 
    407423                print "S2N heuristic works only in data sets with a discrete class value" 
     
    467483    # place a subset of attributes around the circle. this subset must contain "good" attributes for each of the class values 
    468484    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 
    469489        if self.__class__ != FreeViz: 
    470490            import qt 
    471491            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) 
    473493                return 0 
    474494 
Note: See TracChangeset for help on using the changeset viewer.