Ignore:
Files:
406 added
405 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • Orange/doc/modules/exclude-from-regression.txt

    r9671 r9676  
    1515network_read.py 
    1616network_widget.py 
     17PCA4.py 
    1718PCA5.py 
  • Orange/feature/selection.py

    r9671 r9676  
    6868set of features. 
    6969 
    70 :download:`selection-bayes.py <code/selection-bayes.py>` (uses :download:`voting.tab <code/voting.tab>`): 
     70:download:`selection-bayes.py<code/selection-bayes.py>` 
    7171 
    7272.. literalinclude:: code/selection-bayes.py 
     
    9696used. 
    9797 
    98 :download:`selection-filtered-learner.py <code/selection-filtered-learner.py>` (uses :download:`voting.tab <code/voting.tab>`): 
     98:download:`selection-filtered-learner.py<code/selection-filtered-learner.py>` 
    9999 
    100100.. literalinclude:: code/selection-filtered-learner.py 
  • Orange/orng/orngPCA.py

    r9671 r9676  
    1717    warnings.warn("Importing of matplotlib has failed.\nPlotting functions will be unavailable.") 
    1818    mathlib_import = False 
    19      
     19 
    2020#color table for biplot 
    21 Colors = ['bo','go','yo','co','mo'] 
     21Colors = ['bo', 'go', 'yo', 'co', 'mo'] 
    2222 
    2323def defaultImputer(dataset): 
     
    4141def centerData(dataMatrix): 
    4242    """Perfomrs centering od data along rows, returns center and centered data.""" 
    43     center = numpy.sum(dataMatrix, axis = 0)/float(len(dataMatrix)) 
     43    center = numpy.sum(dataMatrix, axis=0) / float(len(dataMatrix)) 
    4444    return center, (dataMatrix - center) 
    4545 
     
    4747    """Performs standardization of data along rows. Throws error if constant 
    4848    variable is present.""" 
    49     scale = numpy.std(dataMatrix, axis = 0) 
     49    scale = numpy.std(dataMatrix, axis=0) 
    5050    if 0. in scale: 
    5151        raise orange.KernelException, "Constant variable, cannot standardize!" 
    52     return scale, dataMatrix * 1./scale 
     52    return scale, dataMatrix * 1. / scale 
    5353 
    5454class PCA(object): 
     
    8888    PCAClassifier object if projection was successful or None if projection has failed 
    8989    """ 
    90      
    91     def __new__(cls, dataset = None, attributes = None, rows = None, standardize = 0, 
    92                  imputer = defaultImputer, continuizer = defaultContinuizer, 
    93                  maxNumberOfComponents = 10, varianceCovered = 0.95, 
    94                  useGeneralizedVectors = 0): 
    95          
     90 
     91    def __new__(cls, dataset=None, attributes=None, rows=None, standardize=0, 
     92                 imputer=defaultImputer, continuizer=defaultContinuizer, 
     93                 maxNumberOfComponents=10, varianceCovered=0.95, 
     94                 useGeneralizedVectors=0): 
     95 
    9696        learner = object.__new__(cls) 
    97          
     97 
    9898        if dataset: 
    9999            learner.__init__(attributes, rows, standardize, imputer, continuizer, 
     
    102102        else: 
    103103            return learner 
    104      
     104 
    105105    #decide what should be inmutable and what not 
    106106    #imutable for sure: imputer and continuizer 
    107     def __init__(self, attributes = None, rows = None, standardize = 0, 
    108                  imputer = defaultImputer, continuizer = defaultContinuizer, 
    109                  maxNumberOfComponents = 10, varianceCovered = 0.95, 
    110                  useGeneralizedVectors = 0): 
    111          
     107    def __init__(self, attributes=None, rows=None, standardize=0, 
     108                 imputer=defaultImputer, continuizer=defaultContinuizer, 
     109                 maxNumberOfComponents=10, varianceCovered=0.95, 
     110                 useGeneralizedVectors=0): 
     111 
    112112        self.attributes = attributes 
    113113        self.rows = rows 
     
    118118        self.varianceCovered = varianceCovered 
    119119        self.useGeneralizedVectors = useGeneralizedVectors 
    120      
     120 
    121121    def __call__(self, dataset): 
    122          
     122 
    123123        #Modify dataset 
    124124        dataset = self._datasetPreprocessing(dataset) 
    125125        dataMatrix, classArray, center, deviation = self._dataMatrixPreprocessing(dataset) 
    126          
     126 
    127127        #Perform projection 
    128128        evalues, evectors = self._createPCAProjection(dataMatrix, classArray) 
    129          
     129 
    130130        #check if return status is None, None 
    131131        if (evalues, evectors) == (None, None): 
    132132            print "Principal component could not be performed (complex eigenvalues or singular matrix if generalized eigenvectors were used)" 
    133133            return None 
    134          
     134 
    135135        #return PCAClassifier 
    136         return PCAClassifier(domain = self.attributes, 
    137                              imputer = self.imputer, 
    138                              continuizer = self.continuizer, 
    139                              center = center, 
    140                              deviation = deviation, 
    141                              evalues = evalues, 
    142                              loadings = evectors) 
     136        return PCAClassifier(domain=self.attributes, 
     137                             imputer=self.imputer, 
     138                             continuizer=self.continuizer, 
     139                             center=center, 
     140                             deviation=deviation, 
     141                             evalues=evalues, 
     142                             loadings=evectors) 
    143143 
    144144    def _datasetPreprocessing(self, dataset): 
     
    151151        if self.attributes: 
    152152            dataset = dataset.select(self.attributes) 
    153          
     153 
    154154        #we need to retain only selected attributes without class attribute     
    155155        self.attributes = [att.name for att in dataset.domain.attributes] 
    156156 
    157157        imputer = self.imputer(dataset) 
    158              
     158 
    159159        if self.rows: 
    160160            dataset = dataset.select(self.rows) 
     
    165165        dataset = dataset.translate(domain) 
    166166 
    167         return dataset         
     167        return dataset 
    168168 
    169169    def _dataMatrixPreprocessing(self, dataset): 
     
    175175 
    176176        dataMatrix, classArray, x = dataset.toNumpy() 
    177          
     177 
    178178        center, dataMatrix = centerData(dataMatrix) 
    179          
     179 
    180180        deviation = None 
    181181        if self.standardize: 
     
    183183 
    184184        return dataMatrix, classArray, center, deviation 
    185      
     185 
    186186    def _createPCAProjection(self, dataMatrix, classArray): 
    187187        """ 
     
    195195        Snapshot with generalized vectors: M * (t(M) * M)^(-1) * t(M) * L * M * x = lambda * M * x 
    196196        """ 
    197          
     197 
    198198        n, d = numpy.shape(dataMatrix) 
    199          
     199 
    200200        if classArray != None: 
    201201            L = numpy.zeros((len(dataMatrix), len(dataMatrix))) 
    202202            for i in range(len(dataMatrix)): 
    203                 for j in range(i+1, len(dataMatrix)): 
    204                     L[i,j] = -int(classArray[i] != classArray[j]) 
    205                     L[j,i] = -int(classArray[i] != classArray[j]) 
     203                for j in range(i + 1, len(dataMatrix)): 
     204                    L[i, j] = -int(classArray[i] != classArray[j]) 
     205                    L[j, i] = -int(classArray[i] != classArray[j]) 
    206206 
    207207            s = numpy.sum(L, axis=0)      # doesn't matter which axis since the matrix L is symmetrical 
    208208            for i in range(len(dataMatrix)): 
    209                 L[i,i] = -s[i] 
    210                  
     209                L[i, i] = -s[i] 
     210 
    211211            matrix = dot(transpose(dataMatrix), L) 
    212212        else: 
    213213            matrix = transpose(dataMatrix) 
    214          
     214 
    215215        if self.useGeneralizedVectors: 
    216216            temp_matrix = dot(transpose(dataMatrix), dataMatrix) 
     
    220220                return None, None 
    221221            matrix = dot(temp_matrix, matrix) 
    222          
     222 
    223223        if n < d: 
    224224            #snapshot method 
     
    232232            evalues = evalues[positiveArray] 
    233233            evectors = evectors[positiveArray] 
    234             evectors = transpose(1./sqrt(evalues)) * transpose(dot(evectors, dataMatrix)) 
     234            evectors = transpose(1. / sqrt(evalues)) * transpose(dot(evectors, dataMatrix)) 
    235235        else: 
    236236            covMatrix = dot(matrix, dataMatrix) 
     
    243243            evalues = evalues[positiveArray] 
    244244            evectors = evectors[positiveArray] 
    245                          
     245 
    246246        order = (numpy.argsort(evalues)[::-1]) 
    247247        N = len(evalues) 
    248248        maxComp = self.maxNumberOfComponents 
    249249        variance = self.varianceCovered 
    250          
     250 
    251251        if maxComp == -1: 
    252252            maxComp = N 
     
    259259        #                   -> value < 1 : explains less than previous attribute 
    260260        for i in range(len(order)): 
    261             variance -= evalues[i] / trace  
     261            variance -= evalues[i] / trace 
    262262            if variance < 0: 
    263263                return evalues[: i + 1] * scale, numpy.take(evectors, order[: i + 1], 1) 
    264          
    265         return evalues * scale, numpy.take(evectors, order, 1)  
     264 
     265        return evalues * scale, numpy.take(evectors, order, 1) 
    266266 
    267267class PCAClassifier(object): 
    268      
     268 
    269269    def __init__(self, domain, imputer, continuizer, center, deviation, evalues, loadings): 
    270270        #data checking and modifying 
     
    277277        self.evalues = evalues 
    278278        self.loadings = loadings 
    279          
     279 
    280280        #last predicition performed -> used for biplot 
    281281        self._dataMatrix = None 
    282282        self._classArray = None 
    283      
     283 
    284284    def __call__(self, dataset): 
    285                  
     285 
    286286        try: 
    287287            #retain class attribute 
     
    298298        dataMatrix -= self.center 
    299299        if self.deviation != None: 
    300             dataMatrix *= 1./self.deviation 
    301              
     300            dataMatrix *= 1. / self.deviation 
     301 
    302302        #save transformed data 
    303303        self._dataMatrix = numpy.dot(dataMatrix, self.loadings) 
    304304 
    305         attributes = [orange.FloatVariable("PC%d" % (i + 1, )) for i in range(len(self.evalues))] 
     305        attributes = [orange.FloatVariable("PC%d" % (i + 1,)) for i in range(len(self.evalues))] 
    306306        new_domain = orange.Domain(attributes) 
    307307        new_table = orange.ExampleTable(new_domain, self._dataMatrix) 
     
    312312            self._classArray = numpy.array([row.getclass() for row in classTable]) 
    313313            new_table = orange.ExampleTable([new_table, classTable]) 
    314          
     314 
    315315        return new_table 
    316      
     316 
    317317    def __str__(self): 
    318          
     318 
    319319        n, d = numpy.shape(self.loadings) 
    320320        comulative = 0.0 
    321          
     321 
    322322        summary = "PCA SUMMARY\n\nCenter:\n\n" 
    323323        summary += " %15s  " * len(self.domain) % tuple(self.domain) + "\n" 
    324324        summary += " %15.4f  " * len(self.center) % tuple(self.center) + "\n\n" 
    325      
     325 
    326326        if self.deviation != None: 
    327327            summary += "Deviation:\n\n" 
    328328            summary += " %15s  " * len(self.domain) % tuple(self.domain) + "\n" 
    329329            summary += " %15.4f  " * len(self.deviation) % tuple(self.deviation) + "\n\n" 
    330     
     330 
    331331        summary += "Importance of components:\n\n %12s   %12s   %12s\n" % ("eigenvalues", "proportion", "cumulative") 
    332332        for evalue in self.evalues: 
    333             comulative += evalue/n 
    334             summary += " %12.4f   %12.4f   %12.4f\n" % (evalue, evalue/n, comulative) 
    335          
    336         summary += "\nLoadings:\n\n" 
    337         summary += "      PC%d" * d % tuple(range(1, d + 1)) + "\n" 
    338         for attr_num in range(len(self.domain)): 
    339             summary += " % 8.4f" * d % tuple(self.loadings[attr_num]) 
    340             summary += "   %-30s\n" % self.domain[attr_num] 
     333            comulative += evalue / n 
     334            summary += " %12.4f   %12.4f   %12.4f\n" % (evalue, evalue / n, comulative) 
     335 
     336        #summary += "\nLoadings:\n\n" 
     337        #summary += "      PC%d" * d % tuple(range(1, d + 1)) + "\n" 
     338        #for attr_num in range(len(self.domain)): 
     339        #    summary += " % 8.4f" * d % tuple(self.loadings[attr_num]) 
     340        #    summary += "   %-30s\n" % self.domain[attr_num] 
    341341 
    342342        return summary 
    343      
     343 
    344344    ################ Ploting functions ################### 
    345      
    346     def plot(self, title = 'Scree plot', filename = 'scree_plot.png'): 
     345 
     346    def plot(self, title='Scree plot', filename='scree_plot.png'): 
    347347        """ 
    348348        Draws a scree plot. Matplotlib is needed. 
     
    354354            If None, plot will be shown 
    355355        """ 
    356          
     356 
    357357        if not mathlib_import: 
    358358            raise orange.KernelException, "Matplotlib was not imported!" 
    359          
     359 
    360360        #plt.clf() -> opens two windows 
    361361        fig = plt.figure() 
    362362        ax = fig.add_subplot(111) 
    363          
     363 
    364364        x_axis = range(len(self.evalues)) 
    365         x_labels = ["PC%d" % (i + 1, ) for i in x_axis] 
    366          
     365        x_labels = ["PC%d" % (i + 1,) for i in x_axis] 
     366 
    367367        ax.set_xticks(x_axis) 
    368368        ax.set_xticklabels(x_labels) 
     
    370370        ax.set_ylabel('Variance') 
    371371        ax.set_title(title + "\n") 
    372         ax.bar(left = x_axis, height = self.evalues, align = 'center') 
    373         ax.axis([-0.5, len(self.evalues) - 0.5, 0, self.evalues[0]*1.05]) 
     372        ax.bar(left=x_axis, height=self.evalues, align='center') 
     373        ax.axis([-0.5, len(self.evalues) - 0.5, 0, self.evalues[0] * 1.05]) 
    374374        if filename: 
    375375            plt.savefig(filename) 
    376376        else: 
    377377            plt.show() 
    378              
    379     def biplot(self, choices = [1,2], scale = 1., title = 'Biplot', 
    380                filename = 'biplot.png'): 
     378 
     379    def biplot(self, choices=[1, 2], scale=1., title='Biplot', 
     380               filename='biplot.png'): 
    381381        """ 
    382382        Draws biplot for PCA. Matplotlib is needed. Actual projection must be 
     
    392392            If None, plot will be shown 
    393393        """ 
    394          
     394 
    395395        if not mathlib_import: 
    396396            raise orange.KernelException, "Matplotlib was not imported!" 
    397          
     397 
    398398        if self._dataMatrix == None: 
    399399            raise orange.KernelException, "No data available for biplot!" 
    400          
     400 
    401401        if len(choices) != 2: 
    402402            raise orange.KernelException, 'You have to choose exactly two components' 
    403          
     403 
    404404        if max(choices[0], choices[1]) > len(self.evalues) or min(choices[0], choices[1]) < 1: 
    405405            raise orange.KernelException, 'Invalid choices' 
    406          
     406 
    407407        choice = numpy.array([i == choices[0] - 1 or i == choices[1] - 1 for i in range(len(self.evalues))]) 
    408          
    409         dataMatrix = self._dataMatrix[:,choice] 
    410         loadings = self.loadings[:,choice] 
     408 
     409        dataMatrix = self._dataMatrix[:, choice] 
     410        loadings = self.loadings[:, choice] 
    411411        lam = (numpy.array(self.evalues)[choice]) 
    412412        lam *= sqrt(len(self._dataMatrix)) 
    413          
     413 
    414414        if scale < 0. or scale > 1.: 
    415415            print "Warning: 'scale' is outside [0, 1]" 
    416         lam = lam**scale 
    417          
     416        lam = lam ** scale 
     417 
    418418        #TO DO -> pc.biplot (maybe) 
    419419        trDataMatrix = dataMatrix / lam 
    420420        trLoadings = loadings * lam 
    421          
     421 
    422422        max_data_value = numpy.max(abs(trDataMatrix)) * 1.05 
    423423        max_load_value = numpy.max(abs(trLoadings)) * 1.5 
    424          
     424 
    425425        #plt.clf() 
    426426        fig = plt.figure() 
     
    432432        ax1.xaxis.set_ticks_position('bottom') 
    433433        ax1.yaxis.set_label_position('left') 
    434         ax1.yaxis.set_ticks_position('left')         
    435          
     434        ax1.yaxis.set_ticks_position('left') 
     435 
    436436        if self._classArray == None: 
    437437            trDataMatrix = transpose(trDataMatrix) 
     
    447447                partialDataMatrix = transpose(trDataMatrix[choice]) 
    448448                ax1.plot(partialDataMatrix[0], partialDataMatrix[1], 
    449                          Colors[i % len(Colors)], label = str(classValues[i])) 
     449                         Colors[i % len(Colors)], label=str(classValues[i])) 
    450450            ax1.legend() 
    451          
     451 
    452452        ax1.set_xlim(-max_data_value, max_data_value) 
    453453        ax1.set_ylim(-max_data_value, max_data_value) 
    454          
     454 
    455455        #eliminate double axis on right 
    456456        ax0 = ax1.twinx() 
    457457        ax0.yaxis.set_visible(False) 
    458                  
     458 
    459459        ax2 = ax0.twiny() 
    460460        ax2.xaxis.set_label_position('top') 
     
    466466        for tl in ax2.get_yticklabels(): 
    467467            tl.set_color('r') 
    468          
    469         arrowprops = dict(facecolor = 'red', edgecolor = 'red', width = 1, headwidth = 4) 
     468 
     469        arrowprops = dict(facecolor='red', edgecolor='red', width=1, headwidth=4) 
    470470        #using annotations instead of arrows because there is a strange implementation 
    471471        #of arrows in matplotlib version 0.99 
    472472        for i in range(len(trLoadings)): 
    473473            x, y = trLoadings[i] 
    474             ax2.annotate('', (x, y), (0, 0), arrowprops = arrowprops) 
    475             ax2.text(x * 1.1, y * 1.2, self.domain[i], color = 'red') 
    476              
     474            ax2.annotate('', (x, y), (0, 0), arrowprops=arrowprops) 
     475            ax2.text(x * 1.1, y * 1.2, self.domain[i], color='red') 
     476 
    477477        ax2.set_xlim(-max_load_value, max_load_value) 
    478478        ax2.set_ylim(-max_load_value, max_load_value) 
    479          
     479 
    480480        if filename: 
    481481            plt.savefig(filename) 
  • docs/reference/rst/Orange.data.domain.rst

    r9664 r9678  
    122122Meta attributes hold additional data attached to individual 
    123123instances. Different instances from the same domain or even the same 
    124 table may have different meta attributes. See documentation on 
    125 :obj:`Orange.data.Instance` for a more thorough description of meta 
    126 values. 
    127  
    128 Meta attributes that appear in instances can, but don't need to be 
     124table may have different meta attributes. (See documentation on 
     125:obj:`Orange.data.Instance` for details about meta values.) 
     126 
     127Meta attributes that appear in instances can - but don't need to - be 
    129128listed in the domain. Typically, the meta attribute will be included in 
    130129the domain for the following reasons. 
    131130 
    132      * If the domain knows about a meta attribute, their values can be 
     131     * If the domain knows about meta attributes, their values can be 
    133132       obtained with indexing by names and variable descriptors, 
    134133       e.g. ``inst["age"]``. Values of unknown meta attributes 
     
    136135       id needs to be an integer). 
    137136 
    138      * When printing out an instance, the symbolic values of discrete 
     137     * When printing out a data instance, the symbolic values of discrete 
    139138       meta attributes can only be printed if the attribute is 
    140139       registered. Also, if the attribute is registered, the printed 
     
    149148       unknown. 
    150149 
    151 For the latter two points - saving to a file and construction of new 
    152 instances - there is an additional flag: a meta attribute can be 
    153 marked as "optional". Such meta attributes are not saved and not added 
    154 to newly constructed data instances. 
    155  
    156 Another distinction between the optional and non-optional meta 
    157 attributes is that the latter are *expected to be* present in all 
    158 data instances from that domain. Saving to files expects will fail 
    159 if a non-optional meta value is missing; in most other places, 
    160 these rules are not strictly enforced, so adhering to them is rather up 
    161 to choice. 
    162  
    163 While the list of features and the class value are constant, 
    164 meta attributes can be added and removed at any time (a detailed 
    165 description of methods related to meta attributes is given below):: 
     150Meta attribute can be marked as "optional". Non-optional meta 
     151attributes are *expected to be* present in all data instances from that 
     152domain. This rule is not strictly enforced. As one of the few places 
     153where the difference matters, saving to files fails if a non-optional 
     154meta value is missing; optional attributes are not written to the file 
     155at all. Also, newly constructed data instances initially have all the 
     156non-optional meta attributes. 
     157 
     158While the list of features and the class value are immutable, 
     159meta attributes can be added and removed at any time:: 
    166160 
    167161     >>> misses = Orange.data.variable.Continuous("misses") 
     
    170164 
    171165This does not change the data: no attributes are added to data 
    172 instances. 
     166instances. Methods related to meta attributes are described in more 
     167details later. 
    173168 
    174169Registering meta attributes enables addressing by indexing, either by 
     
    232227     .. attribute:: features 
    233228 
    234     List of domain attributes 
    235     (:obj:`Orange.data.variable.Variables`) without the class 
    236     variable. Read only. 
     229        List of domain attributes 
     230        (:obj:`Orange.data.variable.Variables`) without the class 
     231        variable. Read only. 
    237232 
    238233     .. attribute:: variables 
    239234 
    240     List of domain attributes 
    241      (:obj:`Orange.data.variable.Variables`) including the class 
    242     variable. Read only. 
     235    List of domain attributes 
     236     (:obj:`~Orange.data.variable.Variables`) including the class 
     237    variable. Read only. 
    243238 
    244239     .. attribute:: class_var 
    245240 
    246      The class variable (:obj:`Orange.data.variable.Variable`), or 
    247     :obj:`None` if there is none. Read only. 
     241     The class variable (:obj:`~Orange.data.variable.Variable`), or 
     242    :obj:`None` if there is none. Read only. 
    248243 
    249244     .. attribute:: class_vars 
    250245 
    251     A list of additional class attributes. Read only. 
     246    A list of additional class attributes. Read only. 
    252247 
    253248     .. attribute:: version 
    254249 
    255     An integer value that is changed when the domain is 
    256     modified. The value can be also used as unique domain identifier; two 
    257     different domains have different value of ``version``. 
     250    An integer value that is changed when the domain is 
     251    modified. The value can be also used as unique domain identifier; two 
     252    different domains have different value of ``version``. 
    258253 
    259254     .. method:: __init__(variables[, class_vars=]) 
    260255 
    261     Construct a domain with the given variables; the 
    262     last one is used as the class variable. :: 
    263  
    264          >>> a, b, c = [Orange.data.variable.Discrete(x) for x in "abc"] 
    265          >>> domain = Orange.data.Domain([a, b, c]) 
    266          >>> domain.features 
    267          <EnumVariable 'a', EnumVariable 'b'> 
    268          >>> domain.class_var 
    269          EnumVariable 'c' 
    270  
    271      :param variables: List of variables (instances of :obj:`Orange.data.variable.Variable`) 
    272     :type variables: list 
     256    Construct a domain with the given variables; the 
     257    last one is used as the class variable. :: 
     258 
     259         >>> a, b, c = [Orange.data.variable.Discrete(x) for x in "abc"] 
     260         >>> domain = Orange.data.Domain([a, b, c]) 
     261         >>> domain.features 
     262         <EnumVariable 'a', EnumVariable 'b'> 
     263         >>> domain.class_var 
     264         EnumVariable 'c' 
     265 
     266     :param variables: List of variables (instances of :obj:`~Orange.data.variable.Variable`) 
     267    :type variables: list 
    273268     :param class_vars: A list of multiple classes; must be a keword argument 
    274269     :type class_vars: list 
     
    276271     .. method:: __init__(features, class_variable[, class_vars=]) 
    277272 
    278     Construct a domain with the given list of features and the 
    279     class variable. :: 
    280  
    281          >>> domain = Orange.data.Domain([a, b], c) 
    282          >>> domain.features 
    283          <EnumVariable 'a', EnumVariable 'b'> 
    284          >>> domain.class_var 
    285          EnumVariable 'c' 
    286  
    287      :param features: List of features (instances of :obj:`Orange.data.variable.Variable`) 
     273    Construct a domain with the given list of features and the 
     274    class variable. :: 
     275 
     276         >>> domain = Orange.data.Domain([a, b], c) 
     277         >>> domain.features 
     278         <EnumVariable 'a', EnumVariable 'b'> 
     279         >>> domain.class_var 
     280         EnumVariable 'c' 
     281 
     282     :param features: List of features (instances of :obj:`~Orange.data.variable.Variable`) 
    288283     :type features: list 
    289284     :param class_variable: Class variable 
     
    294289     .. method:: __init__(variables, has_class[, class_vars=]) 
    295290 
    296     Construct a domain with the given variables. If `has_class` is 
    297     :obj:`True`, the last one is used as the class variable. :: 
    298  
    299          >>> domain = Orange.data.Domain([a, b, c], False) 
    300          >>> domain.features 
    301          <EnumVariable 'a', EnumVariable 'b'> 
    302          >>> domain.class_var 
    303          EnumVariable 'c' 
    304  
    305      :param variables: List of variables (instances of :obj:`Orange.data.variable.Variable`) 
    306     :type features: list 
    307     :param has_class: A flag telling whether the domain has a class 
    308     :type has_class: bool 
     291    Construct a domain with the given variables. If `has_class` is 
     292    :obj:`True`, the last one is used as the class variable. :: 
     293 
     294         >>> domain = Orange.data.Domain([a, b, c], False) 
     295         >>> domain.features 
     296         <EnumVariable 'a', EnumVariable 'b'> 
     297         >>> domain.class_var 
     298         EnumVariable 'c' 
     299 
     300     :param variables: List of variables (instances of :obj:`~Orange.data.variable.Variable`) 
     301    :type features: list 
     302    :param has_class: A flag telling whether the domain has a class 
     303    :type has_class: bool 
    309304     :param class_vars: A list of multiple classes; must be a keyword argument 
    310305     :type class_vars: list 
     
    312307     .. method:: __init__(variables, source[, class_vars=]) 
    313308 
    314     Construct a domain with the given variables that can also be 
    315     specified by names if the variables with that names exist in the 
    316     source list. The last variable from the list is used as the class 
    317     variable. :: 
    318  
    319          >>> domain1 = orange.Domain([a, b]) 
    320          >>> domain2 = orange.Domain(["a", b, c], domain) 
    321  
    322      :param variables: List of variables (strings or instances of :obj:`Orange.data.variable.Variable`) 
    323     :type variables: list 
    324     :param source: An existing domain or a list of variables 
    325      :type source: Orange.data.Domain or list of :obj:`Orange.data.variable.Variable` 
     309    Construct a domain with the given variables that can also be 
     310    specified by names if the variables with that names exist in the 
     311    source list. The last variable from the list is used as the class 
     312    variable. :: 
     313 
     314         >>> domain1 = orange.Domain([a, b]) 
     315         >>> domain2 = orange.Domain(["a", b, c], domain) 
     316 
     317     :param variables: List of variables (strings or instances of :obj:`~Orange.data.variable.Variable`) 
     318    :type variables: list 
     319    :param source: An existing domain or a list of variables 
     320     :type source: Orange.data.Domain or list of :obj:`~Orange.data.variable.Variable` 
    326321     :param class_vars: A list of multiple classes; must be a keyword argument 
    327322     :type class_vars: list 
     
    329324     .. method:: __init__(variables, has_class, source[, class_vars=]) 
    330325 
    331     Similar to above except for the flag which tells whether the 
    332     last variable should be used as the class variable. :: 
    333  
    334          >>> domain1 = orange.Domain([a, b], False) 
    335          >>> domain2 = orange.Domain(["a", b, c], False, domain) 
    336  
    337      :param variables: List of variables (strings or instances of :obj:`Orange.data.variable.Variable`) 
    338     :type variables: list 
    339     :param has_class: A flag telling whether the domain has a class 
    340     :type has_class: bool 
    341     :param source: An existing domain or a list of variables 
    342      :type source: Orange.data.Domain or list of :obj:`Orange.data.variable.Variable` 
     326    Similar to above except for the flag which tells whether the 
     327    last variable should be used as the class variable. :: 
     328 
     329         >>> domain1 = orange.Domain([a, b], False) 
     330         >>> domain2 = orange.Domain(["a", b, c], False, domain) 
     331 
     332     :param variables: List of variables (strings or instances of :obj:`~Orange.data.variable.Variable`) 
     333    :type variables: list 
     334    :param has_class: A flag telling whether the domain has a class 
     335    :type has_class: bool 
     336    :param source: An existing domain or a list of variables 
     337     :type source: Orange.data.Domain or list of :obj:`~Orange.data.variable.Variable` 
    343338     :param class_vars: A list of multiple classes; must be a keyword argument 
    344339     :type class_vars: list 
     
    346341     .. method:: __init__(domain, class_var[, class_vars=]) 
    347342 
    348      Construct a copy of an existing domain 
    349      except that the class variable is replaced with the given one 
    350      and the class variable of the existing domain becomes an 
    351      ordinary feature. If the new class is one of the original 
    352      domain's features, it can also be specified by a name. 
    353  
    354      :param domain: An existing domain 
    355      :type domain: :obj:`Orange.variable.Domain` 
    356      :param class_var: Class variable for the new domain 
    357      :type class_var: string or :obj:`Orange.data.variable.Variable` 
     343     Construct a copy of an existing domain 
     344     except that the class variable is replaced with the given one 
     345     and the class variable of the existing domain becomes an 
     346     ordinary feature. If the new class is one of the original 
     347     domain's features, it can also be specified by a name. 
     348 
     349     :param domain: An existing domain 
     350     :type domain: :obj:`~Orange.variable.Domain` 
     351     :param class_var: Class variable for the new domain 
     352     :type class_var: string or :obj:`~Orange.data.variable.Variable` 
     353     :param class_vars: A list of multiple classes; must be a keyword argument 
     354     :type class_vars: list 
     355 
     356     .. method:: __init__(domain, has_class=False[, class_vars=]) 
     357 
     358     Construct a copy of the domain. If the ``has_class`` 
     359     flag is given and is :obj:`False`, it moves the class 
     360     attribute to ordinary features. 
     361 
     362     :param domain: An existing domain 
     363     :type domain: :obj:`~Orange.variable.Domain` 
     364     :param has_class: A flag telling whether the domain has a class 
     365     :type has_class: bool 
    358366     :param class_vars: A list of multiple classes; must be a keword argument 
    359367     :type class_vars: list 
    360368 
    361      .. method:: __init__(domain, has_class=False[, class_vars=]) 
    362  
    363      Construct a copy of the domain. If the ``has_class`` 
    364      flag is given and is :obj:`False`, it moves the class 
    365      attribute to ordinary features. 
    366  
    367      :param domain: An existing domain 
    368      :type domain: :obj:`Orange.variable.Domain` 
    369      :param has_class: A flag telling whether the domain has a class 
    370      :type has_class: bool 
    371      :param class_vars: A list of multiple classes; must be a keword argument 
    372      :type class_vars: list 
    373  
    374369     .. method:: has_discrete_attributes(include_class=True) 
    375370 
    376     Return :obj:`True` if the domain has any discrete variables; 
    377     class is included unless ``include_class`` is ``False``. 
    378  
    379     :param has_class: Tells whether to consider the class variable 
    380     :type has_class: bool 
    381     :rtype: bool 
     371    Return :obj:`True` if the domain has any discrete variables; 
     372    class is included unless ``include_class`` is ``False``. 
     373 
     374    :param has_class: Tells whether to consider the class variable 
     375    :type has_class: bool 
     376    :rtype: bool 
    382377 
    383378     .. method:: has_continuous_attributes(include_class=True) 
    384379 
    385     Return :obj:`True` if the domain has any continuous variables; 
    386     class is included unless ``include_class`` is ``False``. 
    387  
    388     :param has_class: Tells whether to consider the class variable 
    389     :type has_class: bool 
    390     :rtype: bool 
     380    Return :obj:`True` if the domain has any continuous variables; 
     381    class is included unless ``include_class`` is ``False``. 
     382 
     383    :param has_class: Tells whether to consider the class variable 
     384    :type has_class: bool 
     385    :rtype: bool 
    391386 
    392387     .. method:: has_other_attributes(include_class=True) 
    393388 
    394     Return :obj:`True` if the domain has any variables which are 
    395     neither discrete nor continuous, such as, for instance string variables. 
    396     class is included unless ``include_class`` is ``False``. 
    397  
    398     :param has_class: Tells whether to consider the class variable 
    399     :type has_class: bool 
    400     :rtype: bool 
     389    Return :obj:`True` if the domain has any variables which are 
     390    neither discrete nor continuous, such as, for instance string variables. 
     391    class is included unless ``include_class`` is ``False``. 
     392 
     393    :param has_class: Tells whether to consider the class variable 
     394    :type has_class: bool 
     395    :rtype: bool 
    401396 
    402397 
    403398     .. method:: add_meta(id, variable, optional=0) 
    404399 
    405     Register a meta attribute with the given id (obtained by 
    406     :obj:`Orange.data.new_meta_id`). The same meta attribute should 
    407     have the same id in all domain in which it is registered. :: 
    408  
    409          >>> newid = Orange.data.new_meta_id() 
    410          >>> domain.add_meta(newid, Orange.data.variable.String("origin")) 
    411          >>> data[55]["origin"] = "Nepal" 
    412          >>> data[55] 
    413          ['1', '0', '0', '1', '0', '0', '0', '1', '1', '1', '0', '0', 
    414          '4', '1', '0', '1', 'mammal'], {"name":'oryx', "origin":'Nepal'} 
    415  
    416     The third argument tells whether the meta attribute is optional or 
    417     not. The parameter is an integer, with any non-zero value meaning that 
    418     the attribute is optional. Different values can be used to distinguish 
    419     between various types optional attributes; the meaning of the value 
    420     is not defined in advance and can be used arbitrarily by the 
    421     application. 
    422  
    423     :param id: id of the new meta attribute 
    424     :type id: int 
    425     :param variable: variable descriptor 
    426     :type variable: Orange.data.variable.Variable 
    427     :param optional: tells whether the meta attribute is optional 
    428     :type optional: int 
     400    Register a meta attribute with the given id (obtained by 
     401    :obj:`Orange.data.new_meta_id`). The same meta attribute should 
     402    have the same id in all domain in which it is registered. :: 
     403 
     404         >>> newid = Orange.data.new_meta_id() 
     405         >>> domain.add_meta(newid, Orange.data.variable.String("origin")) 
     406         >>> data[55]["origin"] = "Nepal" 
     407         >>> data[55] 
     408         ['1', '0', '0', '1', '0', '0', '0', '1', '1', '1', '0', '0', 
     409         '4', '1', '0', '1', 'mammal'], {"name":'oryx', "origin":'Nepal'} 
     410 
     411    The third argument tells whether the meta attribute is optional or 
     412    not. The parameter is an integer, with any non-zero value meaning that 
     413    the attribute is optional. Different values can be used to distinguish 
     414    between various types optional attributes; the meaning of the value 
     415    is not defined in advance and can be used arbitrarily by the 
     416    application. 
     417 
     418    :param id: id of the new meta attribute 
     419    :type id: int 
     420    :param variable: variable descriptor 
     421    :type variable: Orange.data.variable.Variable 
     422    :param optional: tells whether the meta attribute is optional 
     423    :type optional: int 
    429424 
    430425     .. method:: add_metas(attributes, optional=0) 
    431426 
    432     Add multiple meta attributes at once. The dictionary contains id's as 
    433     keys and variables (:obj:~Orange.data.variable as the corresponding 
    434     values. The following example shows how to add all meta attributes 
    435     from one domain to another:: 
    436  
    437           newdomain.add_metas(domain.get_metas()) 
    438  
    439     The optional second argument has the same meaning as in :obj:`add_meta`. 
    440  
    441     :param attributes: dictionary of id's and variables 
    442     :type attributes: dict 
    443     :param optional: tells whether the meta attribute is optional 
    444     :type optional: int 
     427    Add multiple meta attributes at once. The dictionary contains id's as 
     428    keys and variables (:obj:~Orange.data.variable as the corresponding 
     429    values. The following example shows how to add all meta attributes 
     430    from one domain to another:: 
     431 
     432          newdomain.add_metas(domain.get_metas()) 
     433 
     434    The optional second argument has the same meaning as in :obj:`add_meta`. 
     435 
     436    :param attributes: dictionary of id's and variables 
     437    :type attributes: dict 
     438    :param optional: tells whether the meta attribute is optional 
     439    :type optional: int 
    445440 
    446441     .. method:: remove_meta(attribute) 
    447442 
    448     Removes one or multiple meta attributes. Removing a meta attribute has 
    449     no effect on data instances. 
    450  
    451     :param attribute: attribute(s) to be removed, given as name, id, variable descriptor or a list of them 
    452     :type attribute: string, int, Orange.data.variable.Variable; or a list 
     443    Removes one or multiple meta attributes. Removing a meta attribute has 
     444    no effect on data instances. 
     445 
     446    :param attribute: attribute(s) to be removed, given as name, id, variable descriptor or a list of them 
     447    :type attribute: string, int, Orange.data.variable.Variable; or a list 
    453448 
    454449     .. method:: has_attribute(attribute) 
    455450 
    456     Return True if the domain contains the specified meta attribute. 
    457  
    458     :param attribute: attribute to be checked 
    459     :type attribute: string, int, Orange.data.variable.Variable 
    460     :rtype: bool 
     451    Return True if the domain contains the specified meta attribute. 
     452 
     453    :param attribute: attribute to be checked 
     454    :type attribute: string, int, Orange.data.variable.Variable 
     455    :rtype: bool 
    461456 
    462457     .. method:: meta_id(attribute) 
    463458 
    464     Return an id of a meta attribute. 
    465  
    466     :param attribute: name or variable descriptor of the attribute 
    467     :type attribute: string or Orange.data.variable.Variable 
    468     :rtype: int 
     459    Return an id of a meta attribute. 
     460 
     461    :param attribute: name or variable descriptor of the attribute 
     462    :type attribute: string or Orange.data.variable.Variable 
     463    :rtype: int 
    469464 
    470465     .. method:: get_meta(attribute) 
    471466 
    472     Return a variable descriptor corresponding to the meta attribute. 
    473  
    474     :param attribute: name or id of the attribute 
    475     :type attribute: string or int 
    476     :rtype: Orange.data.variable.Variable 
     467    Return a variable descriptor corresponding to the meta attribute. 
     468 
     469    :param attribute: name or id of the attribute 
     470    :type attribute: string or int 
     471    :rtype: Orange.data.variable.Variable 
    477472 
    478473     .. method:: get_metas() 
    479474 
    480       Return a dictionary with meta attribute id's as keys and corresponding 
    481       variable descriptors as values. 
     475      Return a dictionary with meta attribute id's as keys and corresponding 
     476      variable descriptors as values. 
    482477 
    483478     .. method:: get_metas(optional) 
    484479 
    485       Return a dictionary with meta attribute id's as keys and corresponding 
    486       variable descriptors as values. The dictionary contains only meta 
    487       attributes for which the argument ``optional`` matches the flag given 
    488       when the attributes were added using :obj:`add_meta` or :obj:`add_metas`. 
    489  
    490       :param optional: flag that specifies the attributes to be returned 
    491       :type optional: int 
    492       :rtype: dict 
     480      Return a dictionary with meta attribute id's as keys and corresponding 
     481      variable descriptors as values. The dictionary contains only meta 
     482      attributes for which the argument ``optional`` matches the flag given 
     483      when the attributes were added using :obj:`add_meta` or :obj:`add_metas`. 
     484 
     485      :param optional: flag that specifies the attributes to be returned 
     486      :type optional: int 
     487      :rtype: dict 
    493488 
    494489     .. method:: is_optional_meta(attribute) 
    495490 
    496     Return True if the given meta attribute is optional, and False if it is 
    497     not. 
    498  
    499     :param attribute: attribute to be checked 
    500     :type attribute: string, int, Orange.data.variable.Variable 
    501     :rtype: bool 
     491    Return True if the given meta attribute is optional, and False if it is 
     492    not. 
     493 
     494    :param attribute: attribute to be checked 
     495    :type attribute: string, int, Orange.data.variable.Variable 
     496    :rtype: bool 
  • source/pyxtract/pyxtract.py

    r9505 r9677  
    929929  if len(myclasses): 
    930930    for classname in ks: 
     931      exportedname = "OrangeBase" if classname=="Orange" else classname 
    931932      if not classdefs[i].hidden: 
    932         functionsfile.write('     PyModule_AddObject(mod, "%s", (PyObject *)&PyOr%s_Type);\n' % (classname, classname)) 
     933        functionsfile.write('     PyModule_AddObject(mod, "%s", ' \ 
     934                            '(PyObject *)&PyOr%s_Type);\n' % 
     935                            (exportedname, classname)) 
    933936 
    934937  for type, fields in myclasses.items(): 
Note: See TracChangeset for help on using the changeset viewer.