Changeset 7805:8bf0810e1663 in orange


Ignore:
Timestamp:
04/02/11 23:51:17 (3 years ago)
Author:
matija <matija.polajnar@…>
Branch:
default
Convert:
b405e044a68e40db790527bf2b80460680f7454b
Message:

Orange.projection.mds: Completion (maybe?) of transition to Orange 2.5.

Location:
orange
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • orange/Orange/projection/mds.py

    r7598 r7805  
    1717.. autoclass:: Orange.projection.mds.MDS 
    1818   :members: 
    19    :exclude-members: Torgerson, getDistance, getStress 
     19   :exclude-members: Torgerson, get_distance, get_stress 
    2020 
    2121Stress functions 
     
    2929       Compute the stress using the correct and the current distance value (the 
    3030       :obj:`Orange.projection.mds.MDS.distances` and 
    31        :obj:`Orange.projection.mds.MDS.projectedDistances` elements). 
     31       :obj:`Orange.projection.mds.MDS.projected_distances` elements). 
    3232        
    3333       :param correct: correct (actual) distance between elements, represented by 
     
    104104 
    105105 
    106 import Orange.core 
    107 import orangeom as orangemds 
    108106from math import * 
    109107from numpy import * 
    110108from numpy.linalg import svd 
     109 
     110import Orange.core 
     111import orangeom as orangemds 
     112from Orange.misc import deprecated_keywords 
     113from Orange.misc import deprecated_members 
    111114 
    112115KruskalStress = orangemds.KruskalStress() 
     
    176179         
    177180         
     181@deprecated_members({"projectedDistances": "projected_distances", 
     182                     "originalDistances": "original_distances", 
     183                     "avgStress": "avg_stress", 
     184                     "progressCallback": "progress_callback", 
     185                     "getStress": "calc_stress", 
     186                     "get_stress": "calc_stress", 
     187                     "calcStress": "calc_stress", 
     188                     "getDistance": "calc_distance", 
     189                     "get_distance": "calc_distance", 
     190                     "calcDistance": "calc_distance", 
     191                     "Torgerson": "torgerson", 
     192                     "SMACOFstep": "smacof_step", 
     193                     "LSMT": "lsmt"}) 
    178194class MDS(object): 
    179195    """ 
     
    199215     
    200216       An :class:`Orange.core.SymMatrix` containing the distances that we 
    201        want to achieve (LSMT changes these). 
    202         
    203     .. attribute:: projectedDistances 
     217       want to achieve (lsmt changes these). 
     218        
     219    .. attribute:: projected_distances 
    204220 
    205221       An :class:`Orange.core.SymMatrix` containing the distances between 
    206222       projected points. 
    207223        
    208     .. attribute:: originalDistances 
     224    .. attribute:: original_distances 
    209225 
    210226       An :class:`Orange.core.SymMatrix` containing the original distances 
     
    223239       An integer holding the number of elements (points). 
    224240        
    225     .. attribute:: avgStress 
     241    .. attribute:: avg_stress 
    226242 
    227243       A float holding the average stress in the :obj:`stress` matrix. 
    228244        
    229     .. attribute:: progressCallback 
     245    .. attribute:: progress_callback 
    230246 
    231247       A function that gets called after each optimization step in the 
     
    236252    def __init__(self, distances=None, dim=2, **kwargs): 
    237253        self.mds=orangemds.MDS(distances, dim, **kwargs) 
    238         self.originalDistances=Orange.core.SymMatrix([m for m in self.distances]) 
     254        self.original_distances=Orange.core.SymMatrix([m for m in self.distances]) 
    239255 
    240256    def __getattr__(self, name): 
    241         if name in ["points", "projectedDistances", "distances" ,"stress", 
    242                     "progressCallback", "n", "dim", "avgStress"]: 
     257        if name in ["points", "projected_distances", "distances" ,"stress", 
     258                    "progress_callback", "n", "dim", "avg_stress"]: 
    243259            #print "rec:",name             
    244260            return self.__dict__["mds"].__dict__[name] 
     
    254270            return 
    255271             
    256         if name in ["projectedDistances", "distances" ,"stress", 
    257                     "progressCallback"]: 
     272        if name in ["projected_distances", "distances" ,"stress", 
     273                    "progress_callback"]: 
    258274            self.mds.__setattr__(name, value) 
    259275        else: 
     
    263279        return True 
    264280             
    265     def SMACOFstep(self): 
     281    def smacof_step(self): 
    266282        """ 
    267283        Perform a single iteration of a Smacof algorithm that optimizes 
     
    270286        self.mds.SMACOFstep() 
    271287 
    272     def calcDistance(self): 
     288    def calc_distance(self): 
    273289        """ 
    274290        Compute the distances between points and update the 
    275         :obj:`projectedDistances` matrix. 
    276          
    277         """ 
    278         self.mds.getDistance() 
    279          
    280     getDistance = calcDistance 
    281  
    282     def calcStress(self, stressFunc=SgnRelStress): 
    283         """ 
    284         Compute the stress between the current :obj:`projectedDistances` and 
    285         :obj:`distances` matrix using *stressFunc* and update the 
     291        :obj:`projected_distances` matrix. 
     292         
     293        """ 
     294        self.mds.get_distance() 
     295         
     296 
     297    @deprecated_keywords({"stressFunc": "stress_func"}) 
     298    def calc_stress(self, stress_func=SgnRelStress): 
     299        """ 
     300        Compute the stress between the current :obj:`projected_distances` and 
     301        :obj:`distances` matrix using *stress_func* and update the 
    286302        :obj:`stress` matrix and :obj:`avgStress` accordingly. 
    287303         
    288304        """ 
    289         self.mds.getStress(stressFunc) 
    290          
    291     getStress = calcStress 
    292  
    293     def optimize(self, iter, stressFunc=SgnRelStress, eps=1e-3, 
    294                  progressCallback=None): 
    295         self.mds.progressCallback=progressCallback 
    296         self.mds.optimize(iter, stressFunc, eps) 
    297  
    298     def run(self, iter, stressFunc=SgnRelStress, eps=1e-3, 
    299             progressCallback=None): 
     305        self.mds.getStress(stress_func) 
     306 
     307    @deprecated_keywords({"stressFunc": "stress_func"}) 
     308    def optimize(self, iter, stress_func=SgnRelStress, eps=1e-3, 
     309                 progress_callback=None): 
     310        self.mds.progress_callback=progress_callback 
     311        self.mds.optimize(iter, stress_func, eps) 
     312 
     313    @deprecated_keywords({"stressFunc": "stress_func"}) 
     314    def run(self, iter, stress_func=SgnRelStress, eps=1e-3, 
     315            progress_callback=None): 
    300316        """ 
    301317        Perform optimization until stopping conditions are met. 
    302318        Stopping conditions are: 
    303319            
    304            * optimization runs for *iter* iterations of SMACOFstep function, or 
     320           * optimization runs for *iter* iterations of smacof_step function, or 
    305321           * stress improvement (old stress minus new stress) is smaller than 
    306322             eps * old stress. 
     
    309325        :type iter: int 
    310326         
    311         :param stressFunc: stress function. 
    312         """ 
    313         self.optimize(iter, stressFunc, eps, progressCallback) 
     327        :param stress_func: stress function. 
     328        """ 
     329        self.optimize(iter, stress_func, eps, progress_callback) 
    314330 
    315331    def torgerson(self): 
     
    357373#        X = matrixmultiply(U,D) 
    358374#        self.X = take(X,idx,1) 
    359     Torgerson = torgerson 
     375     
    360376    # Kruskal's monotone transformation 
    361     def LSMT(self): 
     377    def lsmt(self): 
    362378        """ 
    363379        Execute Kruskal monotone transformation. 
     
    371387        for i in xrange(1,self.n): 
    372388            for j in xrange(i): 
    373                 o.append((self.originalDistances[i,j],(i,j))) 
     389                o.append((self.original_distances[i,j],(i,j))) 
    374390        o.sort(_mycompare) 
    375391        # find the ties in o, and construct the d vector sorting in order within ties 
     
    378394        uv = [] # numbers of consecutively tied o values 
    379395        (i,j) = o[0][1] 
    380         distnorm = self.projectedDistances[i,j]*self.projectedDistances[i,j] 
    381         td = [self.projectedDistances[i,j]] # fetch distance 
     396        distnorm = self.projected_distances[i,j]*self.projected_distances[i,j] 
     397        td = [self.projected_distances[i,j]] # fetch distance 
    382398        for l in xrange(1,len(o)): 
    383399            # copy now sorted distances in an array 
    384400            # but sort distances within a tied o 
    385401            (i,j) = o[l][1] 
    386             cd = self.projectedDistances[i,j] 
    387             distnorm += self.projectedDistances[i,j]*self.projectedDistances[i,j] 
     402            cd = self.projected_distances[i,j] 
     403            distnorm += self.projected_distances[i,j]*self.projected_distances[i,j] 
    388404            if o[l][0] != o[l-1][0]: 
    389405                # differing value, flush 
  • orange/doc/Orange/rst/code/mds-advanced.py

    r7493 r7805  
    2121mds = Orange.projection.mds.MDS(matrix) 
    2222mds.Torgerson() 
    23 mds.calcStress(Orange.projection.mds.KruskalStress) 
     23mds.calc_stress(Orange.projection.mds.KruskalStress) 
    2424 
    2525# Optimization loop; calculate the stress only after each 10 optimization steps: 
    2626for i in range(100): 
    27     oldStress = mds.avgStress 
     27    old_stress = mds.avg_stress 
    2828    for j in range(10): 
    2929        mds.SMACOFstep() 
    3030 
    31     mds.calcStress(Orange.projection.mds.KruskalStress) 
    32     if oldStress * 1e-3 > math.fabs(oldStress - mds.avgStress): 
     31    mds.calc_stress(Orange.projection.mds.KruskalStress) 
     32    if old_stress * 1e-3 > math.fabs(old_stress - mds.avg_stress): 
    3333        break 
    3434 
  • orange/doc/Orange/rst/code/mds-scatterplot.py

    r7602 r7805  
    3131 
    3232# Paint each class separately 
    33 for c in range(len(table.domain.classVar.values)): 
     33for c in range(len(table.domain.class_var.values)): 
    3434    sel = filter(lambda x: x[-1] == c, points) 
    3535    x = [s[0] for s in sel] 
Note: See TracChangeset for help on using the changeset viewer.