Ignore:
Files:
1 deleted
49 edited

Legend:

Unmodified
Added
Removed
  • Orange/classification/rules.py

    r9701 r9738  
    611611 
    612612 
     613class ConvertClass: 
     614    """ Converting class variables into dichotomous class variable. """ 
     615    def __init__(self, classAtt, classValue, newClassAtt): 
     616        self.classAtt = classAtt 
     617        self.classValue = classValue 
     618        self.newClassAtt = newClassAtt 
     619 
     620    def __call__(self, example, returnWhat): 
     621        if example[self.classAtt] == self.classValue: 
     622            return Orange.data.Value(self.newClassAtt, self.classValue + "_") 
     623        else: 
     624            return Orange.data.Value(self.newClassAtt, "not " + self.classValue) 
     625 
     626 
     627def create_dichotomous_class(domain, att, value, negate, removeAtt=None): 
     628    # create new variable 
     629    newClass = Orange.data.variable.Discrete(att.name + "_", values=[str(value) + "_", "not " + str(value)]) 
     630    positive = Orange.data.Value(newClass, str(value) + "_") 
     631    negative = Orange.data.Value(newClass, "not " + str(value)) 
     632    newClass.getValueFrom = ConvertClass(att, str(value), newClass) 
     633 
     634    att = [a for a in domain.attributes] 
     635    newDomain = Orange.data.Domain(att + [newClass]) 
     636    newDomain.addmetas(domain.getmetas()) 
     637    if negate == 1: 
     638        return (newDomain, negative) 
     639    else: 
     640        return (newDomain, positive) 
     641 
     642 
    613643class LaplaceEvaluator(RuleEvaluator): 
    614644    """ 
     
    619649            return 0. 
    620650        sumDist = rule.class_distribution.cases 
    621         if not sumDist or (target_class>-1 and not rule.class_distribution[target_class]): 
     651        if not sumDist or (target_class > -1 and not rule.class_distribution[target_class]): 
    622652            return 0. 
    623653        # get distribution 
    624         if target_class>-1: 
    625             return (rule.class_distribution[target_class]+1)/(sumDist+2) 
     654        if target_class > -1: 
     655            return (rule.class_distribution[target_class] + 1) / (sumDist + 2) 
    626656        else: 
    627             return (max(rule.class_distribution)+1)/(sumDist+len(data.domain.class_var.values)) 
     657            return (max(rule.class_distribution) + 1) / (sumDist + len(data.domain.class_var.values)) 
    628658 
    629659LaplaceEvaluator = deprecated_members({"weightID": "weight_id", 
     
    639669            return 0. 
    640670        sumDist = rule.class_distribution.cases 
    641         if not sumDist or (target_class>-1 and not rule.class_distribution[target_class]): 
     671        if not sumDist or (target_class > -1 and not rule.class_distribution[target_class]): 
    642672            return 0. 
    643673        # get distribution 
    644         if target_class>-1: 
    645             pRule = rule.class_distribution[target_class]/apriori[target_class] 
    646             pTruePositive = rule.class_distribution[target_class]/sumDist 
    647             pClass = apriori[target_class]/apriori.cases 
     674        if target_class > -1: 
     675            pRule = rule.class_distribution[target_class] / apriori[target_class] 
     676            pTruePositive = rule.class_distribution[target_class] / sumDist 
     677            pClass = apriori[target_class] / apriori.cases 
    648678        else: 
    649             pRule = sumDist/apriori.cases 
    650             pTruePositive = max(rule.class_distribution)/sumDist 
    651             pClass = apriori[rule.class_distribution.modus()]/sum(apriori) 
    652         if pTruePositive>pClass: 
    653             return pRule*(pTruePositive-pClass) 
    654         else: return (pTruePositive-pClass)/max(pRule,1e-6) 
     679            pRule = sumDist / apriori.cases 
     680            pTruePositive = max(rule.class_distribution) / sumDist 
     681            pClass = apriori[rule.class_distribution.modus()] / sum(apriori) 
     682        if pTruePositive > pClass: 
     683            return pRule * (pTruePositive - pClass) 
     684        else: return (pTruePositive - pClass) / max(pRule, 1e-6) 
    655685 
    656686WRACCEvaluator = deprecated_members({"weightID": "weight_id", 
     
    675705            return 0. 
    676706        # get distribution 
    677         if target_class>-1: 
    678             p = rule.class_distribution[target_class]+self.m*apriori[target_class]/apriori.abs 
     707        if target_class > -1: 
     708            p = rule.class_distribution[target_class] + self.m * apriori[target_class] / apriori.abs 
    679709            p = p / (rule.class_distribution.abs + self.m) 
    680710        else: 
    681             p = max(rule.class_distribution)+self.m*apriori[rule.\ 
    682                 class_distribution.modus()]/apriori.abs 
    683             p = p / (rule.class_distribution.abs + self.m)       
     711            p = max(rule.class_distribution) + self.m * apriori[rule.\ 
     712                class_distribution.modus()] / apriori.abs 
     713            p = p / (rule.class_distribution.abs + self.m) 
    684714        return p 
    685715 
     
    707737 
    708738    """ 
    709      
     739 
    710740    def __new__(cls, instances=None, weight_id=0, **kwargs): 
    711741        self = RuleLearner.__new__(cls, **kwargs) 
     
    715745        else: 
    716746            return self 
    717          
    718     def __init__(self, evaluator = RuleEvaluator_Entropy(), beam_width = 5, 
    719         alpha = 1.0, **kwds): 
     747 
     748    def __init__(self, evaluator=RuleEvaluator_Entropy(), beam_width=5, 
     749        alpha=1.0, **kwds): 
    720750        self.__dict__.update(kwds) 
    721751        self.rule_finder = RuleBeamFinder() 
    722         self.rule_finder.ruleFilter = RuleBeamFilter_Width(width = beam_width) 
     752        self.rule_finder.ruleFilter = RuleBeamFilter_Width(width=beam_width) 
    723753        self.rule_finder.evaluator = evaluator 
    724         self.rule_finder.validator = RuleValidator_LRS(alpha = alpha) 
    725          
     754        self.rule_finder.validator = RuleValidator_LRS(alpha=alpha) 
     755 
    726756    def __call__(self, instances, weight=0): 
    727757        supervisedClassCheck(instances) 
    728          
    729         cl = RuleLearner.__call__(self,instances,weight) 
     758 
     759        cl = RuleLearner.__call__(self, instances, weight) 
    730760        rules = cl.rules 
    731761        return CN2Classifier(rules, instances, weight) 
     
    759789 
    760790    """ 
    761      
     791 
    762792    @deprecated_keywords({"examples": "instances"}) 
    763     def __init__(self, rules=None, instances=None, weight_id = 0, **argkw): 
     793    def __init__(self, rules=None, instances=None, weight_id=0, **argkw): 
    764794        self.rules = rules 
    765795        self.examples = instances 
     
    768798        self.__dict__.update(argkw) 
    769799        if instances is not None: 
    770             self.prior = Orange.statistics.distribution.Distribution(instances.domain.class_var,instances) 
     800            self.prior = Orange.statistics.distribution.Distribution(instances.domain.class_var, instances) 
    771801 
    772802    def __call__(self, instance, result_type=Orange.classification.Classifier.GetValue): 
     
    790820                break 
    791821        if not classifier: 
    792             classifier = Orange.classification.ConstantClassifier(instance.domain.class_var,\ 
     822            classifier = Orange.classification.ConstantClassifier(instance.domain.class_var, \ 
    793823                self.prior.modus()) 
    794824            classifier.defaultDistribution = self.prior 
     
    799829        if result_type == Orange.classification.Classifier.GetProbabilities: 
    800830          return classifier.default_distribution 
    801         return (classifier(instance),classifier.default_distribution) 
     831        return (classifier(instance), classifier.default_distribution) 
    802832 
    803833    def __str__(self): 
    804         ret_str = rule_to_string(self.rules[0])+" "+str(self.rules[0].\ 
    805             class_distribution)+"\n" 
     834        ret_str = rule_to_string(self.rules[0]) + " " + str(self.rules[0].\ 
     835            class_distribution) + "\n" 
    806836        for r in self.rules[1:]: 
    807             ret_str += "ELSE "+rule_to_string(r)+" "+str(r.class_distribution)+"\n" 
     837            ret_str += "ELSE " + rule_to_string(r) + " " + str(r.class_distribution) + "\n" 
    808838        return ret_str 
    809839 
     
    839869        else: 
    840870            return self 
    841              
    842     def __init__(self, evaluator = RuleEvaluator_Laplace(), beam_width = 5, 
    843         alpha = 1.0, **kwds): 
     871 
     872    def __init__(self, evaluator=RuleEvaluator_Laplace(), beam_width=5, 
     873        alpha=1.0, **kwds): 
    844874        self.__dict__.update(kwds) 
    845875        self.rule_finder = RuleBeamFinder() 
    846         self.rule_finder.ruleFilter = RuleBeamFilter_Width(width = beam_width) 
     876        self.rule_finder.ruleFilter = RuleBeamFilter_Width(width=beam_width) 
    847877        self.rule_finder.evaluator = evaluator 
    848         self.rule_finder.validator = RuleValidator_LRS(alpha = alpha) 
    849         self.rule_finder.rule_stoppingValidator = RuleValidator_LRS(alpha = 1.0) 
     878        self.rule_finder.validator = RuleValidator_LRS(alpha=alpha) 
     879        self.rule_finder.rule_stoppingValidator = RuleValidator_LRS(alpha=1.0) 
    850880        self.rule_stopping = RuleStopping_Apriori() 
    851881        self.data_stopping = RuleDataStoppingCriteria_NoPositives() 
    852      
     882 
    853883    @deprecated_keywords({"weight": "weight_id"}) 
    854884    def __call__(self, instances, weight_id=0): 
    855885        supervisedClassCheck(instances) 
    856          
     886 
    857887        rules = RuleList() 
    858888        self.rule_stopping.apriori = Orange.statistics.distribution.Distribution( 
    859             instances.domain.class_var,instances) 
    860         progress=getattr(self,"progressCallback",None) 
     889            instances.domain.class_var, instances) 
     890        progress = getattr(self, "progressCallback", None) 
    861891        if progress: 
    862892            progress.start = 0.0 
     
    870900                progress.end += distrib[target_class] 
    871901            self.target_class = target_class 
    872             cl = RuleLearner.__call__(self,instances,weight_id) 
     902            cl = RuleLearner.__call__(self, instances, weight_id) 
    873903            for r in cl.rules: 
    874904                rules.append(r) 
    875905        if progress: 
    876             progress(1.0,None) 
     906            progress(1.0, None) 
    877907        return CN2UnorderedClassifier(rules, instances, weight_id) 
    878908 
     
    907937 
    908938    @deprecated_keywords({"examples": "instances"}) 
    909     def __init__(self, rules = None, instances = None, weight_id = 0, **argkw): 
     939    def __init__(self, rules=None, instances=None, weight_id=0, **argkw): 
    910940        self.rules = rules 
    911941        self.examples = instances 
     
    918948 
    919949    @deprecated_keywords({"retRules": "ret_rules"}) 
    920     def __call__(self, instance, result_type=Orange.classification.Classifier.GetValue, ret_rules = False): 
     950    def __call__(self, instance, result_type=Orange.classification.Classifier.GetValue, ret_rules=False): 
    921951        """ 
    922952        :param instance: instance to be classified. 
     
    933963            disc = Orange.statistics.distribution.Discrete(disc1) 
    934964            sumdisc = sumd 
    935             for i,d in enumerate(disc): 
    936                 disc[i]+=disc2[i] 
     965            for i, d in enumerate(disc): 
     966                disc[i] += disc2[i] 
    937967                sumdisc += disc2[i] 
    938968            return disc, sumdisc 
     
    950980            retDist = self.prior 
    951981            sumdisc = self.prior.abs 
    952              
     982 
    953983        if sumdisc > 0.0: 
    954984            for c in self.examples.domain.class_var: 
     
    956986        else: 
    957987            retDist.normalize() 
    958          
     988 
    959989        if ret_rules: 
    960990            if result_type == Orange.classification.Classifier.GetValue: 
     
    962992            if result_type == Orange.classification.Classifier.GetProbabilities: 
    963993              return (retDist, covRules) 
    964             return (retDist.modus(),retDist,covRules) 
     994            return (retDist.modus(), retDist, covRules) 
    965995        if result_type == Orange.classification.Classifier.GetValue: 
    966996          return retDist.modus() 
    967997        if result_type == Orange.classification.Classifier.GetProbabilities: 
    968998          return retDist 
    969         return (retDist.modus(),retDist) 
     999        return (retDist.modus(), retDist) 
    9701000 
    9711001    def __str__(self): 
    9721002        retStr = "" 
    9731003        for r in self.rules: 
    974             retStr += rule_to_string(r)+" "+str(r.class_distribution)+"\n" 
     1004            retStr += rule_to_string(r) + " " + str(r.class_distribution) + "\n" 
    9751005        return retStr 
    9761006 
     
    10121042        else: 
    10131043            return self 
    1014          
    1015     def __init__(self, evaluator = WRACCEvaluator(), beam_width = 5, 
    1016                 alpha = 0.05, mult=0.7, **kwds): 
    1017         CN2UnorderedLearner.__init__(self, evaluator = evaluator, 
    1018                                           beam_width = beam_width, alpha = alpha, **kwds) 
     1044 
     1045    def __init__(self, evaluator=WRACCEvaluator(), beam_width=5, 
     1046                alpha=0.05, mult=0.7, **kwds): 
     1047        CN2UnorderedLearner.__init__(self, evaluator=evaluator, 
     1048                                          beam_width=beam_width, alpha=alpha, **kwds) 
    10191049        self.cover_and_remove = CovererAndRemover_MultWeights(mult=mult) 
    10201050 
    1021     def __call__(self, instances, weight=0):         
     1051    def __call__(self, instances, weight=0): 
    10221052        supervisedClassCheck(instances) 
    1023          
     1053 
    10241054        oldInstances = Orange.data.Table(instances) 
    1025         classifier = CN2UnorderedLearner.__call__(self,instances,weight) 
     1055        classifier = CN2UnorderedLearner.__call__(self, instances, weight) 
    10261056        for r in classifier.rules: 
    1027             r.filterAndStore(oldInstances,weight,r.classifier.default_val) 
     1057            r.filterAndStore(oldInstances, weight, r.classifier.default_val) 
    10281058        return classifier 
    10291059 
     
    10951125 
    10961126    """ 
    1097      
     1127 
    10981128    def __init__(self, argument_id=0, width=5, m=2, opt_reduction=2, nsampling=100, max_rule_complexity=5, 
    10991129                 rule_sig=1.0, att_sig=1.0, postpruning=None, min_quality=0., min_coverage=1, min_improved=1, min_improved_perc=0.0, 
    1100                  learn_for_class = None, learn_one_rule = False, evd=None, evd_arguments=None, prune_arguments=False, analyse_argument=-1, 
    1101                  alternative_learner = None, min_cl_sig = 0.5, min_beta = 0.0, set_prefix_rules = False, add_sub_rules = False, debug=False, 
     1130                 learn_for_class=None, learn_one_rule=False, evd=None, evd_arguments=None, prune_arguments=False, analyse_argument= -1, 
     1131                 alternative_learner=None, min_cl_sig=0.5, min_beta=0.0, set_prefix_rules=False, add_sub_rules=False, debug=False, 
    11021132                 **kwds): 
    1103          
     1133 
    11041134        # argument ID which is passed to abcn2 learner 
    11051135        self.argument_id = argument_id 
     
    11171147        if max_rule_complexity - 1 < 0: 
    11181148            max_rule_complexity = 10 
    1119         self.rule_finder.rule_stoppingValidator = RuleValidator_LRS(alpha = 1.0, min_quality = 0., max_rule_complexity = max_rule_complexity - 1, min_coverage=min_coverage) 
     1149        self.rule_finder.rule_stoppingValidator = RuleValidator_LRS(alpha=1.0, min_quality=0., max_rule_complexity=max_rule_complexity - 1, min_coverage=min_coverage) 
    11201150        self.refiner = RuleBeamRefiner_Selector() 
    1121         self.refiner_arguments = SelectorAdder(discretizer = Orange.feature.discretization.EntropyDiscretization(forceAttribute = 1, 
    1122                                                                                            maxNumberOfIntervals = 2)) 
     1151        self.refiner_arguments = SelectorAdder(discretizer=Orange.feature.discretization.EntropyDiscretization(forceAttribute=1, 
     1152                                                                                           maxNumberOfIntervals=2)) 
    11231153        self.prune_arguments = prune_arguments 
    11241154        # evc evaluator 
    11251155        evdGet = Orange.core.EVDistGetter_Standard() 
    1126         self.rule_finder.evaluator = RuleEvaluator_mEVC(m=m, evDistGetter = evdGet, min_improved = min_improved, min_improved_perc = min_improved_perc) 
     1156        self.rule_finder.evaluator = RuleEvaluator_mEVC(m=m, evDistGetter=evdGet, min_improved=min_improved, min_improved_perc=min_improved_perc) 
    11271157        self.rule_finder.evaluator.returnExpectedProb = True 
    11281158        self.rule_finder.evaluator.optimismReduction = opt_reduction 
    11291159        self.rule_finder.evaluator.ruleAlpha = rule_sig 
    11301160        self.rule_finder.evaluator.attributeAlpha = att_sig 
    1131         self.rule_finder.evaluator.validator = RuleValidator_LRS(alpha = 1.0, min_quality = min_quality, min_coverage=min_coverage, max_rule_complexity = max_rule_complexity - 1) 
     1161        self.rule_finder.evaluator.validator = RuleValidator_LRS(alpha=1.0, min_quality=min_quality, min_coverage=min_coverage, max_rule_complexity=max_rule_complexity - 1) 
    11321162 
    11331163        # learn stopping criteria 
     
    11351165        self.data_stopping = RuleDataStoppingCriteria_NoPositives() 
    11361166        # evd fitting 
    1137         self.evd_creator = EVDFitter(self,n=nsampling) 
     1167        self.evd_creator = EVDFitter(self, n=nsampling) 
    11381168        self.evd = evd 
    11391169        self.evd_arguments = evd_arguments 
    11401170        # classifier 
    11411171        self.add_sub_rules = add_sub_rules 
    1142         self.classifier = PILAR(alternative_learner = alternative_learner, min_cl_sig = min_cl_sig, min_beta = min_beta, set_prefix_rules = set_prefix_rules) 
     1172        self.classifier = PILAR(alternative_learner=alternative_learner, min_cl_sig=min_cl_sig, min_beta=min_beta, set_prefix_rules=set_prefix_rules) 
    11431173        self.debug = debug 
    11441174        # arbitrary parameters 
     
    11481178    def __call__(self, examples, weight_id=0): 
    11491179        # initialize progress bar 
    1150         progress=getattr(self,"progressCallback",None) 
     1180        progress = getattr(self, "progressCallback", None) 
    11511181        if progress: 
    11521182            progress.start = 0.0 
     
    11551185                             examples.domain.class_var, examples, weight_id) 
    11561186            distrib.normalize() 
    1157          
     1187 
    11581188        # we begin with an empty set of rules 
    11591189        all_rules = RuleList() 
    11601190 
    11611191        # th en, iterate through all classes and learn rule for each class separately 
    1162         for cl_i,cl in enumerate(examples.domain.class_var): 
     1192        for cl_i, cl in enumerate(examples.domain.class_var): 
    11631193            if progress: 
    11641194                step = distrib[cl] / 2. 
    11651195                progress.start = progress.end 
    11661196                progress.end += step 
    1167                  
    1168             if self.learn_for_class and not self.learn_for_class in [cl,cl_i]: 
     1197 
     1198            if self.learn_for_class and not self.learn_for_class in [cl, cl_i]: 
    11691199                continue 
    11701200 
     
    11871217                progress.start = progress.end 
    11881218                progress.end += step 
    1189              
     1219 
    11901220            aes = self.get_argumented_examples(dich_data) 
    11911221            aes = self.sort_arguments(aes, dich_data) 
     
    12101240 
    12111241            if not progress and self.debug: 
    1212                 print " arguments finished ... "                     
    1213                     
     1242                print " arguments finished ... " 
     1243 
    12141244            # remove all examples covered by rules 
    12151245            for rule in rules: 
    12161246                dich_data = self.remove_covered_examples(rule, dich_data, weight_id) 
    12171247            if progress: 
    1218                 progress(self.remaining_probability(dich_data),None) 
     1248                progress(self.remaining_probability(dich_data), None) 
    12191249 
    12201250            # learn normal rules on remaining examples 
     
    12301260                    dich_data = self.remove_covered_examples(rule, dich_data, weight_id) 
    12311261                    if progress: 
    1232                         progress(self.remaining_probability(dich_data),None) 
     1262                        progress(self.remaining_probability(dich_data), None) 
    12331263                    rules.append(rule) 
    12341264                    if self.learn_one_rule: 
     
    12461276 
    12471277            if progress: 
    1248                 progress(1.0,None) 
     1278                progress(1.0, None) 
    12491279        # create a classifier from all rules         
    12501280        return self.create_classifier(all_rules, examples, weight_id) 
     
    12541284        positive_args = self.init_pos_args(ae, examples, weight_id) 
    12551285        if not positive_args: # something wrong 
    1256             raise "There is a problem with argumented example %s"%str(ae) 
     1286            raise "There is a problem with argumented example %s" % str(ae) 
    12571287            return None 
    12581288        negative_args = self.init_neg_args(ae, examples, weight_id) 
     
    12621292        self.rule_finder.refiner.example = ae 
    12631293        # set arguments to filter 
    1264         self.rule_finder.ruleFilter.setArguments(examples.domain,positive_args) 
     1294        self.rule_finder.ruleFilter.setArguments(examples.domain, positive_args) 
    12651295 
    12661296        # learn a rule 
    12671297        self.rule_finder.evaluator.bestRule = None 
    1268         self.rule_finder(examples,weight_id, 0, positive_args) 
    1269          
     1298        self.rule_finder(examples, weight_id, 0, positive_args) 
     1299 
    12701300        # return best rule 
    12711301        return self.rule_finder.evaluator.bestRule 
    1272          
     1302 
    12731303    def prepare_settings(self, examples, weight_id, cl_i, progress): 
    12741304        # apriori distribution 
    12751305        self.apriori = Orange.statistics.distribution.Distribution( 
    1276                                 examples.domain.class_var,examples,weight_id) 
    1277          
     1306                                examples.domain.class_var, examples, weight_id) 
     1307 
    12781308        # prepare covering mechanism 
    12791309        self.coverAndRemove = CovererAndRemover_Prob(examples, weight_id, 0, self.apriori, self.argument_id) 
     
    12831313        # TODO: why evd and evd_this???? 
    12841314        if self.rule_finder.evaluator.optimismReduction > 0 and not self.evd: 
    1285             self.evd_this = self.evd_creator.computeEVD(examples, weight_id, target_class=0, progress = progress) 
     1315            self.evd_this = self.evd_creator.computeEVD(examples, weight_id, target_class=0, progress=progress) 
    12861316        if self.evd: 
    12871317            self.evd_this = self.evd[cl_i] 
     
    13031333        Create dichotomous class. 
    13041334        """ 
    1305         (newDomain, targetVal) = createDichotomousClass(examples.domain, examples.domain.class_var, str(cl), negate=0) 
     1335        (newDomain, targetVal) = create_dichotomous_class(examples.domain, examples.domain.class_var, str(cl), negate=0) 
    13061336        newDomainmetas = newDomain.getmetas() 
    13071337        newDomain.addmeta(Orange.data.new_meta_id(), examples.domain.class_var) # old class as meta 
     
    13161346        if not self.argument_id: 
    13171347            return None 
    1318          
     1348 
    13191349        # get argumented examples 
    1320         return ArgumentFilter_hasSpecial()(examples, self.argument_id, target_class = 0) 
     1350        return ArgumentFilter_hasSpecial()(examples, self.argument_id, target_class=0) 
    13211351 
    13221352    def sort_arguments(self, arg_examples, examples): 
     
    13241354            return None 
    13251355        evaluateAndSortArguments(examples, self.argument_id) 
    1326         if len(arg_examples)>0: 
     1356        if len(arg_examples) > 0: 
    13271357            # sort examples by their arguments quality (using first argument as it has already been sorted) 
    13281358            sorted = arg_examples.native() 
    1329             sorted.sort(lambda x,y: -cmp(x[self.argument_id].value.positive_arguments[0].quality, 
     1359            sorted.sort(lambda x, y:-cmp(x[self.argument_id].value.positive_arguments[0].quality, 
    13301360                                         y[self.argument_id].value.positive_arguments[0].quality)) 
    13311361            return Orange.data.Table(examples.domain, sorted) 
     
    13431373        self.rule_finder.refiner = self.refiner 
    13441374        self.rule_finder.ruleFilter = self.ruleFilter 
    1345          
     1375 
    13461376    def learn_normal_rule(self, examples, weight_id, apriori): 
    13471377        if hasattr(self.rule_finder.evaluator, "bestRule"): 
    13481378            self.rule_finder.evaluator.bestRule = None 
    1349         rule = self.rule_finder(examples,weight_id,0,RuleList()) 
     1379        rule = self.rule_finder(examples, weight_id, 0, RuleList()) 
    13501380        if hasattr(self.rule_finder.evaluator, "bestRule") and self.rule_finder.evaluator.returnExpectedProb: 
    13511381            rule = self.rule_finder.evaluator.bestRule 
    13521382            self.rule_finder.evaluator.bestRule = None 
    13531383        if self.postpruning: 
    1354             rule = self.postpruning(rule,examples,weight_id,0, aprior) 
     1384            rule = self.postpruning(rule, examples, weight_id, 0, aprior) 
    13551385        return rule 
    13561386 
    13571387    def remove_covered_examples(self, rule, examples, weight_id): 
    1358         nexamples, nweight = self.cover_and_remove(rule,examples,weight_id,0) 
     1388        nexamples, nweight = self.cover_and_remove(rule, examples, weight_id, 0) 
    13591389        return nexamples 
    13601390 
    13611391 
    13621392    def prune_unnecessary_rules(self, rules, examples, weight_id): 
    1363         return self.cover_and_remove.getBestRules(rules,examples,weight_id) 
     1393        return self.cover_and_remove.getBestRules(rules, examples, weight_id) 
    13641394 
    13651395    def change_domain(self, rule, cl, examples, weight_id): 
    1366         rule.filter = Orange.core.Filter_values(domain = examples.domain, 
    1367                                         conditions = rule.filter.conditions) 
    1368         rule.filterAndStore(examples, weight_id, cl)         
     1396        rule.filter = Orange.core.Filter_values(domain=examples.domain, 
     1397                                        conditions=rule.filter.conditions) 
     1398        rule.filterAndStore(examples, weight_id, cl) 
    13691399        if hasattr(rule, "learner") and hasattr(rule.learner, "arg_example"): 
    13701400            rule.learner.arg_example = Orange.data.Instance(examples.domain, rule.learner.arg_example) 
     
    13761406    def add_sub_rules_call(self, rules, examples, weight_id): 
    13771407        apriori = Orange.statistics.distribution.Distribution( 
    1378                             examples.domain.class_var,examples,weight_id) 
     1408                            examples.domain.class_var, examples, weight_id) 
    13791409        new_rules = RuleList() 
    13801410        for r in rules: 
     
    13871417            tmpRle.filter.conditions = r.filter.conditions[:r.requiredConditions] # do not split argument 
    13881418            tmpRle.parentRule = None 
    1389             tmpRle.filterAndStore(examples,weight_id,r.classifier.default_val) 
     1419            tmpRle.filterAndStore(examples, weight_id, r.classifier.default_val) 
    13901420            tmpRle.complexity = 0 
    13911421            tmpList.append(tmpRle) 
     
    13961426                    oldREP = self.rule_finder.evaluator.returnExpectedProb 
    13971427                    self.rule_finder.evaluator.returnExpectedProb = False 
    1398                     tmpRule.quality = self.rule_finder.evaluator(tmpRule,examples,weight_id,r.classifier.default_val,apriori) 
     1428                    tmpRule.quality = self.rule_finder.evaluator(tmpRule, examples, weight_id, r.classifier.default_val, apriori) 
    13991429                    self.rule_finder.evaluator.returnExpectedProb = oldREP 
    1400                 tmpList.sort(lambda x,y: -cmp(x.quality, y.quality)) 
     1430                tmpList.sort(lambda x, y:-cmp(x.quality, y.quality)) 
    14011431                tmpList = tmpList[:self.rule_filter.width] 
    1402                      
     1432 
    14031433                for tmpRule in tmpList: 
    14041434                    # if rule not in rules already, add it to the list 
    1405                     if not True in [Orange.classification.rules.rules_equal(ri,tmpRule) for ri in new_rules] and len(tmpRule.filter.conditions)>0 and tmpRule.quality > apriori[r.classifier.default_val]/apriori.abs: 
     1435                    if not True in [Orange.classification.rules.rules_equal(ri, tmpRule) for ri in new_rules] and len(tmpRule.filter.conditions) > 0 and tmpRule.quality > apriori[r.classifier.default_val] / apriori.abs: 
    14061436                        new_rules.append(tmpRule) 
    14071437                    # create new tmpRules, set parent Rule, append them to tmpList2 
    1408                     if not True in [Orange.classification.rules.rules_equal(ri,tmpRule) for ri in new_rules]: 
     1438                    if not True in [Orange.classification.rules.rules_equal(ri, tmpRule) for ri in new_rules]: 
    14091439                        for c in r.filter.conditions: 
    14101440                            tmpRule2 = tmpRule.clone() 
    14111441                            tmpRule2.parentRule = tmpRule 
    14121442                            tmpRule2.filter.conditions.append(c) 
    1413                             tmpRule2.filterAndStore(examples,weight_id,r.classifier.default_val) 
     1443                            tmpRule2.filterAndStore(examples, weight_id, r.classifier.default_val) 
    14141444                            tmpRule2.complexity += 1 
    14151445                            if tmpRule2.class_distribution.abs < tmprule.class_distribution.abs: 
     
    14221452        # prepare arguments 
    14231453        for p in ae[self.argument_id].value.positive_arguments: 
    1424             new_arg = Rule(filter=ArgFilter(argument_id = self.argument_id, 
    1425                                                    filter = self.newFilter_values(p.filter), 
    1426                                                    arg_example = ae), 
    1427                                                    complexity = 0) 
     1454            new_arg = Rule(filter=ArgFilter(argument_id=self.argument_id, 
     1455                                                   filter=self.newFilter_values(p.filter), 
     1456                                                   arg_example=ae), 
     1457                                                   complexity=0) 
    14281458            new_arg.valuesFilter = new_arg.filter.filter 
    14291459            pos_args.append(new_arg) 
     
    14331463            old_exp = self.rule_finder.evaluator.returnExpectedProb 
    14341464            self.rule_finder.evaluator.returnExpectedProb = False 
    1435              
     1465 
    14361466        # argument pruning (all or just unfinished arguments) 
    14371467        # if pruning is chosen, then prune arguments if possible 
     
    14471477                p.filter.conditions = pruned_conditions 
    14481478                p.learner.setattr("arg_length", 0) 
    1449                  
     1479 
    14501480            else: # prune only unspecified conditions 
    14511481                spec_conditions = [c for c in p.filter.conditions if not c.unspecialized_condition] 
     
    14651495                        # find minimum value 
    14661496                        if u.oper == Orange.core.ValueFilter_continuous.Greater or u.oper == Orange.core.ValueFilter_continuous.GreaterEqual: 
    1467                             u.ref = min([float(e[u.position])-10. for e in p.examples]) 
     1497                            u.ref = min([float(e[u.position]) - 10. for e in p.examples]) 
    14681498                        else: 
    1469                             u.ref = max([float(e[u.position])+10. for e in p.examples]) 
     1499                            u.ref = max([float(e[u.position]) + 10. for e in p.examples]) 
    14701500                        p.filter.conditions.append(u) 
    14711501                        p.filter.filter.conditions.append(u) 
    1472                  
     1502 
    14731503        # set parameters to arguments 
    1474         for p_i,p in enumerate(pos_args): 
    1475             p.filterAndStore(examples,weight_id,0) 
     1504        for p_i, p in enumerate(pos_args): 
     1505            p.filterAndStore(examples, weight_id, 0) 
    14761506            p.filter.domain = examples.domain 
    14771507            p.classifier = p.learner(p.examples, p.weightID) 
     
    14791509            p.learner.setattr("arg_example", ae) 
    14801510            p.complexity = len(p.filter.conditions) 
    1481              
     1511 
    14821512        if hasattr(self.rule_finder.evaluator, "returnExpectedProb"): 
    14831513            self.rule_finder.evaluator.returnExpectedProb = old_exp 
     
    15061536        cn2_learner.rule_finder.refiner = SelectorArgConditions(crit_example, allowed_conditions) 
    15071537        cn2_learner.rule_finder.evaluator = Orange.classification.rules.MEstimateEvaluator(self.rule_finder.evaluator.m) 
    1508         rule = cn2_learner.rule_finder(examples,weight_id,0,RuleList()) 
     1538        rule = cn2_learner.rule_finder(examples, weight_id, 0, RuleList()) 
    15091539        return rule.filter.conditions 
    15101540 
     
    15441574    :type mult: float 
    15451575    """ 
    1546     def __init__(self, width=5, nsampling=100, rule_sig=1.0, att_sig=1.0,\ 
    1547         min_coverage = 1., max_rule_complexity = 5.): 
     1576    def __init__(self, width=5, nsampling=100, rule_sig=1.0, att_sig=1.0, \ 
     1577        min_coverage=1., max_rule_complexity=5.): 
    15481578        ABCN2.__init__(self, width=width, nsampling=nsampling, 
    15491579            rule_sig=rule_sig, att_sig=att_sig, min_coverage=int(min_coverage), 
    1550             max_rule_complexity = int(max_rule_complexity)) 
     1580            max_rule_complexity=int(max_rule_complexity)) 
    15511581 
    15521582class DefaultLearner(Orange.core.Learner): 
     
    15541584    Default lerner - returns default classifier with predefined output class. 
    15551585    """ 
    1556     def __init__(self,default_value = None): 
     1586    def __init__(self, default_value=None): 
    15571587        self.default_value = default_value 
    1558     def __call__(self,examples,weight_id=0): 
    1559         return Orange.classification.majority.ConstantClassifier(self.default_value,defaultDistribution = Orange.core.Distribution(examples.domain.class_var,examples,weight_id)) 
     1588    def __call__(self, examples, weight_id=0): 
     1589        return Orange.classification.majority.ConstantClassifier(self.default_value, defaultDistribution=Orange.core.Distribution(examples.domain.class_var, examples, weight_id)) 
    15601590 
    15611591class ABCN2Ordered(ABCN2): 
     
    15751605        ABCN2.__init__(self, argument_id=argument_id, **kwds) 
    15761606        self.opt_reduction = 0 
    1577         self.rule_finder.evaluator.optimismReduction = self.opt_reduction         
     1607        self.rule_finder.evaluator.optimismReduction = self.opt_reduction 
    15781608        self.classifier = CN2UnorderedClassifier 
    15791609 
     
    15851615        ABCN2.__init__(self, argument_id=argument_id, **kwds) 
    15861616        self.opt_reduction = 0 
    1587         self.rule_finder.evaluator.optimismReduction = self.opt_reduction         
     1617        self.rule_finder.evaluator.optimismReduction = self.opt_reduction 
    15881618 
    15891619class ABCN2_StandardClassification(ABCN2): 
     
    15931623    def __init__(self, argument_id=0, **kwds): 
    15941624        ABCN2.__init__(self, argument_id=argument_id, **kwds) 
    1595         self.classifier = CN2UnorderedClassifier         
     1625        self.classifier = CN2UnorderedClassifier 
    15961626 
    15971627 
    15981628class RuleStopping_Apriori(RuleStoppingCriteria): 
    15991629    def __init__(self, apriori=None): 
    1600         self.apriori =  None 
    1601          
    1602     def __call__(self,rules,rule,instances,data): 
     1630        self.apriori = None 
     1631 
     1632    def __call__(self, rules, rule, instances, data): 
    16031633        if not self.apriori: 
    16041634            return False 
    16051635        if not type(rule.classifier) == Orange.classification.ConstantClassifier: 
    16061636            return False 
    1607         ruleAcc = rule.class_distribution[rule.classifier.default_val]/rule.class_distribution.abs 
    1608         aprioriAcc = self.apriori[rule.classifier.default_val]/self.apriori.abs 
    1609         if ruleAcc>aprioriAcc: 
     1637        ruleAcc = rule.class_distribution[rule.classifier.default_val] / rule.class_distribution.abs 
     1638        aprioriAcc = self.apriori[rule.classifier.default_val] / self.apriori.abs 
     1639        if ruleAcc > aprioriAcc: 
    16101640            return False 
    16111641        return True 
     
    16131643 
    16141644class RuleStopping_SetRules(RuleStoppingCriteria): 
    1615     def __init__(self,validator): 
     1645    def __init__(self, validator): 
    16161646        self.rule_stopping = RuleStoppingCriteria_NegativeDistribution() 
    16171647        self.validator = validator 
    16181648 
    1619     def __call__(self,rules,rule,instances,data):         
    1620         ru_st = self.rule_stopping(rules,rule,instances,data) 
     1649    def __call__(self, rules, rule, instances, data): 
     1650        ru_st = self.rule_stopping(rules, rule, instances, data) 
    16211651        if not ru_st: 
    16221652            self.validator.rules.append(rule) 
     
    16261656class LengthValidator(RuleValidator): 
    16271657    """ prune rules with more conditions than self.length. """ 
    1628     def __init__(self, length=-1): 
     1658    def __init__(self, length= -1): 
    16291659        self.length = length 
    1630          
     1660 
    16311661    def __call__(self, rule, data, weight_id, target_class, apriori): 
    16321662        if self.length >= 0: 
    16331663            return len(rule.filter.conditions) <= self.length 
    1634         return True     
     1664        return True 
    16351665 
    16361666 
    16371667class NoDuplicatesValidator(RuleValidator): 
    1638     def __init__(self,alpha=.05,min_coverage=0,max_rule_length=0,rules=RuleList()): 
     1668    def __init__(self, alpha=.05, min_coverage=0, max_rule_length=0, rules=RuleList()): 
    16391669        self.rules = rules 
    1640         self.validator = RuleValidator_LRS(alpha=alpha,\ 
    1641             min_coverage=min_coverage,max_rule_length=max_rule_length) 
    1642          
     1670        self.validator = RuleValidator_LRS(alpha=alpha, \ 
     1671            min_coverage=min_coverage, max_rule_length=max_rule_length) 
     1672 
    16431673    def __call__(self, rule, data, weight_id, target_class, apriori): 
    1644         if rule_in_set(rule,self.rules): 
     1674        if rule_in_set(rule, self.rules): 
    16451675            return False 
    1646         return bool(self.validator(rule,data,weight_id,target_class,apriori)) 
    1647                  
     1676        return bool(self.validator(rule, data, weight_id, target_class, apriori)) 
     1677 
    16481678 
    16491679 
    16501680class RuleClassifier_BestRule(RuleClassifier): 
    1651     def __init__(self, rules, instances, weight_id = 0, **argkw): 
     1681    def __init__(self, rules, instances, weight_id=0, **argkw): 
    16521682        self.rules = rules 
    16531683        self.examples = instances 
     
    16611691        bestRule = None 
    16621692        for r in self.rules: 
    1663             if r(instance) and (not bestRule or r.quality>bestRule.quality): 
    1664                 for v_i,v in enumerate(instance.domain.class_var): 
     1693            if r(instance) and (not bestRule or r.quality > bestRule.quality): 
     1694                for v_i, v in enumerate(instance.domain.class_var): 
    16651695                    retDist[v_i] = r.class_distribution[v_i] 
    16661696                bestRule = r 
     
    16801710        if result_type == Orange.classification.Classifier.GetProbabilities: 
    16811711          return retDist 
    1682         return (retDist.modus(),retDist) 
     1712        return (retDist.modus(), retDist) 
    16831713 
    16841714    def __str__(self): 
    16851715        retStr = "" 
    16861716        for r in self.rules: 
    1687             retStr += rule_to_string(r)+" "+str(r.class_distribution)+"\n" 
    1688         return retStr     
     1717            retStr += rule_to_string(r) + " " + str(r.class_distribution) + "\n" 
     1718        return retStr 
    16891719 
    16901720 
     
    16961726    :type mult: float     
    16971727    """ 
    1698      
    1699     def __init__(self, mult = 0.7): 
     1728 
     1729    def __init__(self, mult=0.7): 
    17001730        self.mult = mult 
    17011731    def __call__(self, rule, instances, weights, target_class): 
    17021732        if not weights: 
    17031733            weights = Orange.data.new_meta_id() 
    1704             instances.addMetaAttribute(weights,1.) 
     1734            instances.addMetaAttribute(weights, 1.) 
    17051735            instances.domain.addmeta(weights, Orange.data.variable.\ 
    1706                 Continuous("weights-"+str(weights)), True) 
     1736                Continuous("weights-" + str(weights)), True) 
    17071737        newWeightsID = Orange.data.new_meta_id() 
    1708         instances.addMetaAttribute(newWeightsID,1.) 
     1738        instances.addMetaAttribute(newWeightsID, 1.) 
    17091739        instances.domain.addmeta(newWeightsID, Orange.data.variable.\ 
    1710             Continuous("weights-"+str(newWeightsID)), True) 
     1740            Continuous("weights-" + str(newWeightsID)), True) 
    17111741        for instance in instances: 
    17121742            if rule(instance) and instance.getclass() == rule.classifier(\ 
    1713                 instance,Orange.classification.Classifier.GetValue): 
    1714                 instance[newWeightsID]=instance[weights]*self.mult 
     1743                instance, Orange.classification.Classifier.GetValue): 
     1744                instance[newWeightsID] = instance[weights] * self.mult 
    17151745            else: 
    1716                 instance[newWeightsID]=instance[weights] 
    1717         return (instances,newWeightsID) 
     1746                instance[newWeightsID] = instance[weights] 
     1747        return (instances, newWeightsID) 
    17181748 
    17191749 
     
    17231753     
    17241754    """ 
    1725      
     1755 
    17261756    def __call__(self, rule, instances, weights, target_class): 
    17271757        if not weights: 
    17281758            weights = Orange.data.new_meta_id() 
    1729             instances.addMetaAttribute(weights,1.) 
     1759            instances.addMetaAttribute(weights, 1.) 
    17301760            instances.domain.addmeta(weights, Orange.data.variable.\ 
    1731                 Continuous("weights-"+str(weights)), True) 
     1761                Continuous("weights-" + str(weights)), True) 
    17321762        try: 
    17331763            coverage = instances.domain.getmeta("Coverage") 
    17341764        except: 
    17351765            coverage = Orange.data.variable.Continuous("Coverage") 
    1736             instances.domain.addmeta(Orange.data.new_meta_id(),coverage, True) 
    1737             instances.addMetaAttribute(coverage,0.0) 
     1766            instances.domain.addmeta(Orange.data.new_meta_id(), coverage, True) 
     1767            instances.addMetaAttribute(coverage, 0.0) 
    17381768        newWeightsID = Orange.data.new_meta_id() 
    1739         instances.addMetaAttribute(newWeightsID,1.) 
     1769        instances.addMetaAttribute(newWeightsID, 1.) 
    17401770        instances.domain.addmeta(newWeightsID, Orange.data.variable.\ 
    1741             Continuous("weights-"+str(newWeightsID)), True) 
     1771            Continuous("weights-" + str(newWeightsID)), True) 
    17421772        for instance in instances: 
    1743             if rule(instance) and instance.getclass() == rule.classifier(instance,\ 
     1773            if rule(instance) and instance.getclass() == rule.classifier(instance, \ 
    17441774                    Orange.classification.Classifier.GetValue): 
    17451775                try: 
    1746                     instance[coverage]+=1.0 
     1776                    instance[coverage] += 1.0 
    17471777                except: 
    1748                     instance[coverage]=1.0 
    1749                 instance[newWeightsID]=1.0/(instance[coverage]+1) 
     1778                    instance[coverage] = 1.0 
     1779                instance[newWeightsID] = 1.0 / (instance[coverage] + 1) 
    17501780            else: 
    1751                 instance[newWeightsID]=instance[weights] 
    1752         return (instances,newWeightsID) 
     1781                instance[newWeightsID] = instance[weights] 
     1782        return (instances, newWeightsID) 
    17531783 
    17541784 
     
    17561786    """ This class impements probabilistic covering. """ 
    17571787    def __init__(self, examples, weight_id, target_class, apriori, argument_id): 
    1758         self.best_rule = [None]*len(examples) 
     1788        self.best_rule = [None] * len(examples) 
    17591789        self.prob_attribute = Orange.data.new_meta_id() 
    1760         self.apriori_prob = apriori[target_class]/apriori.abs 
     1790        self.apriori_prob = apriori[target_class] / apriori.abs 
    17611791        examples.addMetaAttribute(self.prob_attribute, self.apriori_prob) 
    1762         examples.domain.addmeta(self.prob_attribute,  
     1792        examples.domain.addmeta(self.prob_attribute, 
    17631793            Orange.data.variable.Continuous("Probs")) 
    17641794        self.argument_id = argument_id 
     
    17661796    def getBestRules(self, current_rules, examples, weight_id): 
    17671797        best_rules = RuleList() 
    1768         for r_i,r in enumerate(self.best_rule): 
    1769             if r and not rule_in_set(r,best_rules) and int(examples[r_i].getclass())==int(r.classifier.default_value): 
     1798        for r_i, r in enumerate(self.best_rule): 
     1799            if r and not rule_in_set(r, best_rules) and int(examples[r_i].getclass()) == int(r.classifier.default_value): 
    17701800                if hasattr(r.learner, "arg_example"): 
    17711801                    setattr(r, "best_example", r.learner.arg_example) 
     
    17741804                best_rules.append(r) 
    17751805        return best_rules 
    1776          
     1806 
    17771807    def __call__(self, rule, examples, weights, target_class): 
    17781808        """ if example has an argument, then the rule must be consistent with the argument. """ 
     
    17821812                e[self.prob_attribute] = 1.0 
    17831813                self.best_rule[ei] = rule 
    1784             elif rule(e) and rule.quality>e[self.prob_attribute]: 
    1785                 e[self.prob_attribute] = rule.quality+0.001 # 0.001 is added to avoid numerical errors 
    1786                 self.best_rule[ei]=rule 
    1787         return (examples,weights) 
     1814            elif rule(e) and rule.quality > e[self.prob_attribute]: 
     1815                e[self.prob_attribute] = rule.quality + 0.001 # 0.001 is added to avoid numerical errors 
     1816                self.best_rule[ei] = rule 
     1817        return (examples, weights) 
    17881818 
    17891819    def filter_covers_example(self, example, filter): 
     
    17911821        if filter(example): 
    17921822            try: 
    1793                 if example[self.argument_id].value and len(example[self.argument_id].value.positive_arguments)>0: # example has positive arguments 
     1823                if example[self.argument_id].value and len(example[self.argument_id].value.positive_arguments) > 0: # example has positive arguments 
    17941824                    # conditions should cover at least one of the positive arguments 
    17951825                    one_arg_covered = False 
    17961826                    for pA in example[self.argument_id].value.positive_arguments: 
    1797                         arg_covered = [self.condIn(c,filter_indices) for c in pA.filter.conditions] 
     1827                        arg_covered = [self.condIn(c, filter_indices) for c in pA.filter.conditions] 
    17981828                        one_arg_covered = one_arg_covered or len(arg_covered) == sum(arg_covered) #arg_covered 
    17991829                        if one_arg_covered: 
     
    18011831                    if not one_arg_covered: 
    18021832                        return False 
    1803                 if example[self.argument_id].value and len(example[self.argument_id].value.negative_arguments)>0: # example has negative arguments 
     1833                if example[self.argument_id].value and len(example[self.argument_id].value.negative_arguments) > 0: # example has negative arguments 
    18041834                    # condition should not cover neither of negative arguments 
    18051835                    for pN in example[self.argument_id].value.negative_arguments: 
    18061836                        arg_covered = [self.condIn(c, filter_indices) for c in pN.filter.conditions] 
    1807                         if len(arg_covered)==sum(arg_covered): 
     1837                        if len(arg_covered) == sum(arg_covered): 
    18081838                            return False 
    18091839            except: 
     
    18141844    def condIn(self, cond, filter_indices): # is condition in the filter? 
    18151845        condInd = RuleCoversArguments.conditionIndex(cond) 
    1816         if operator.or_(condInd,filter_indices[cond.position]) == filter_indices[cond.position]: 
     1846        if operator.or_(condInd, filter_indices[cond.position]) == filter_indices[cond.position]: 
    18171847            return True 
    1818         return False         
     1848        return False 
    18191849 
    18201850 
     
    18221852        p = 0.0 
    18231853        for ei, e in enumerate(examples): 
    1824             p += (e[self.prob_attribute] - self.apriori_prob)/(1.0-self.apriori_prob) 
    1825         return p/len(examples) 
     1854            p += (e[self.prob_attribute] - self.apriori_prob) / (1.0 - self.apriori_prob) 
     1855        return p / len(examples) 
    18261856 
    18271857 
     
    18291859 
    18301860@deprecated_keywords({"showDistribution": "show_distribution"}) 
    1831 def rule_to_string(rule, show_distribution = True): 
     1861def rule_to_string(rule, show_distribution=True): 
    18321862    """ 
    18331863    Write a string presentation of rule in human readable format. 
     
    18561886    conds = rule.filter.conditions 
    18571887    domain = rule.filter.domain 
    1858      
     1888 
    18591889    ret = "IF " 
    1860     if len(conds)==0: 
     1890    if len(conds) == 0: 
    18611891        ret = ret + "TRUE" 
    18621892 
    1863     for i,c in enumerate(conds): 
     1893    for i, c in enumerate(conds): 
    18641894        if i > 0: 
    18651895            ret += " AND " 
     
    18711901    if rule.classifier and type(rule.classifier) == Orange.classification.ConstantClassifier\ 
    18721902            and rule.classifier.default_val: 
    1873         ret = ret + " THEN "+domain.class_var.name+"="+\ 
     1903        ret = ret + " THEN " + domain.class_var.name + "=" + \ 
    18741904        str(rule.classifier.default_value) 
    18751905        if show_distribution: 
     
    18771907    elif rule.classifier and type(rule.classifier) == Orange.classification.ConstantClassifier\ 
    18781908            and type(domain.class_var) == Orange.core.EnumVariable: 
    1879         ret = ret + " THEN "+domain.class_var.name+"="+\ 
     1909        ret = ret + " THEN " + domain.class_var.name + "=" + \ 
    18801910        str(rule.class_distribution.modus()) 
    18811911        if show_distribution: 
    18821912            ret += str(rule.class_distribution) 
    1883     return ret         
     1913    return ret 
    18841914 
    18851915def supervisedClassCheck(instances): 
     
    18881918    if instances.domain.class_var.varType == Orange.core.VarTypes.Continuous: 
    18891919        raise Exception("CN2 requires a discrete class!") 
    1890      
    1891  
    1892 def rule_in_set(rule,rules): 
     1920 
     1921 
     1922def rule_in_set(rule, rules): 
    18931923    for r in rules: 
    1894         if rules_equal(rule,r): 
     1924        if rules_equal(rule, r): 
    18951925            return True 
    18961926    return False 
    18971927 
    1898 def rules_equal(rule1,rule2): 
    1899     if not len(rule1.filter.conditions)==len(rule2.filter.conditions): 
     1928def rules_equal(rule1, rule2): 
     1929    if not len(rule1.filter.conditions) == len(rule2.filter.conditions): 
    19001930        return False 
    19011931    for c1 in rule1.filter.conditions: 
    1902         found=False # find the same condition in the other rule 
     1932        found = False # find the same condition in the other rule 
    19031933        for c2 in rule2.filter.conditions: 
    19041934            try: 
     
    19111941                    if not c1.oper == c2.oper: continue # same operator? 
    19121942                    if not c1.ref == c2.ref: continue #same threshold? 
    1913                 found=True 
     1943                found = True 
    19141944                break 
    19151945            except: 
     
    19211951# Miscellaneous - utility functions 
    19221952def avg(l): 
    1923     if len(l)==0: 
     1953    if len(l) == 0: 
    19241954        return 0. 
    1925     return sum(l)/len(l) 
     1955    return sum(l) / len(l) 
    19261956 
    19271957def var(l): 
    1928     if len(l)<2: 
     1958    if len(l) < 2: 
    19291959        return 0. 
    19301960    av = avg(l) 
    1931     vars=[math.pow(li-av,2) for li in l] 
    1932     return sum(vars)/(len(l)-1) 
     1961    vars = [math.pow(li - av, 2) for li in l] 
     1962    return sum(vars) / (len(l) - 1) 
    19331963 
    19341964def median(l): 
    1935     if len(l)==0: 
    1936         return 0.     
     1965    if len(l) == 0: 
     1966        return 0. 
    19371967    l.sort() 
    19381968    le = len(l) 
    1939     if le%2 == 1: 
    1940         return l[(le-1)/2] 
     1969    if le % 2 == 1: 
     1970        return l[(le - 1) / 2] 
    19411971    else: 
    1942         return (l[le/2-1]+l[le/2])/2 
    1943  
    1944 def perc(l,p): 
     1972        return (l[le / 2 - 1] + l[le / 2]) / 2 
     1973 
     1974def perc(l, p): 
    19451975    l.sort() 
    1946     return l[int(math.floor(p*len(l)))] 
     1976    return l[int(math.floor(p * len(l)))] 
    19471977 
    19481978class EVDFitter: 
     
    19551985        # initialize random seed to make experiments repeatable 
    19561986        random.seed(self.randomseed) 
    1957          
    1958          
     1987 
     1988 
    19591989    def createRandomDataSet(self, data): 
    19601990        newData = Orange.core.ExampleTable(data) 
    19611991        # shuffle data 
    19621992        cl_num = newData.toNumpy("C") 
    1963         random.shuffle(cl_num[0][:,0]) 
    1964         clData = Orange.core.ExampleTable(Orange.core.Domain([newData.domain.classVar]),cl_num[0]) 
    1965         for d_i,d in enumerate(newData): 
     1993        random.shuffle(cl_num[0][:, 0]) 
     1994        clData = Orange.core.ExampleTable(Orange.core.Domain([newData.domain.classVar]), cl_num[0]) 
     1995        for d_i, d in enumerate(newData): 
    19661996            d[newData.domain.classVar] = clData[d_i][newData.domain.classVar] 
    19671997        return newData 
     
    19702000        l = Orange.core.EVDistList() 
    19712001        for el in evdList: 
    1972             l.append(Orange.core.EVDist(mu=el[0],beta=el[1],percentiles=el[2])) 
     2002            l.append(Orange.core.EVDist(mu=el[0], beta=el[1], percentiles=el[2])) 
    19732003        return l 
    19742004 
    19752005 
    19762006    # estimated fisher tippett parameters for a set of values given in vals list (+ deciles) 
    1977     def compParameters(self, vals, oldMi, oldBeta, oldPercs, fixedBeta=False):                     
     2007    def compParameters(self, vals, oldMi, oldBeta, oldPercs, fixedBeta=False): 
    19782008        # compute percentiles 
    19792009        vals.sort() 
    19802010        N = len(vals) 
    1981         percs = [avg(vals[int(float(N)*i/10):int(float(N)*(i+1)/10)]) for i in range(10)] 
    1982         if N<10: 
     2011        percs = [avg(vals[int(float(N) * i / 10):int(float(N) * (i + 1) / 10)]) for i in range(10)] 
     2012        if N < 10: 
    19832013            return oldMi, oldBeta, percs 
    19842014        if not fixedBeta: 
    1985             beta = min(2.0, math.sqrt(6*var(vals)/math.pow(math.pi,2)))#min(2.0, max(oldBeta, math.sqrt(6*var(vals)/math.pow(math.pi,2)))) 
     2015            beta = min(2.0, math.sqrt(6 * var(vals) / math.pow(math.pi, 2)))#min(2.0, max(oldBeta, math.sqrt(6*var(vals)/math.pow(math.pi,2)))) 
    19862016        else: 
    19872017            beta = oldBeta 
    1988         mi = max(oldMi,percs[-1]+beta*math.log(-math.log(0.95))) 
    1989         mi = percs[-1]+beta*math.log(-math.log(0.95)) 
    1990         return max(oldMi, numpy.average(vals)-beta*0.5772156649), beta, None 
    1991      
     2018        mi = max(oldMi, percs[-1] + beta * math.log(-math.log(0.95))) 
     2019        mi = percs[-1] + beta * math.log(-math.log(0.95)) 
     2020        return max(oldMi, numpy.average(vals) - beta * 0.5772156649), beta, None 
     2021 
    19922022    def prepare_learner(self): 
    19932023        self.oldStopper = self.learner.ruleFinder.ruleStoppingValidator 
     
    20022032        self.learner.ruleFinder.ruleStoppingValidator.max_rule_complexity = 0 
    20032033        self.learner.ruleFinder.refiner = Orange.core.RuleBeamRefiner_Selector() 
    2004         self.learner.ruleFinder.ruleFilter = Orange.core.RuleBeamFilter_Width(width = 5) 
     2034        self.learner.ruleFinder.ruleFilter = Orange.core.RuleBeamFilter_Width(width=5) 
    20052035 
    20062036 
     
    20182048 
    20192049        # loop through N (sampling repetitions) 
    2020         extremeDists=[(0, 1, [])] 
     2050        extremeDists = [(0, 1, [])] 
    20212051        self.learner.ruleFinder.ruleStoppingValidator.max_rule_complexity = self.oldStopper.max_rule_complexity 
    2022         maxVals = [[] for l in range(self.oldStopper.max_rule_complexity+1)] 
     2052        maxVals = [[] for l in range(self.oldStopper.max_rule_complexity + 1)] 
    20232053        for d_i in range(self.n): 
    20242054            if not progress: 
     
    20262056                    print d_i, 
    20272057            else: 
    2028                 progress(float(d_i)/self.n, None)                 
     2058                progress(float(d_i) / self.n, None) 
    20292059            # create data set (remove and randomize) 
    20302060            a = time.time() 
     
    20332063            self.learner.ruleFinder.evaluator.rules = RuleList() 
    20342064            a = time.time() 
    2035             for l in range(self.oldStopper.max_rule_complexity+2): 
     2065            for l in range(self.oldStopper.max_rule_complexity + 2): 
    20362066               self.learner.ruleFinder.evaluator.rules.append(None) 
    20372067            a = time.time() 
    20382068            # Next, learn a rule 
    2039             self.learner.ruleFinder(tempData,weightID,target_class, RuleList()) 
     2069            self.learner.ruleFinder(tempData, weightID, target_class, RuleList()) 
    20402070            a = time.time() 
    2041             for l in range(self.oldStopper.max_rule_complexity+1): 
     2071            for l in range(self.oldStopper.max_rule_complexity + 1): 
    20422072                if self.learner.ruleFinder.evaluator.rules[l]: 
    20432073                    maxVals[l].append(self.learner.ruleFinder.evaluator.rules[l].quality) 
     
    20582088        for l in range(self.oldStopper.max_rule_complexity): 
    20592089            for i in range(len(maxVals[l])): 
    2060                 if maxVals[l+1][i] < maxVals[l][i]: 
    2061                     maxVals[l+1][i] = maxVals[l][i] 
     2090                if maxVals[l + 1][i] < maxVals[l][i]: 
     2091                    maxVals[l + 1][i] = maxVals[l][i] 
    20622092##        print 
    20632093##        for mi, m in enumerate(maxVals): 
    20642094##            print "mi=",mi,m 
    20652095 
    2066         mu, beta, perc = 1.0, 2.0, [0.0]*10 
    2067         for mi,m in enumerate(maxVals): 
     2096        mu, beta, perc = 1.0, 2.0, [0.0] * 10 
     2097        for mi, m in enumerate(maxVals): 
    20682098##            if mi == 0: 
    20692099##                mu, beta, perc = self.compParameters(m, mu, beta, perc) 
     
    20712101            mu, beta, perc = self.compParameters(m, mu, beta, perc, fixedBeta=True) 
    20722102            extremeDists.append((mu, beta, perc)) 
    2073             extremeDists.extend([(0,1,[])]*(mi)) 
     2103            extremeDists.extend([(0, 1, [])] * (mi)) 
    20742104            if self.learner.debug: 
    20752105                print mi, mu, beta, perc 
     
    20772107        self.restore_learner() 
    20782108        return self.createEVDistList(extremeDists) 
    2079          
     2109 
    20802110class ABBeamFilter(Orange.core.RuleBeamFilter): 
    20812111    """ 
     
    20842114        - leaves first N rules that have only of arguments in condition part 
    20852115    """ 
    2086     def __init__(self,width=5): 
    2087         self.width=width 
    2088         self.pArgs=None 
    2089  
    2090     def __call__(self,rulesStar,examples,weight_id): 
    2091         newStar=Orange.core.RuleList() 
    2092         rulesStar.sort(lambda x,y: -cmp(x.quality,y.quality)) 
    2093         argsNum=0 
    2094         for r_i,r in enumerate(rulesStar): 
    2095             if r_i<self.width: # either is one of best "width" rules 
     2116    def __init__(self, width=5): 
     2117        self.width = width 
     2118        self.pArgs = None 
     2119 
     2120    def __call__(self, rulesStar, examples, weight_id): 
     2121        newStar = Orange.core.RuleList() 
     2122        rulesStar.sort(lambda x, y:-cmp(x.quality, y.quality)) 
     2123        argsNum = 0 
     2124        for r_i, r in enumerate(rulesStar): 
     2125            if r_i < self.width: # either is one of best "width" rules 
    20962126                newStar.append(r) 
    20972127            elif self.onlyPositives(r): 
    2098                 if argsNum<self.width: 
     2128                if argsNum < self.width: 
    20992129                    newStar.append(r) 
    2100                     argsNum+=1 
    2101         return newStar                 
    2102  
    2103     def setArguments(self,domain,positive_arguments): 
     2130                    argsNum += 1 
     2131        return newStar 
     2132 
     2133    def setArguments(self, domain, positive_arguments): 
    21042134        self.pArgs = positive_arguments 
    21052135        self.domain = domain 
    2106         self.argTab = [0]*len(self.domain.attributes) 
     2136        self.argTab = [0] * len(self.domain.attributes) 
    21072137        for arg in self.pArgs: 
    21082138            for cond in arg.filter.conditions: 
    2109                 self.argTab[cond.position]=1 
    2110          
    2111     def onlyPositives(self,rule): 
     2139                self.argTab[cond.position] = 1 
     2140 
     2141    def onlyPositives(self, rule): 
    21122142        if not self.pArgs: 
    21132143            return False 
    21142144 
    2115         ruleTab=[0]*len(self.domain.attributes) 
     2145        ruleTab = [0] * len(self.domain.attributes) 
    21162146        for cond in rule.filter.conditions: 
    2117             ruleTab[cond.position]=1 
    2118         return map(operator.or_,ruleTab,self.argTab)==self.argTab 
     2147            ruleTab[cond.position] = 1 
     2148        return map(operator.or_, ruleTab, self.argTab) == self.argTab 
    21192149 
    21202150 
     
    21272157        self.indices = [] 
    21282158        for a in self.arguments: 
    2129             indNA = getattr(a.filter,"indices",None) 
     2159            indNA = getattr(a.filter, "indices", None) 
    21302160            if not indNA: 
    21312161                a.filter.setattr("indices", RuleCoversArguments.filterIndices(a.filter)) 
     
    21352165        if not self.indices: 
    21362166            return False 
    2137         if not getattr(rule.filter,"indices",None): 
     2167        if not getattr(rule.filter, "indices", None): 
    21382168            rule.filter.indices = RuleCoversArguments.filterIndices(rule.filter) 
    21392169        for index in self.indices: 
    2140             if map(operator.or_,rule.filter.indices,index) == rule.filter.indices: 
     2170            if map(operator.or_, rule.filter.indices, index) == rule.filter.indices: 
    21412171                return True 
    21422172        return False 
     
    21452175        if not filter.domain: 
    21462176            return [] 
    2147         ind = [0]*len(filter.domain.attributes) 
     2177        ind = [0] * len(filter.domain.attributes) 
    21482178        for c in filter.conditions: 
    2149             ind[c.position]=operator.or_(ind[c.position], 
     2179            ind[c.position] = operator.or_(ind[c.position], 
    21502180                                         RuleCoversArguments.conditionIndex(c)) 
    21512181        return ind 
     
    21642194        else: 
    21652195            return 1 # 0001 
    2166     conditionIndex = staticmethod(conditionIndex)         
     2196    conditionIndex = staticmethod(conditionIndex) 
    21672197 
    21682198    def oneSelectorToCover(ruleIndices, argIndices): 
     
    21712201            if not argIndices[r_i]: 
    21722202                continue 
    2173             if at>-1 and not ind == argIndices[r_i]: # need two changes 
    2174                 return (-1,0) 
     2203            if at > -1 and not ind == argIndices[r_i]: # need two changes 
     2204                return (-1, 0) 
    21752205            if not ind == argIndices[r_i]: 
    2176                 if argIndices[r_i] in [1,3,5]: 
    2177                     at,type=r_i,argIndices[r_i] 
    2178                 if argIndices[r_i]==6: 
    2179                     if ind==3: 
    2180                         at,type=r_i,5 
    2181                     if ind==5: 
    2182                         at,type=r_i,3 
    2183         return at,type 
     2206                if argIndices[r_i] in [1, 3, 5]: 
     2207                    at, type = r_i, argIndices[r_i] 
     2208                if argIndices[r_i] == 6: 
     2209                    if ind == 3: 
     2210                        at, type = r_i, 5 
     2211                    if ind == 5: 
     2212                        at, type = r_i, 3 
     2213        return at, type 
    21842214    oneSelectorToCover = staticmethod(oneSelectorToCover) 
    21852215 
     
    21902220       - refined rules are not consistent with any of negative arguments. 
    21912221    """ 
    2192     def __init__(self, example=None, not_allowed_selectors=[], argument_id = None, 
    2193                  discretizer = Orange.core.EntropyDiscretization(forceAttribute=True)): 
     2222    def __init__(self, example=None, not_allowed_selectors=[], argument_id=None, 
     2223                 discretizer=Orange.core.EntropyDiscretization(forceAttribute=True)): 
    21942224        # required values - needed values of attributes 
    21952225        self.example = example 
     
    21972227        self.not_allowed_selectors = not_allowed_selectors 
    21982228        self.discretizer = discretizer 
    2199          
    2200     def __call__(self, oldRule, data, weight_id, target_class=-1): 
     2229 
     2230    def __call__(self, oldRule, data, weight_id, target_class= -1): 
    22012231        inNotAllowedSelectors = RuleCoversArguments(self.not_allowed_selectors) 
    22022232        new_rules = Orange.core.RuleList() 
    22032233 
    22042234        # get positive indices (selectors already in the rule) 
    2205         indices = getattr(oldRule.filter,"indices",None) 
     2235        indices = getattr(oldRule.filter, "indices", None) 
    22062236        if not indices: 
    22072237            indices = RuleCoversArguments.filterIndices(oldRule.filter) 
    2208             oldRule.filter.setattr("indices",indices) 
     2238            oldRule.filter.setattr("indices", indices) 
    22092239 
    22102240        # get negative indices (selectors that should not be in the rule) 
    2211         negative_indices = [0]*len(data.domain.attributes) 
     2241        negative_indices = [0] * len(data.domain.attributes) 
    22122242        for nA in self.not_allowed_selectors: 
    22132243            #print indices, nA.filter.indices 
    2214             at_i,type_na = RuleCoversArguments.oneSelectorToCover(indices, nA.filter.indices) 
    2215             if at_i>-1: 
    2216                 negative_indices[at_i] = operator.or_(negative_indices[at_i],type_na) 
     2244            at_i, type_na = RuleCoversArguments.oneSelectorToCover(indices, nA.filter.indices) 
     2245            if at_i > -1: 
     2246                negative_indices[at_i] = operator.or_(negative_indices[at_i], type_na) 
    22172247 
    22182248        #iterate through indices = attributes  
    2219         for i,ind in enumerate(indices): 
     2249        for i, ind in enumerate(indices): 
    22202250            if not self.example[i] or self.example[i].isSpecial(): 
    22212251                continue 
    2222             if ind == 1:  
     2252            if ind == 1: 
    22232253                continue 
    2224             if data.domain[i].varType == Orange.core.VarTypes.Discrete and not negative_indices[i]==1: # DISCRETE attribute 
     2254            if data.domain[i].varType == Orange.core.VarTypes.Discrete and not negative_indices[i] == 1: # DISCRETE attribute 
    22252255                if self.example: 
    22262256                    values = [self.example[i]] 
     
    22292259                for v in values: 
    22302260                    tempRule = oldRule.clone() 
    2231                     tempRule.filter.conditions.append(Orange.core.ValueFilter_discrete(position = i, 
    2232                                                                                   values = [Orange.core.Value(data.domain[i],v)], 
     2261                    tempRule.filter.conditions.append(Orange.core.ValueFilter_discrete(position=i, 
     2262                                                                                  values=[Orange.core.Value(data.domain[i], v)], 
    22332263                                                                                  acceptSpecial=0)) 
    22342264                    tempRule.complexity += 1 
    22352265                    tempRule.filter.indices[i] = 1 # 1 stands for discrete attribute (see RuleCoversArguments.conditionIndex) 
    22362266                    tempRule.filterAndStore(oldRule.examples, oldRule.weightID, target_class) 
    2237                     if len(tempRule.examples)<len(oldRule.examples): 
     2267                    if len(tempRule.examples) < len(oldRule.examples): 
    22382268                        new_rules.append(tempRule) 
    2239             elif data.domain[i].varType == Orange.core.VarTypes.Continuous and not negative_indices[i]==7: # CONTINUOUS attribute 
     2269            elif data.domain[i].varType == Orange.core.VarTypes.Continuous and not negative_indices[i] == 7: # CONTINUOUS attribute 
    22402270                try: 
    22412271                    at = data.domain[i] 
    2242                     at_d = self.discretizer(at,oldRule.examples) 
     2272                    at_d = self.discretizer(at, oldRule.examples) 
    22432273                except: 
    22442274                    continue # discretization failed ! 
    22452275                # If discretization makes sense? then: 
    2246                 if len(at_d.values)>1: 
     2276                if len(at_d.values) > 1: 
    22472277                    for p in at_d.getValueFrom.transformer.points: 
    22482278                        #LESS 
    2249                         if not negative_indices[i]==3: 
    2250                             tempRule = self.getTempRule(oldRule,i,Orange.core.ValueFilter_continuous.LessEqual,p,target_class,3) 
    2251                             if len(tempRule.examples)<len(oldRule.examples) and self.example[i]<=p:# and not inNotAllowedSelectors(tempRule): 
     2279                        if not negative_indices[i] == 3: 
     2280                            tempRule = self.getTempRule(oldRule, i, Orange.core.ValueFilter_continuous.LessEqual, p, target_class, 3) 
     2281                            if len(tempRule.examples) < len(oldRule.examples) and self.example[i] <= p:# and not inNotAllowedSelectors(tempRule): 
    22522282                                new_rules.append(tempRule) 
    22532283                        #GREATER 
    2254                         if not negative_indices[i]==5: 
    2255                             tempRule = self.getTempRule(oldRule,i,Orange.core.ValueFilter_continuous.Greater,p,target_class,5) 
    2256                             if len(tempRule.examples)<len(oldRule.examples) and self.example[i]>p:# and not inNotAllowedSelectors(tempRule): 
     2284                        if not negative_indices[i] == 5: 
     2285                            tempRule = self.getTempRule(oldRule, i, Orange.core.ValueFilter_continuous.Greater, p, target_class, 5) 
     2286                            if len(tempRule.examples) < len(oldRule.examples) and self.example[i] > p:# and not inNotAllowedSelectors(tempRule): 
    22572287                                new_rules.append(tempRule) 
    22582288        for r in new_rules: 
     
    22612291        return new_rules 
    22622292 
    2263     def getTempRule(self,oldRule,pos,oper,ref,target_class,atIndex): 
     2293    def getTempRule(self, oldRule, pos, oper, ref, target_class, atIndex): 
    22642294        tempRule = oldRule.clone() 
    22652295 
     
    22692299                                                                        acceptSpecial=0)) 
    22702300        tempRule.complexity += 1 
    2271         tempRule.filter.indices[pos] = operator.or_(tempRule.filter.indices[pos],atIndex) # from RuleCoversArguments.conditionIndex 
    2272         tempRule.filterAndStore(oldRule.examples,tempRule.weightID,target_class) 
     2301        tempRule.filter.indices[pos] = operator.or_(tempRule.filter.indices[pos], atIndex) # from RuleCoversArguments.conditionIndex 
     2302        tempRule.filterAndStore(oldRule.examples, tempRule.weightID, target_class) 
    22732303        return tempRule 
    22742304 
     
    22762306        tempRule = oldRule.clone() 
    22772307        tempRule.filter.conditions[ci] = condition 
    2278         tempRule.filter.conditions[ci].setattr("specialized",1) 
    2279         tempRule.filterAndStore(oldRule.examples,oldRule.weightID,target_class) 
     2308        tempRule.filter.conditions[ci].setattr("specialized", 1) 
     2309        tempRule.filterAndStore(oldRule.examples, oldRule.weightID, target_class) 
    22802310        return tempRule 
    22812311 
     
    22872317class ArgFilter(Orange.core.Filter): 
    22882318    """ This class implements AB-covering principle. """ 
    2289     def __init__(self, argument_id=None, filter = Orange.core.Filter_values(), arg_example = None): 
     2319    def __init__(self, argument_id=None, filter=Orange.core.Filter_values(), arg_example=None): 
    22902320        self.filter = filter 
    2291         self.indices = getattr(filter,"indices",[]) 
    2292         if not self.indices and len(filter.conditions)>0: 
     2321        self.indices = getattr(filter, "indices", []) 
     2322        if not self.indices and len(filter.conditions) > 0: 
    22932323            self.indices = RuleCoversArguments.filterIndices(filter) 
    22942324        self.argument_id = argument_id 
     
    22962326        self.conditions = filter.conditions 
    22972327        self.arg_example = arg_example 
    2298          
    2299     def condIn(self,cond): # is condition in the filter? 
     2328 
     2329    def condIn(self, cond): # is condition in the filter? 
    23002330        condInd = ruleCoversArguments.conditionIndex(cond) 
    2301         if operator.or_(condInd,self.indices[cond.position]) == self.indices[cond.position]: 
     2331        if operator.or_(condInd, self.indices[cond.position]) == self.indices[cond.position]: 
    23022332            return True 
    23032333        return False 
    2304      
    2305     def __call__(self,example): 
     2334 
     2335    def __call__(self, example): 
    23062336##        print "in", self.filter(example)#, self.filter.conditions[0](example) 
    23072337##        print self.filter.conditions[1].values 
     
    23102340        elif self.filter(example): 
    23112341            try: 
    2312                 if example[self.argument_id].value and len(example[self.argument_id].value.positiveArguments)>0: # example has positive arguments 
     2342                if example[self.argument_id].value and len(example[self.argument_id].value.positiveArguments) > 0: # example has positive arguments 
    23132343                    # conditions should cover at least one of the positive arguments 
    23142344                    oneArgCovered = False 
     
    23202350                    if not oneArgCovered: 
    23212351                        return False 
    2322                 if example[self.argument_id].value and len(example[self.argument_id].value.negativeArguments)>0: # example has negative arguments 
     2352                if example[self.argument_id].value and len(example[self.argument_id].value.negativeArguments) > 0: # example has negative arguments 
    23232353                    # condition should not cover neither of negative arguments 
    23242354                    for pN in example[self.argument_id].value.negativeArguments: 
    23252355                        argCovered = [self.condIn(c) for c in pN.filter.conditions] 
    2326                         if len(argCovered)==sum(argCovered): 
     2356                        if len(argCovered) == sum(argCovered): 
    23272357                            return False 
    23282358            except: 
     
    23322362            return False 
    23332363 
    2334     def __setattr__(self,name,obj): 
    2335         self.__dict__[name]=obj 
    2336         self.filter.setattr(name,obj) 
     2364    def __setattr__(self, name, obj): 
     2365        self.__dict__[name] = obj 
     2366        self.filter.setattr(name, obj) 
    23372367 
    23382368    def deep_copy(self): 
     
    23602390        self.allowed_selectors = allowed_selectors 
    23612391 
    2362     def __call__(self, oldRule, data, weight_id, target_class=-1): 
     2392    def __call__(self, oldRule, data, weight_id, target_class= -1): 
    23632393        if len(oldRule.filter.conditions) >= len(self.allowed_selectors): 
    23642394            return Orange.core.RuleList() 
     
    23702400                tempRule.filter.conditions.append(c) 
    23712401                tempRule.filterAndStore(oldRule.examples, oldRule.weightID, target_class) 
    2372                 if len(tempRule.examples)<len(oldRule.examples): 
     2402                if len(tempRule.examples) < len(oldRule.examples): 
    23732403                    new_rules.append(tempRule) 
    23742404            # unspecified condition 
     
    23892419                    if tempRule(self.example): 
    23902420                        tempRule.filterAndStore(oldRule.examples, oldRule.weightID, target_class) 
    2391                         if len(tempRule.examples)<len(oldRule.examples): 
     2421                        if len(tempRule.examples) < len(oldRule.examples): 
    23922422                            new_rules.append(tempRule) 
    23932423##        print " NEW RULES " 
     
    24012431 
    24022432class CrossValidation: 
    2403     def __init__(self, folds=5, random_generator = 150): 
     2433    def __init__(self, folds=5, random_generator=150): 
    24042434        self.folds = folds 
    24052435        self.random_generator = random_generator 
    24062436 
    24072437    def __call__(self, learner, examples, weight): 
    2408         res = orngTest.crossValidation([learner], (examples, weight), folds = self.folds, random_generator = self.random_generator) 
     2438        res = orngTest.crossValidation([learner], (examples, weight), folds=self.folds, random_generator=self.random_generator) 
    24092439        return self.get_prob_from_res(res, examples) 
    24102440 
     
    24232453    PILAR (Probabilistic improvement of learning algorithms with rules). 
    24242454    """ 
    2425     def __init__(self, alternative_learner = None, min_cl_sig = 0.5, min_beta = 0.0, set_prefix_rules = False, optimize_betas = True): 
     2455    def __init__(self, alternative_learner=None, min_cl_sig=0.5, min_beta=0.0, set_prefix_rules=False, optimize_betas=True): 
    24262456        self.alternative_learner = alternative_learner 
    24272457        self.min_cl_sig = min_cl_sig 
     
    24352465        if self.alternative_learner: 
    24362466            prob_dist = self.selected_evaluation(self.alternative_learner, examples, weight) 
    2437             classifier = self.alternative_learner(examples,weight) 
     2467            classifier = self.alternative_learner(examples, weight) 
    24382468##            prob_dist = Orange.core.DistributionList() 
    24392469##            for e in examples: 
     
    24442474 
    24452475##        print "result" 
    2446         for ri,r in enumerate(cl.rules): 
    2447             cl.rules[ri].setattr("beta",cl.ruleBetas[ri]) 
     2476        for ri, r in enumerate(cl.rules): 
     2477            cl.rules[ri].setattr("beta", cl.ruleBetas[ri]) 
    24482478##            if cl.ruleBetas[ri] > 0: 
    24492479##                print Orange.classification.rules.rule_to_string(r), r.quality, cl.ruleBetas[ri] 
     
    24572487        for cl in examples.domain.class_var: 
    24582488            tmpRle = Orange.core.Rule() 
    2459             tmpRle.filter = Orange.core.Filter_values(domain = examples.domain) 
     2489            tmpRle.filter = Orange.core.Filter_values(domain=examples.domain) 
    24602490            tmpRle.parentRule = None 
    2461             tmpRle.filterAndStore(examples,weight,int(cl)) 
    2462             tmpRle.quality = tmpRle.class_distribution[int(cl)]/tmpRle.class_distribution.abs 
     2491            tmpRle.filterAndStore(examples, weight, int(cl)) 
     2492            tmpRle.quality = tmpRle.class_distribution[int(cl)] / tmpRle.class_distribution.abs 
    24632493            rules.append(tmpRle) 
    24642494        return rules 
    2465          
     2495 
    24662496    def sort_rules(self, rules): 
    24672497        new_rules = Orange.core.RuleList() 
     
    24832513                    foundRule = True 
    24842514                    continue 
    2485                 if len(r.filter.conditions) ==  len(bestRule.filter.conditions) and r.beta > bestRule.beta: 
     2515                if len(r.filter.conditions) == len(bestRule.filter.conditions) and r.beta > bestRule.beta: 
    24862516                    bestRule = r 
    24872517                    foundRule = True 
     
    24992529    normalizes probabilities. 
    25002530    """ 
    2501     def __init__(self, rules, examples, weight_id = 0, **argkw): 
     2531    def __init__(self, rules, examples, weight_id=0, **argkw): 
    25022532        self.rules = rules 
    25032533        self.examples = examples 
    2504         self.apriori = Orange.core.Distribution(examples.domain.class_var,examples,weight_id) 
    2505         self.apriori_prob = [a/self.apriori.abs for a in self.apriori] 
     2534        self.apriori = Orange.core.Distribution(examples.domain.class_var, examples, weight_id) 
     2535        self.apriori_prob = [a / self.apriori.abs for a in self.apriori] 
    25062536        self.weight_id = weight_id 
    25072537        self.__dict__.update(argkw) 
     
    25092539 
    25102540    @deprecated_keywords({"retRules": "ret_rules"}) 
    2511     def __call__(self, example, result_type=Orange.classification.Classifier.GetValue, ret_rules = False): 
    2512         example = Orange.core.Example(self.examples.domain,example) 
     2541    def __call__(self, example, result_type=Orange.classification.Classifier.GetValue, ret_rules=False): 
     2542        example = Orange.core.Example(self.examples.domain, example) 
    25132543        tempDist = Orange.core.Distribution(example.domain.class_var) 
    2514         best_rules = [None]*len(example.domain.class_var.values) 
     2544        best_rules = [None] * len(example.domain.class_var.values) 
    25152545 
    25162546        for r in self.rules: 
    25172547            if r(example) and not self.default_class_index == int(r.classifier.default_val) and \ 
    2518                (not best_rules[int(r.classifier.default_val)] or r.quality>tempDist[r.classifier.default_val]): 
     2548               (not best_rules[int(r.classifier.default_val)] or r.quality > tempDist[r.classifier.default_val]): 
    25192549                tempDist[r.classifier.default_val] = r.quality 
    25202550                best_rules[int(r.classifier.default_val)] = r 
    25212551        for b in best_rules: 
    25222552            if b: 
    2523                 used = getattr(b,"used",0.0) 
    2524                 b.setattr("used",used+1) 
     2553                used = getattr(b, "used", 0.0) 
     2554                b.setattr("used", used + 1) 
    25252555        nonCovPriorSum = sum([tempDist[i] == 0. and self.apriori_prob[i] or 0. for i in range(len(self.apriori_prob))]) 
    25262556        if tempDist.abs < 1.: 
    25272557            residue = 1. - tempDist.abs 
    2528             for a_i,a in enumerate(self.apriori_prob): 
     2558            for a_i, a in enumerate(self.apriori_prob): 
    25292559                if tempDist[a_i] == 0.: 
    2530                     tempDist[a_i]=self.apriori_prob[a_i]*residue/nonCovPriorSum 
     2560                    tempDist[a_i] = self.apriori_prob[a_i] * residue / nonCovPriorSum 
    25312561            final_dist = tempDist #Orange.core.Distribution(example.domain.class_var) 
    25322562        else: 
     
    25362566                if r: 
    25372567                    tmp_examples = r.filter(tmp_examples) 
    2538             tmpDist = Orange.core.Distribution(tmp_examples.domain.class_var,tmp_examples,self.weight_id) 
     2568            tmpDist = Orange.core.Distribution(tmp_examples.domain.class_var, tmp_examples, self.weight_id) 
    25392569            tmpDist.normalize() 
    2540             probs = [0.]*len(self.examples.domain.class_var.values) 
     2570            probs = [0.] * len(self.examples.domain.class_var.values) 
    25412571            for i in range(len(self.examples.domain.class_var.values)): 
    2542                 probs[i] = tmpDist[i]+tempDist[i]*2 
     2572                probs[i] = tmpDist[i] + tempDist[i] * 2 
    25432573            final_dist = Orange.core.Distribution(self.examples.domain.class_var) 
    2544             for cl_i,cl in enumerate(self.examples.domain.class_var): 
     2574            for cl_i, cl in enumerate(self.examples.domain.class_var): 
    25452575                final_dist[cl] = probs[cl_i] 
    25462576            final_dist.normalize() 
    2547                  
     2577 
    25482578        if ret_rules: # Do you want to return rules with classification? 
    25492579            if result_type == Orange.classification.Classifier.GetValue: 
    2550               return (final_dist.modus(),best_rules) 
     2580              return (final_dist.modus(), best_rules) 
    25512581            if result_type == Orange.core.GetProbabilities: 
    25522582              return (final_dist, best_rules) 
    2553             return (final_dist.modus(),final_dist, best_rules) 
     2583            return (final_dist.modus(), final_dist, best_rules) 
    25542584        if result_type == Orange.classification.Classifier.GetValue: 
    25552585          return final_dist.modus() 
    25562586        if result_type == Orange.core.GetProbabilities: 
    25572587          return final_dist 
    2558         return (final_dist.modus(),final_dist) 
    2559      
     2588        return (final_dist.modus(), final_dist) 
     2589 
    25602590RuleClassifier_bestRule = deprecated_members({"defaultClassIndex": "default_class_index"})(RuleClassifier_bestRule) 
  • Orange/clustering/__init__.py

    r9671 r9725  
    1414import orange 
    1515import random 
    16 import statc 
     16from Orange import statc 
    1717     
    1818__docformat__ = 'restructuredtext' 
  • Orange/clustering/kmeans.py

    r9724 r9725  
    120120import orange 
    121121import random 
    122 import statc 
     122from Orange import statc 
    123123 
    124124import Orange.clustering.hierarchical 
  • Orange/data/variable.py

    r9671 r9727  
    1 """ 
    2 ======================== 
    3 Variables (``variable``) 
    4 ======================== 
    5  
    6 Data instances in Orange can contain several types of variables: 
    7 :ref:`discrete <discrete>`, :ref:`continuous <continuous>`, 
    8 :ref:`strings <string>`, and :ref:`Python <Python>` and types derived from it. 
    9 The latter represent arbitrary Python objects. 
    10 The names, types, values (where applicable), functions for computing the 
    11 variable value from values of other variables, and other properties of the 
    12 variables are stored in descriptor classes defined in this module. 
    13  
    14 Variable descriptors 
    15 -------------------- 
    16  
    17 Variable descriptors can be constructed either directly, using  
    18 constructors and passing attributes as parameters, or by a  
    19 factory function :func:`Orange.data.variable.make`, which either  
    20 retrieves an existing descriptor or constructs a new one. 
    21  
    22 .. class:: Variable 
    23  
    24     An abstract base class for variable descriptors. 
    25  
    26     .. attribute:: name 
    27  
    28         The name of the variable. Variable names do not need to be unique since two 
    29         variables are considered the same only if they have the same descriptor 
    30         (e.g. even multiple variables in the same table can have the same name). 
    31         This should, however, be avoided since it may result in unpredictable 
    32         behavior. 
    33      
    34     .. attribute:: var_type 
    35         
    36         Variable type; it can be Orange.data.Type.Discrete, 
    37         Orange.data.Type.Continuous, Orange.data.Type.String or 
    38         Orange.data.Type.Other.   
    39  
    40     .. attribute:: get_value_from 
    41  
    42         A function (an instance of :obj:`Orange.classification.Classifier`) which computes 
    43         a value of the variable from values of one or more other variables. This 
    44         is used, for instance, in discretization where the variables describing 
    45         the discretized variable are computed from the original variable.  
    46  
    47     .. attribute:: ordered 
    48      
    49         A flag telling whether the values of a discrete variable are ordered. At 
    50         the moment, no built-in method treats ordinal variables differently than 
    51         nominal ones. 
    52      
    53     .. attribute:: distributed 
    54      
    55         A flag telling whether the values of the variables are distributions. 
    56         As for the flag ordered, no methods treat such variables in any special 
    57         manner. 
    58      
    59     .. attribute:: random_generator 
    60      
    61         A local random number generator used by method 
    62         :obj:`Variable.random_value`. 
    63      
    64     .. attribute:: default_meta_id 
    65      
    66         A proposed (but not guaranteed) meta id to be used for that variable. 
    67         This is used, for instance, by the data loader for tab-delimited file 
    68         format instead of assigning an arbitrary new value, or by 
    69         :obj:`Orange.data.new_meta_id` if the variable is passed as an argument.  
    70          
    71     .. attribute:: attributes 
    72          
    73         A dictionary which allows the user to store additional information 
    74         about the variable. All values should be strings. See the section  
    75         about :ref:`storing additional information <attributes>`. 
    76  
    77     .. method:: __call__(obj) 
    78      
    79            Convert a string, number, or other suitable object into a variable 
    80            value. 
    81             
    82            :param obj: An object to be converted into a variable value 
    83            :type o: any suitable 
    84            :rtype: :class:`Orange.data.Value` 
    85         
    86     .. method:: randomvalue() 
    87  
    88            Return a random value for the variable. 
    89         
    90            :rtype: :class:`Orange.data.Value` 
    91         
    92     .. method:: compute_value(inst) 
    93  
    94            Compute the value of the variable given the instance by calling 
    95            obj:`~Variable.get_value_from` through a mechanism that prevents deadlocks by 
    96            circular calls. 
    97  
    98            :rtype: :class:`Orange.data.Value` 
    99  
    100 .. _discrete: 
    101 .. class:: Discrete 
    102  
    103     Bases: :class:`Variable` 
    104     
    105     Descriptor for discrete variables. 
    106      
    107     .. attribute:: values 
    108      
    109         A list with symbolic names for variables' values. Values are stored as 
    110         indices referring to this list. Therefore, modifying this list  
    111         instantly changes the (symbolic) names of values as they are printed out or 
    112         referred to by user. 
    113      
    114         .. note:: 
    115          
    116             The size of the list is also used to indicate the number of 
    117             possible values for this variable. Changing the size - especially 
    118             shrinking the list - can have disastrous effects and is therefore not 
    119             really recommended. Also, do not add values to the list by 
    120             calling its append or extend method: call the :obj:`add_value` 
    121             method instead. 
    122  
    123             It is also assumed that this attribute is always defined (but can 
    124             be empty), so never set it to None. 
    125      
    126     .. attribute:: base_value 
    127  
    128             Stores the base value for the variable as an index in `values`. 
    129             This can be, for instance, a "normal" value, such as "no 
    130             complications" as opposed to abnormal "low blood pressure". The 
    131             base value is used by certain statistics, continuization etc. 
    132             potentially, learning algorithms. The default is -1 which means that 
    133             there is no base value. 
    134      
    135     .. method:: add_value 
    136      
    137             Add a value to values. Always call this function instead of 
    138             appending to values. 
    139  
    140 .. _continuous: 
    141 .. class:: Continuous 
    142  
    143     Bases: :class:`Variable` 
    144  
    145     Descriptor for continuous variables. 
    146      
    147     .. attribute:: number_of_decimals 
    148      
    149         The number of decimals used when the value is printed out, converted to 
    150         a string or saved to a file. 
    151      
    152     .. attribute:: scientific_format 
    153      
    154         If ``True``, the value is printed in scientific format whenever it 
    155         would have more than 5 digits. In this case, :obj:`number_of_decimals` is 
    156         ignored. 
    157  
    158     .. attribute:: adjust_decimals 
    159      
    160         Tells Orange to monitor the number of decimals when the value is 
    161         converted from a string (when the values are read from a file or 
    162         converted by, e.g. ``inst[0]="3.14"``):  
    163         0: the number of decimals is not adjusted automatically; 
    164         1: the number of decimals is (and has already) been adjusted; 
    165         2: automatic adjustment is enabled, but no values have been converted yet. 
    166  
    167         By default, adjustment of the number of decimals goes as follows: 
    168      
    169         If the variable was constructed when data was read from a file, it will  
    170         be printed with the same number of decimals as the largest number of  
    171         decimals encountered in the file. If scientific notation occurs in the  
    172         file, :obj:`scientific_format` will be set to ``True`` and scientific format  
    173         will be used for values too large or too small.  
    174      
    175         If the variable is created in a script, it will have, by default, three 
    176         decimal places. This can be changed either by setting the value 
    177         from a string (e.g. ``inst[0]="3.14"``, but not ``inst[0]=3.14``) or by 
    178         manually setting the :obj:`number_of_decimals`. 
    179  
    180     .. attribute:: start_value, end_value, step_value 
    181      
    182         The range used for :obj:`randomvalue`. 
    183  
    184 .. _String: 
    185 .. class:: String 
    186  
    187     Bases: :class:`Variable` 
    188  
    189     Descriptor for variables that contain strings. No method can use them for  
    190     learning; some will complain and others will silently ignore them when they  
    191     encounter them. They can be, however, useful for meta-attributes; if  
    192     instances in a dataset have unique IDs, the most efficient way to store them  
    193     is to read them as meta-attributes. In general, never use discrete  
    194     attributes with many (say, more than 50) values. Such attributes are  
    195     probably not of any use for learning and should be stored as string 
    196     attributes. 
    197  
    198     When converting strings into values and back, empty strings are treated  
    199     differently than usual. For other types, an empty string can be used to 
    200     denote undefined values, while :obj:`String` will take empty strings 
    201     as empty strings -- except when loading or saving into file. 
    202     Empty strings in files are interpreted as undefined; to specify an empty 
    203     string, enclose the string in double quotes; these are removed when the 
    204     string is loaded. 
    205  
    206 .. _Python: 
    207 .. class:: Python 
    208  
    209     Bases: :class:`Variable` 
    210  
    211     Base class for descriptors defined in Python. It is fully functional 
    212     and can be used as a descriptor for attributes that contain arbitrary Python 
    213     values. Since this is an advanced topic, PythonVariables are described on a  
    214     separate page. !!TODO!! 
    215      
    216      
    217 Variables computed from other variables 
    218 --------------------------------------- 
    219  
    220 Values of variables are often computed from other variables, such as in 
    221 discretization. The mechanism described below usually functions behind the scenes, 
    222 so understanding it is required only for implementing specific transformations. 
    223  
    224 Monk 1 is a well-known dataset with target concept ``y := a==b or e==1``. 
    225 It can help the learning algorithm if the four-valued attribute ``e`` is 
    226 replaced with a binary attribute having values `"1"` and `"not 1"`. The 
    227 new variable will be computed from the old one on the fly.  
    228  
    229 .. literalinclude:: code/variable-get_value_from.py 
    230     :lines: 7-17 
    231      
    232 The new variable is named ``e2``; we define it with a descriptor of type  
    233 :obj:`Discrete`, with appropriate name and values ``"not 1"`` and ``1`` (we  
    234 chose this order so that the ``not 1``'s index is ``0``, which can be, if  
    235 needed, interpreted as ``False``). Finally, we tell e2 to use  
    236 ``checkE`` to compute its value when needed, by assigning ``checkE`` to  
    237 ``e2.get_value_from``.  
    238  
    239 ``checkE`` is a function that is passed an instance and another argument we  
    240 do not care about here. If the instance's ``e`` equals ``1``, the function  
    241 returns value ``1``, otherwise it returns ``not 1``. Both are returned as  
    242 values, not plain strings. 
    243  
    244 In most circumstances the value of ``e2`` can be computed on the fly - we can  
    245 pretend that the variable exists in the data, although it does not (but  
    246 can be computed from it). For instance, we can compute the information gain of 
    247 variable ``e2`` or its distribution without actually constructing data containing 
    248 the new variable. 
    249  
    250 .. literalinclude:: code/variable-get_value_from.py 
    251     :lines: 19-22 
    252  
    253 There are methods which cannot compute values on the fly because it would be 
    254 too complex or time consuming. In such cases, the data need to be converted 
    255 to a new :obj:`Orange.data.Table`:: 
    256  
    257     new_domain = Orange.data.Domain([data.domain["a"], data.domain["b"], e2, data.domain.class_var]) 
    258     new_data = Orange.data.Table(new_domain, data)  
    259  
    260 Automatic computation is useful when the data is split into training and  
    261 testing examples. Training instances can be modified by adding, removing  
    262 and transforming variables (in a typical setup, continuous variables  
    263 are discretized prior to learning, therefore the original variables are  
    264 replaced by new ones). Test instances, on the other hand, are left as they  
    265 are. When they are classified, the classifier automatically converts the  
    266 testing instances into the new domain, which includes recomputation of  
    267 transformed variables.  
    268  
    269 .. literalinclude:: code/variable-get_value_from.py 
    270     :lines: 24- 
    271  
    272 .. _attributes: 
    273  
    274 Storing additional variables 
    275 ----------------------------- 
    276  
    277 All variables have a field :obj:`~Variable.attributes`, a dictionary 
    278 which can contain strings. Although the current implementation allows all 
    279 types of value we strongly advise to use only strings. An example: 
    280  
    281 .. literalinclude:: code/attributes.py 
    282  
    283 These attributes can only be saved to a .tab file. They are listed in the 
    284 third line in <name>=<value> format, after other attribute specifications 
    285 (such as "meta" or "class"), and are separated by spaces.  
    286  
    287 .. _variable_descriptor_reuse: 
    288  
    289 Reuse of descriptors 
    290 -------------------- 
    291  
    292 There are situations when variable descriptors need to be reused. Typically, the  
    293 user loads some training examples, trains a classifier, and then loads a separate 
    294 test set. For the classifier to recognize the variables in the second data set, 
    295 the descriptors, not just the names, need to be the same.  
    296  
    297 When constructing new descriptors for data read from a file or during unpickling, 
    298 Orange checks whether an appropriate descriptor (with the same name and, in case 
    299 of discrete variables, also values) already exists and reuses it. When new 
    300 descriptors are constructed by explicitly calling the above constructors, this 
    301 always creates new descriptors and thus new variables, although a variable with 
    302 the same name may already exist. 
    303  
    304 The search for an existing variable is based on four attributes: the variable's name, 
    305 type, ordered values, and unordered values. As for the latter two, the values can  
    306 be explicitly ordered by the user, e.g. in the second line of the tab-delimited  
    307 file. For instance, sizes can be ordered as small, medium, or big. 
    308  
    309 The search for existing variables can end with one of the following statuses. 
    310  
    311 .. data:: Orange.data.variable.MakeStatus.NotFound (4) 
    312  
    313     The variable with that name and type does not exist.  
    314  
    315 .. data:: Orange.data.variable.MakeStatus.Incompatible (3) 
    316  
    317     There are variables with matching name and type, but their 
    318     values are incompatible with the prescribed ordered values. For example, 
    319     if the existing variable already has values ["a", "b"] and the new one 
    320     wants ["b", "a"], the old variable cannot be reused. The existing list can, 
    321     however be appended with the new values, so searching for ["a", "b", "c"] would 
    322     succeed. Likewise a search for ["a"] would be successful, since the extra existing value 
    323     does not matter. The formal rule is thus that the values are compatible iff ``existing_values[:len(ordered_values)] == ordered_values[:len(existing_values)]``. 
    324  
    325 .. data:: Orange.data.variable.MakeStatus.NoRecognizedValues (2) 
    326  
    327     There is a matching variable, yet it has none of the values that the new 
    328     variable will have (this is obviously possible only if the new variable has 
    329     no prescribed ordered values). For instance, we search for a variable 
    330     "sex" with values "male" and "female", while there is a variable of the same  
    331     name with values "M" and "F" (or, well, "no" and "yes" :). Reuse of this  
    332     variable is possible, though this should probably be a new variable since it  
    333     obviously comes from a different data set. If we do decide to reuse the variable, the  
    334     old variable will get some unneeded new values and the new one will inherit  
    335     some from the old. 
    336  
    337 .. data:: Orange.data.variable.MakeStatus.MissingValues (1) 
    338  
    339     There is a matching variable with some of the values that the new one  
    340     requires, but some values are missing. This situation is neither uncommon  
    341     nor suspicious: in case of separate training and testing data sets there may 
    342     be values which occur in one set but not in the other. 
    343  
    344 .. data:: Orange.data.variable.MakeStatus.OK (0) 
    345  
    346     There is a perfect match which contains all the prescribed values in the 
    347     correct order. The existing variable may have some extra values, though. 
    348  
    349 Continuous variables can obviously have only two statuses,  
    350 :obj:`~Orange.data.variable.MakeStatus.NotFound` or :obj:`~Orange.data.variable.MakeStatus.OK`. 
    351  
    352 When loading the data using :obj:`Orange.data.Table`, Orange takes the safest  
    353 approach and, by default, reuses everything that is compatible up to  
    354 and including :obj:`~Orange.data.variable.MakeStatus.NoRecognizedValues`. Unintended reuse would be obvious from the 
    355 variable having too many values, which the user can notice and fix. More on that  
    356 in the page on `loading data`. !!TODO!! 
    357  
    358 There are two functions for reusing the variables instead of creating new ones. 
    359  
    360 .. function:: Orange.data.variable.make(name, type, ordered_values, unordered_values[, create_new_on]) 
    361  
    362     Find and return an existing variable or create a new one if none of the existing 
    363     variables matches the given name, type and values. 
    364      
    365     The optional `create_new_on` specifies the status at which a new variable is 
    366     created. The status must be at most :obj:`~Orange.data.variable.MakeStatus.Incompatible` since incompatible (or 
    367     non-existing) variables cannot be reused. If it is set lower, for instance  
    368     to :obj:`~Orange.data.variable.MakeStatus.MissingValues`, a new variable is created even if there exists 
    369     a variable which is only missing the same values. If set to :obj:`~Orange.data.variable.MakeStatus.OK`, the function 
    370     always creates a new variable. 
    371      
    372     The function returns a tuple containing a variable descriptor and the 
    373     status of the best matching variable. So, if ``create_new_on`` is set to 
    374     :obj:`~Orange.data.variable.MakeStatus.MissingValues`, and there exists a variable whose status is, say, 
    375     :obj:`~Orange.data.variable.MakeStatus.NoRecognizedValues`, a variable would be created, while the second  
    376     element of the tuple would contain :obj:`~Orange.data.variable.MakeStatus.NoRecognizedValues`. If, on the other 
    377     hand, there exists a variable which is perfectly OK, its descriptor is  
    378     returned and the returned status is :obj:`~Orange.data.variable.MakeStatus.OK`. The function returns no  
    379     indicator whether the returned variable is reused or not. This can be, 
    380     however, read from the status code: if it is smaller than the specified 
    381     ``create_new_on``, the variable is reused, otherwise a new descriptor has been constructed. 
    382  
    383     The exception to the rule is when ``create_new_on`` is OK. In this case, the  
    384     function does not search through the existing variables and cannot know the  
    385     status, so the returned status in this case is always :obj:`~Orange.data.variable.MakeStatus.OK`. 
    386  
    387     :param name: Variable name 
    388     :param type: Variable type 
    389     :type type: Orange.data.variable.Type 
    390     :param ordered_values: a list of ordered values 
    391     :param unordered_values: a list of values, for which the order does not 
    392         matter 
    393     :param create_new_on: gives the condition for constructing a new variable instead 
    394         of using the new one 
    395      
    396     :return_type: a tuple (:class:`Orange.data.variable.Variable`, int) 
    397      
    398 .. function:: Orange.data.variable.retrieve(name, type, ordered_values, onordered_values[, create_new_on]) 
    399  
    400     Find and return an existing variable, or :obj:`None` if no match is found. 
    401      
    402     :param name: variable name. 
    403     :param type: variable type. 
    404     :type type: Orange.data.variable.Type 
    405     :param ordered_values: a list of ordered values 
    406     :param unordered_values: a list of values, for which the order does not 
    407         matter 
    408     :param create_new_on: gives the condition for constructing a new variable instead 
    409         of using the new one 
    410  
    411     :return_type: :class:`Orange.data.variable.Variable` 
    412      
    413 These following examples (from :download:`variable-reuse.py <code/variable-reuse.py>`) give the shown results if 
    414 executed only once (in a Python session) and in this order. 
    415  
    416 :func:`Orange.data.variable.make` can be used for the construction of new variables. :: 
    417      
    418     >>> v1, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, ["a", "b"]) 
    419     >>> print s, v1.values 
    420     4 <a, b> 
    421  
    422 No surprises here: a new variable is created and the status is :obj:`~Orange.data.variable.MakeStatus.NotFound`. :: 
    423  
    424     >>> v2, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, ["a"], ["c"]) 
    425     >>> print s, v2 is v1, v1.values 
    426     1 True <a, b, c> 
    427  
    428 The status is 1 (:obj:`~Orange.data.variable.MakeStatus.MissingValues`), yet the variable is reused (``v2 is v1``). 
    429 ``v1`` gets a new value, ``"c"``, which was given as an unordered value. It does 
    430 not matter that the new variable does not need the value ``b``. :: 
    431  
    432     >>> v3, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, ["a", "b", "c", "d"]) 
    433     >>> print s, v3 is v1, v1.values 
    434     1 True <a, b, c, d> 
    435  
    436 This is like before, except that the new value, ``d`` is not among the 
    437 ordered values. :: 
    438  
    439     >>> v4, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, ["b"]) 
    440     >>> print s, v4 is v1, v1.values, v4.values 
    441     3, False, <b>, <a, b, c, d> 
    442  
    443 The new variable needs to have ``b`` as the first value, so it is incompatible  
    444 with the existing variables. The status is thus 3 (:obj:`~Orange.data.variable.MakeStatus.Incompatible`), the two  
    445 variables are not equal and have different lists of values. :: 
    446  
    447     >>> v5, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, None, ["c", "a"]) 
    448     >>> print s, v5 is v1, v1.values, v5.values 
    449     0 True <a, b, c, d> <a, b, c, d> 
    450  
    451 The new variable has values ``c`` and ``a``, but the order is not important,  
    452 so the existing attribute is :obj:`~Orange.data.variable.MakeStatus.OK`. :: 
    453  
    454     >>> v6, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, None, ["e"]) "a"]) 
    455     >>> print s, v6 is v1, v1.values, v6.values 
    456     2 True <a, b, c, d, e> <a, b, c, d, e> 
    457  
    458 The new variable has different values than the existing variable (status is 2, 
    459 :obj:`~Orange.data.variable.MakeStatus.NoRecognizedValues`), but the existing one is nonetheless reused. Note that we 
    460 gave ``e`` in the list of unordered values. If it was among the ordered, the 
    461 reuse would fail. :: 
    462  
    463     >>> v7, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, None, 
    464             ["f"], Orange.data.variable.MakeStatus.NoRecognizedValues))) 
    465     >>> print s, v7 is v1, v1.values, v7.values 
    466     2 False <a, b, c, d, e> <f> 
    467  
    468 This is the same as before, except that we prohibited reuse when there are no 
    469 recognized values. Hence a new variable is created, though the returned status is  
    470 the same as before:: 
    471  
    472     >>> v8, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, 
    473             ["a", "b", "c", "d", "e"], None, Orange.data.variable.MakeStatus.OK) 
    474     >>> print s, v8 is v1, v1.values, v8.values 
    475     0 False <a, b, c, d, e> <a, b, c, d, e> 
    476  
    477 Finally, this is a perfect match, but any reuse is prohibited, so a new  
    478 variable is created. 
    479  
    480 """ 
    4811from orange import Variable 
    4822from orange import EnumVariable as Discrete 
  • Orange/distance/__init__.py

    r9752 r9753  
    2020    ExamplesDistanceConstructor_Relief as Relief 
    2121 
     22<<<<<<< local 
     23from Orange import statc 
     24======= 
    2225from Orange.misc import progress_bar_milestones 
    2326 
    2427import statc 
     28>>>>>>> other 
    2529import numpy 
    2630from numpy import linalg 
  • Orange/ensemble/bagging.py

    r9671 r9733  
    3030            :class:`Orange.ensemble.bagging.BaggedLearner` 
    3131    """ 
    32     def __new__(cls, learner, instances=None, weightId=None, **kwargs): 
     32    def __new__(cls, learner, instances=None, weight_id=None, **kwargs): 
    3333        self = orange.Learner.__new__(cls, **kwargs) 
    3434        if instances is not None: 
    3535            self.__init__(self, learner, **kwargs) 
    36             return self.__call__(instances, weightId) 
     36            return self.__call__(instances, weight_id) 
    3737        else: 
    3838            return self 
     
    6767            classifiers.append(self.learner(data, weight)) 
    6868        return BaggedClassifier(classifiers = classifiers, name=self.name,\ 
    69                     classVar=instances.domain.classVar) 
     69                    class_var=instances.domain.class_var) 
     70BaggedLearner = Orange.misc.deprecated_members({"weightId":"weight_id", "examples":"instances"})(BaggedLearner) 
    7071 
    7172class BaggedClassifier(orange.Classifier): 
     
    8485    :type name: str 
    8586     
    86     :param classVar: the class feature. 
    87     :type classVar: :class:`Orange.data.variable.Variable` 
     87    :param class_var: the class feature. 
     88    :type class_var: :class:`Orange.data.variable.Variable` 
    8889 
    8990    """ 
    9091 
    91     def __init__(self, classifiers, name, classVar, **kwds): 
     92    def __init__(self, classifiers, name, class_var, **kwds): 
    9293        self.classifiers = classifiers 
    9394        self.name = name 
    94         self.classVar = classVar 
     95        self.class_var = class_var 
    9596        self.__dict__.update(kwds) 
    9697 
    97     def __call__(self, instance, resultType = orange.GetValue): 
     98    def __call__(self, instance, result_type = orange.GetValue): 
    9899        """ 
    99100        :param instance: instance to be classified. 
     
    107108              :class:`Orange.statistics.Distribution` or a tuple with both 
    108109        """ 
    109         if self.classVar.varType == Orange.data.Type.Discrete: 
    110             freq = [0.] * len(self.classVar.values) 
     110        if self.class_var.var_type == Orange.data.Type.Discrete: 
     111            freq = [0.] * len(self.class_var.values) 
    111112            for c in self.classifiers: 
    112113                freq[int(c(instance))] += 1 
    113114            index = freq.index(max(freq)) 
    114             value = Orange.data.Value(self.classVar, index) 
    115             if resultType == orange.GetValue: 
     115            value = Orange.data.Value(self.class_var, index) 
     116            if result_type == orange.GetValue: 
    116117                return value 
    117118            for i in range(len(freq)): 
    118119                freq[i] = freq[i]/len(self.classifiers) 
    119120            freq = Orange.statistics.distribution.Discrete(freq) 
    120             if resultType == orange.GetProbabilities: 
     121            if result_type == orange.GetProbabilities: 
    121122                return freq 
    122             elif resultType == orange.GetBoth: 
     123            elif result_type == orange.GetBoth: 
    123124                return (value, freq) 
    124125            else: 
    125126                return value 
    126127             
    127         elif self.classVar.varType ==Orange.data.Type.Continuous: 
    128             votes = [c(instance, orange.GetBoth if resultType==\ 
    129                 orange.GetProbabilities else resultType) \ 
     128        elif self.class_var.var_type ==Orange.data.Type.Continuous: 
     129            votes = [c(instance, orange.GetBoth if result_type==\ 
     130                orange.GetProbabilities else result_type) \ 
    130131                for c in self.classifiers] 
    131132            wsum = float(len(self.classifiers)) 
    132             if resultType in [orange.GetBoth, orange.GetProbabilities]: 
     133            if result_type in [orange.GetBoth, orange.GetProbabilities]: 
    133134                pred = sum([float(c) for c, p in votes]) / wsum 
    134135#               prob = sum([float(p.modus()) for c, p in votes]) / wsum 
     
    140141                     
    141142                prob = Orange.statistics.distribution.Continuous(prob) 
    142                 return (self.classVar(pred), prob) if resultType == orange.GetBoth\ 
     143                return (self.class_var(pred), prob) if result_type == orange.GetBoth\ 
    143144                    else prob 
    144             elif resultType == orange.GetValue: 
     145            elif result_type == orange.GetValue: 
    145146                pred = sum([float(c) for c in votes]) / wsum 
    146                 return self.classVar(pred) 
     147                return self.class_var(pred) 
    147148             
    148149    def __reduce__(self): 
    149         return type(self), (self.classifiers, self.name, self.classVar), dict(self.__dict__) 
    150      
     150        return type(self), (self.classifiers, self.name, self.class_var), dict(self.__dict__) 
     151BaggedClassifier = Orange.misc.deprecated_members({"example":"instance", "classVar":"class_var","resultType":"result_type"})(BaggedClassifier) 
  • Orange/ensemble/boosting.py

    r9671 r9733  
    2727            :class:`Orange.ensemble.boosting.BoostedLearner` 
    2828    """ 
    29     def __new__(cls, learner, instances=None, weightId=None, **kwargs): 
     29    def __new__(cls, learner, instances=None, weight_id=None, **kwargs): 
    3030        self = orange.Learner.__new__(cls, **kwargs) 
    3131        if instances is not None: 
    3232            self.__init__(self, learner, **kwargs) 
    33             return self.__call__(instances, weightId) 
     33            return self.__call__(instances, weight_id) 
    3434        else: 
    3535            return self 
     
    4040        self.learner = learner 
    4141 
    42     def __call__(self, instances, origWeight = 0): 
     42    def __call__(self, instances, orig_weight = 0): 
    4343        """ 
    4444        Learn from the given table of data instances. 
     
    4646        :param instances: data instances to learn from. 
    4747        :type instances: Orange.data.Table 
    48         :param origWeight: weight. 
    49         :type origWeight: int 
     48        :param orig_weight: weight. 
     49        :type orig_weight: int 
    5050        :rtype: :class:`Orange.ensemble.boosting.BoostedClassifier` 
    5151         
     
    5353        import math 
    5454        weight = Orange.data.new_meta_id() 
    55         if origWeight: 
     55        if orig_weight: 
    5656            for i in instances: 
    57                 i.setweight(weight, i.getweight(origWeight)) 
     57                i.setweight(weight, i.getweight(orig_weight)) 
    5858        else: 
    5959            instances.addMetaAttribute(weight, 1.0) 
     
    8080                instances.removeMetaAttribute(weight) 
    8181                return BoostedClassifier(classifiers = classifiers,  
    82                     name=self.name, classVar=instances.domain.classVar) 
     82                    name=self.name, class_var=instances.domain.class_var) 
    8383            beta = epsilon/(1-epsilon) 
    8484            for e in range(n): 
     
    9191        instances.removeMetaAttribute(weight) 
    9292        return BoostedClassifier(classifiers = classifiers, name=self.name,  
    93             classVar=instances.domain.classVar) 
     93            class_var=instances.domain.class_var) 
     94BoostedLearner = Orange.misc.deprecated_members({"examples":"instances", "classVar":"class_var", "weightId":"weigth_id", "origWeight":"orig_weight"})(BoostedLearner) 
    9495 
    9596class BoostedClassifier(orange.Classifier): 
     
    108109    :type name: str 
    109110     
    110     :param classVar: the class feature. 
    111     :type classVar: :class:`Orange.data.variable.Variable` 
     111    :param class_var: the class feature. 
     112    :type class_var: :class:`Orange.data.variable.Variable` 
    112113     
    113114    """ 
    114115 
    115     def __init__(self, classifiers, name, classVar, **kwds): 
     116    def __init__(self, classifiers, name, class_var, **kwds): 
    116117        self.classifiers = classifiers 
    117118        self.name = name 
    118         self.classVar = classVar 
     119        self.class_var = class_var 
    119120        self.__dict__.update(kwds) 
    120121 
    121     def __call__(self, instance, resultType = orange.GetValue): 
     122    def __call__(self, instance, result_type = orange.GetValue): 
    122123        """ 
    123124        :param instance: instance to be classified. 
     
    131132              :class:`Orange.statistics.Distribution` or a tuple with both 
    132133        """ 
    133         votes = Orange.statistics.distribution.Discrete(self.classVar) 
     134        votes = Orange.statistics.distribution.Discrete(self.class_var) 
    134135        for c, e in self.classifiers: 
    135136            votes[int(c(instance))] += e 
    136         index = Orange.misc.selection.selectBestIndex(votes) 
     137        index = Orange.misc.selection.select_best_index(votes) 
    137138        # TODO 
    138         value = Orange.data.Value(self.classVar, index) 
    139         if resultType == orange.GetValue: 
     139        value = Orange.data.Value(self.class_var, index) 
     140        if result_type == orange.GetValue: 
    140141            return value 
    141142        sv = sum(votes) 
    142143        for i in range(len(votes)): 
    143144            votes[i] = votes[i]/sv 
    144         if resultType == orange.GetProbabilities: 
     145        if result_type == orange.GetProbabilities: 
    145146            return votes 
    146         elif resultType == orange.GetBoth: 
     147        elif result_type == orange.GetBoth: 
    147148            return (value, votes) 
    148149        else: 
     
    150151         
    151152    def __reduce__(self): 
    152         return type(self), (self.classifiers, self.name, self.classVar), dict(self.__dict__) 
    153      
     153        return type(self), (self.classifiers, self.name, self.class_var), dict(self.__dict__) 
     154 
     155BoostedClassifier = Orange.misc.deprecated_members({"classVar":"class_var", "resultType":"result_type"})(BoostedClassifier) 
  • Orange/ensemble/forest.py

    r9697 r9733  
    55import random 
    66import copy 
     7from Orange.misc import deprecated_keywords 
    78 
    89def _default_small_learner(attributes=None, rand=None, base=None): 
     
    2930  
    3031class _RandomForestSimpleTreeLearner(Orange.core.Learner): 
    31     """ A learner which wraps an ordinary SimpleTreeLearner.  Sets the 
     32    """A learner which wraps an ordinary SimpleTreeLearner.  Sets the 
    3233    skip_prob so that the number of randomly chosen features for each 
    33     split is  (on average) as specified.  """ 
    34  
    35     def __new__(cls, examples = None, weightID = 0, **argkw): 
     34    split is  (on average) as specified.""" 
     35 
     36    def __new__(cls, instances = None, weight_id = 0, **argkw): 
    3637        self = Orange.core.Learner.__new__(cls, **argkw) 
    37         if examples: 
     38        if instances: 
    3839            self.__init__(**argkw) 
    39             return self.__call__(examples, weightID) 
     40            return self.__call__(instances, weight_id) 
    4041        else: 
    4142            return self 
     
    4647        self.rand = rand 
    4748     
    48     def __call__(self, examples, weight=0): 
     49    def __call__(self, instances, weight=0): 
    4950        osp,orand = self.base.skip_prob, self.base.random_generator 
    50         self.base.skip_prob = 1-float(self.attributes)/len(examples.domain.attributes) 
     51        self.base.skip_prob = 1-float(self.attributes)/len(instances.domain.attributes) 
    5152        self.base.random_generator = self.rand 
    52         r = self.base(examples, weight) 
     53        r = self.base(instances, weight) 
    5354        self.base.skip_prob, self.base.random_generator = osp, orand 
    5455        return r 
     56_RandomForestSimpleTreeLearner = Orange.misc.deprecated_members({"weightID":"weight_id", "examples":"instances"})(_RandomForestSimpleTreeLearner) 
    5557    
    5658class RandomForestLearner(orange.Learner): 
     
    170172        return RandomForestClassifier(classifiers = classifiers, name=self.name,\ 
    171173                    domain=instances.domain, class_var=instances.domain.class_var) 
    172   
     174RandomForestLearner = Orange.misc.deprecated_members({"examples":"instances"})(RandomForestLearner) 
    173175 
    174176class RandomForestClassifier(orange.Classifier): 
     
    202204        self.__dict__.update(kwds) 
    203205 
    204     def __call__(self, instance, resultType = orange.GetValue): 
     206    def __call__(self, instance, result_type = orange.GetValue): 
    205207        """ 
    206208        :param instance: instance to be classified. 
     
    221223         
    222224            # voting for class probabilities 
    223             if resultType == orange.GetProbabilities or resultType == orange.GetBoth: 
     225            if result_type == orange.GetProbabilities or result_type == orange.GetBoth: 
    224226                prob = [0.] * len(self.domain.class_var.values) 
    225227                for c in self.classifiers: 
     
    234236            # this may not be the same class as one obtaining the 
    235237            # highest probability through probability voting 
    236             if resultType == orange.GetValue or resultType == orange.GetBoth: 
     238            if result_type == orange.GetValue or result_type == orange.GetBoth: 
    237239                cfreq = [0] * len(self.domain.class_var.values) 
    238240                for c in self.classifiers: 
     
    241243                cvalue = Orange.data.Value(self.domain.class_var, index) 
    242244     
    243             if resultType == orange.GetValue: return cvalue 
    244             elif resultType == orange.GetProbabilities: return cprob 
     245            if result_type == orange.GetValue: return cvalue 
     246            elif result_type == orange.GetProbabilities: return cprob 
    245247            else: return (cvalue, cprob) 
    246248         
     
    249251         
    250252            # voting for class probabilities 
    251             if resultType == orange.GetProbabilities or resultType == orange.GetBoth: 
     253            if result_type == orange.GetProbabilities or result_type == orange.GetBoth: 
    252254                probs = [c(instance, orange.GetBoth) for c in self.classifiers] 
    253255                cprob = dict() 
     
    262264                 
    263265            # gather average class value 
    264             if resultType == orange.GetValue or resultType == orange.GetBoth: 
     266            if result_type == orange.GetValue or result_type == orange.GetBoth: 
    265267                values = [c(instance).value for c in self.classifiers] 
    266268                cvalue = Orange.data.Value(self.domain.class_var, sum(values) / len(self.classifiers)) 
    267269             
    268             if resultType == orange.GetValue: return cvalue 
    269             elif resultType == orange.GetProbabilities: return cprob 
     270            if result_type == orange.GetValue: return cvalue 
     271            elif result_type == orange.GetProbabilities: return cprob 
    270272            else: return (cvalue, cprob) 
    271273             
    272274    def __reduce__(self): 
    273275        return type(self), (self.classifiers, self.name, self.domain, self.class_var), dict(self.__dict__) 
    274  
     276RandomForestClassifier = Orange.misc.deprecated_members({"resultType":"result_type", "classVar":"class_var", "example":"instance"})(RandomForestClassifier) 
    275277### MeasureAttribute_randomForests 
    276278 
     
    326328        else: 
    327329            self.learner = learner 
    328    
    329     def __call__(self, feature, instances, apriorClass=None): 
     330 
     331    @deprecated_keywords({"apriorClass":"aprior_class"}) 
     332    def __call__(self, feature, instances, aprior_class=None): 
    330333        """ 
    331334        Return importance of a given feature. 
     
    339342        :type instances: :class:`Orange.data.Table` 
    340343         
    341         :param apriorClass: not used! 
     344        :param aprior_class: not used! 
    342345         
    343346        """ 
     
    354357        else: 
    355358          raise Exception("MeasureAttribute_rf can not be called with (\ 
    356                 contingency,classDistribution, apriorClass) as fuction arguments.") 
     359                contingency,classDistribution, aprior_class) as fuction arguments.") 
    357360 
    358361        self._buffer(instances) 
     
    482485    a new split constructor. 
    483486    """ 
    484  
    485     def __new__(cls, examples = None, weightID = 0, **argkw): 
     487    @deprecated_keywords({"weightID":"weight_id", "examples":"instances"}) 
     488    def __new__(cls, instances = None, weight_id = 0, **argkw): 
    486489        self = Orange.core.Learner.__new__(cls, **argkw) 
    487         if examples: 
     490        if instances: 
    488491            self.__init__(**argkw) 
    489             return self.__call__(examples, weightID) 
     492            return self.__call__(instances, weight_id) 
    490493        else: 
    491494            return self 
     
    497500        if not self.rand: #for all the built trees 
    498501            self.rand = random.Random(0) 
    499      
    500     def __call__(self, examples, weight=0): 
     502 
     503    @deprecated_keywords({"examples":"instances"}) 
     504    def __call__(self, instances, weight=0): 
    501505        """ A current tree learner is copied, modified and then used. 
    502506        Modification: set a different split constructor, which uses 
     
    508512        if not bcopy.measure: 
    509513            bcopy.measure = Orange.feature.scoring.Gini() \ 
    510                 if isinstance(examples.domain.class_var, Orange.data.variable.Discrete) \ 
     514                if isinstance(instances.domain.class_var, Orange.data.variable.Discrete) \ 
    511515                else Orange.feature.scoring.MSE() 
    512516 
     
    514518            bcopy.split, self.attributes, self.rand) 
    515519 
    516         return bcopy(examples, weight=weight) 
     520        return bcopy(instances, weight=weight) 
    517521 
    518522class SplitConstructor_AttributeSubset(orange.TreeSplitConstructor): 
     
    524528            self.rand = random.Random(0) 
    525529 
    526     def __call__(self, gen, weightID, contingencies, apriori, candidates, clsfr): 
     530    @deprecated_keywords({"weightID":"weight_id"}) 
     531    def __call__(self, gen, weight_id, contingencies, apriori, candidates, clsfr): 
    527532        # if number of features for subset is not set, use square root 
    528533        cand = [1]*int(self.attributes) + [0]*(len(candidates) - int(self.attributes)) 
     
    530535        # instead with all features, we will invoke split constructor  
    531536        # only for the subset of a features 
    532         t = self.scons(gen, weightID, contingencies, apriori, cand, clsfr) 
     537        t = self.scons(gen, weight_id, contingencies, apriori, cand, clsfr) 
    533538        return t 
  • Orange/evaluation/reliability.py

    r9724 r9725  
    22 
    33import random 
    4 import statc 
     4from Orange import statc 
    55import math 
    66import warnings 
  • Orange/evaluation/scoring.py

    r9671 r9725  
    449449""" 
    450450 
    451 import statc, operator, math 
     451import operator, math 
    452452from operator import add 
    453453import numpy 
    454454 
    455455import Orange 
     456from Orange import statc 
    456457 
    457458 
  • Orange/misc/environ.py

    r9691 r9725  
    277277def add_orange_directories_to_path(): 
    278278    """Add orange directory paths to sys.path.""" 
     279 
     280    return 
    279281    paths_to_add = [install_dir] 
    280282 
  • Orange/misc/selection.py

    r9671 r9732  
    103103     
    104104    def __init__(self, compare=cmp, seed = 0, call_compare_on_1st = False): 
    105         self.randomGenerator = random.Random(seed) 
     105        self.randomGenerator = random.RandomGenerator(seed) 
    106106        self.compare=compare 
    107107        self.wins=0 
     
    134134            elif cmpr==0: 
    135135                self.wins=self.wins+1 
    136                 if not self.randomGenerator.randint(0, self.wins-1): 
     136                if not self.randomGenerator(self.wins): 
    137137                    self.best=x 
    138138                    self.bestIndex=self.index 
  • Orange/misc/visfuncts.py

    r9706 r9725  
    1 import orange, statc, random 
     1import orange, random 
    22from Orange.feature import scoring 
    33from Orange.misc import progress_bar_milestones 
     4from Orange import statc 
    45import copy 
    56from math import ceil 
  • Orange/orng/orngABML.py

    r9671 r9737  
    99import math 
    1010 
     11from Orange.classification.rules import create_dichotomous_class as createDichotomousClass 
     12from Orange.classification.rules import ConvertClass 
    1113# regular expressions 
    1214# exppression for testing validity of a set of arguments: 
     
    4244    else: 
    4345        if leave_ref: 
    44             return str(domain[arg.position].name)+strSign(arg.oper) 
     46            return str(domain[arg.position].name) + strSign(arg.oper) 
    4547        else: 
    46             return str(domain[arg.position].name)+strSign(arg.oper)+str(arg.ref) 
    47              
    48 def listOfAttributeNames(rule, leave_ref = False): 
     48            return str(domain[arg.position].name) + strSign(arg.oper) + str(arg.ref) 
     49 
     50def listOfAttributeNames(rule, leave_ref=False): 
    4951    if not rule.filter.conditions: 
    5052        return "" 
     
    5658    list += strArg(rule.filter.conditions[-1], rule.filter.domain, lr) 
    5759    return list 
    58          
    59      
     60 
     61 
    6062class Argumentation: 
    6163    """ Class that describes a set of positive and negative arguments 
     
    6668        self.not_yet_computed_arguments = [] # Arguments that need the whole data set 
    6769                                          # when processing are stored here  
    68      
     70 
    6971    # add an argument that supports the class of the example 
    7072    def addPositive(self, argument): 
     
    7678 
    7779    def addNotYetComputed(self, argument, notyet, positive): 
    78         self.not_yet_computed_arguments.append((argument,notyet,positive)) 
     80        self.not_yet_computed_arguments.append((argument, notyet, positive)) 
    7981 
    8082    def __str__(self): 
     
    8284        # iterate through positive arguments (rules) and 
    8385        # write them down as a text list 
    84         if len(self.positive_arguments)>0: 
    85             for (i,pos) in enumerate(self.positive_arguments[:-1]): 
    86                 retValue+="{"+listOfAttributeNames(pos)+"}" 
    87                 retValue+="," 
    88             retValue+="{"+listOfAttributeNames(self.positive_arguments[-1])+"}" 
     86        if len(self.positive_arguments) > 0: 
     87            for (i, pos) in enumerate(self.positive_arguments[:-1]): 
     88                retValue += "{" + listOfAttributeNames(pos) + "}" 
     89                retValue += "," 
     90            retValue += "{" + listOfAttributeNames(self.positive_arguments[-1]) + "}" 
    8991            # do the same thing for negative argument, 
    9092            # just that this time use sign "~" in front of the list 
    91         if len(self.negative_arguments)>0: 
    92             if len(retValue)>0: 
     93        if len(self.negative_arguments) > 0: 
     94            if len(retValue) > 0: 
    9395                retValue += "," 
    94             for (i,neg) in enumerate(self.negative_arguments[:-1]): 
    95                 retValue+="~" 
    96                 retValue+="{"+listOfAttributeNames(neg,leave_ref=True)+"}" 
    97                 retValue+="," 
    98             retValue+="~{"+listOfAttributeNames(self.negative_arguments[-1],leave_ref=True)+"}" 
     96            for (i, neg) in enumerate(self.negative_arguments[:-1]): 
     97                retValue += "~" 
     98                retValue += "{" + listOfAttributeNames(neg, leave_ref=True) + "}" 
     99                retValue += "," 
     100            retValue += "~{" + listOfAttributeNames(self.negative_arguments[-1], leave_ref=True) + "}" 
    99101        return retValue 
    100102 
     
    106108        """ convert str to val - used for creating variables. """ 
    107109        return self.filestr2val(strV, None) 
    108      
     110 
    109111    def filestr2val(self, strV, example=None): 
    110112        """ write arguments (from string in file) to value - used also as a function for reading from data. """ 
    111113        mt = testVal.match(strV) 
    112114        if not mt or not mt.end() == len(strV): 
    113             warnings.warn(strV+" is a badly formed argument.") 
     115            warnings.warn(strV + " is a badly formed argument.") 
    114116            return Orange.core.PythonValueSpecial(2) # return special if argument doesnt match the formal form  
    115117 
     
    119121 
    120122        # get a set of arguments 
    121         splitedSet = filter(lambda x:x!='' and x!='"', argRE.split(strV)) 
     123        splitedSet = filter(lambda x:x != '' and x != '"', argRE.split(strV)) 
    122124 
    123125        # create an Argumentation object - an empty set of arguments 
     
    130132                continue 
    131133            argument = Orange.core.Rule(filter=Orange.core.Filter_values(domain=domain)) 
    132             argument.setattr("unspecialized_argument",False) 
    133              
    134             reasonValues = filter(lambda x:x!='' and x!='"', argAt.split(sp)) # reasons in this argument 
     134            argument.setattr("unspecialized_argument", False) 
     135 
     136            reasonValues = filter(lambda x:x != '' and x != '"', argAt.split(sp)) # reasons in this argument 
    135137            # iterate through argument names 
    136138            for r in reasonValues: 
    137                 r=string.strip(r)   # Remove all white characters on both sides 
     139                r = string.strip(r)   # Remove all white characters on both sides 
    138140                try: 
    139141                    attribute = domain[r] 
     
    141143                    attribute = None 
    142144                if attribute: # only attribute name is mentioned as a reason 
    143                     if domain.index(attribute)<0: 
    144                         warnings.warn("Meta attribute %s used in argument. Is this intentional?"%r) 
     145                    if domain.index(attribute) < 0: 
     146                        warnings.warn("Meta attribute %s used in argument. Is this intentional?" % r) 
    145147                        continue 
    146148                    value = example[attribute] 
    147149                    if attribute.varType == Orange.core.VarTypes.Discrete: # discrete argument 
    148150                        argument.filter.conditions.append(Orange.core.ValueFilter_discrete( 
    149                                                             position = domain.attributes.index(attribute), 
     151                                                            position=domain.attributes.index(attribute), 
    150152                                                            values=[value], 
    151                                                             acceptSpecial = 0)) 
    152                         argument.filter.conditions[-1].setattr("unspecialized_condition",False) 
     153                                                            acceptSpecial=0)) 
     154                        argument.filter.conditions[-1].setattr("unspecialized_condition", False) 
    153155                    else: # continuous but without reference point 
    154                         warnings.warn("Continous attributes (%s) in arguments should not be used without a comparison sign (<,<=,>,>=)"%r)             
    155              
     156                        warnings.warn("Continous attributes (%s) in arguments should not be used without a comparison sign (<,<=,>,>=)" % r) 
     157 
    156158                else: # attribute and something name is the reason, probably cont. attribute 
    157159                    # one of four possible delimiters should be found, <,>,<=,>= 
    158                     splitReason = filter(lambda x:x!='' and x!='"', argCompare.split(r)) 
    159                     if len(splitReason)>2 or len(splitReason)==0: 
    160                         warnings.warn("Reason %s is a badly formed part of an argument."%r) 
     160                    splitReason = filter(lambda x:x != '' and x != '"', argCompare.split(r)) 
     161                    if len(splitReason) > 2 or len(splitReason) == 0: 
     162                        warnings.warn("Reason %s is a badly formed part of an argument." % r) 
    161163                        continue 
    162164                    # get attribute name and continous reference value 
     
    175177                        attribute = domain[attributeName] 
    176178                    except: 
    177                         warnings.warn("Attribute %s is not a part of the domain"%attributeName) 
     179                        warnings.warn("Attribute %s is not a part of the domain" % attributeName) 
    178180                        continue 
    179                     if domain.index(attribute)<0: 
    180                         warnings.warn("Meta attribute %s used in argument. Is this intentional?"%r) 
     181                    if domain.index(attribute) < 0: 
     182                        warnings.warn("Meta attribute %s used in argument. Is this intentional?" % r) 
    181183                        continue 
    182184                    if refValue: 
     
    184186                            ref = eval(refValue) 
    185187                        except: 
    186                             warnings.warn("Error occured while reading value by argument's reason. Argument: %s, value: %s"%(r,refValue)) 
     188                            warnings.warn("Error occured while reading value by argument's reason. Argument: %s, value: %s" % (r, refValue)) 
    187189                            continue 
    188190                    else: 
    189                         ref = 0.                         
     191                        ref = 0. 
    190192                    if sign == "<": oper = Orange.core.ValueFilter_continuous.Less 
    191193                    elif sign == ">": oper = Orange.core.ValueFilter_continuous.Greater 
     
    193195                    else: oper = Orange.core.ValueFilter_continuous.GreaterEqual 
    194196                    argument.filter.conditions.append(Orange.core.ValueFilter_continuous( 
    195                                                 position = domain.attributes.index(attribute), 
     197                                                position=domain.attributes.index(attribute), 
    196198                                                oper=oper, 
    197199                                                ref=ref, 
    198                                                 acceptSpecial = 0)) 
     200                                                acceptSpecial=0)) 
    199201                    if not refValue and type == POSITIVE: 
    200                         argument.filter.conditions[-1].setattr("unspecialized_condition",True) 
    201                         argument.setattr("unspecialized_argument",True) 
     202                        argument.filter.conditions[-1].setattr("unspecialized_condition", True) 
     203                        argument.setattr("unspecialized_argument", True) 
    202204                    else: 
    203                         argument.filter.conditions[-1].setattr("unspecialized_condition",False) 
     205                        argument.filter.conditions[-1].setattr("unspecialized_condition", False) 
    204206 
    205207            if example.domain.classVar: 
    206                 argument.classifier = Orange.core.DefaultClassifier(defaultVal = example.getclass()) 
     208                argument.classifier = Orange.core.DefaultClassifier(defaultVal=example.getclass()) 
    207209            argument.complexity = len(argument.filter.conditions) 
    208210 
     
    212214                argumentation.addNegative(argument) 
    213215            type = POSITIVE 
    214         return argumentation                     
     216        return argumentation 
    215217 
    216218 
     
    221223    # used for writing to string 
    222224    def val2str(self, val): 
    223         return str(val)         
    224  
    225      
     225        return str(val) 
     226 
     227 
    226228class ArgumentFilter_hasSpecial: 
    227     def __call__(self, examples, attribute, target_class=-1, negate=0): 
    228         indices = [0]*len(examples) 
     229    def __call__(self, examples, attribute, target_class= -1, negate=0): 
     230        indices = [0] * len(examples) 
    229231        for i in range(len(examples)): 
    230232            if examples[i][attribute].isSpecial(): 
    231                 indices[i]=1 
    232             elif target_class>-1 and not int(examples[i].getclass()) == target_class: 
    233                 indices[i]=1 
     233                indices[i] = 1 
     234            elif target_class > -1 and not int(examples[i].getclass()) == target_class: 
     235                indices[i] = 1 
    234236            elif len(examples[i][attribute].value.positive_arguments) == 0: 
    235                 indices[i]=1 
    236         return examples.select(indices,0,negate=negate) 
    237  
    238 def evaluateAndSortArguments(examples, argAtt, evaluateFunction = None, apriori = None): 
     237                indices[i] = 1 
     238        return examples.select(indices, 0, negate=negate) 
     239 
     240def evaluateAndSortArguments(examples, argAtt, evaluateFunction=None, apriori=None): 
    239241    """ Evaluate positive arguments and sort them by quality. """ 
    240242    if not apriori: 
    241         apriori = Orange.core.Distribution(examples.domain.classVar,examples) 
     243        apriori = Orange.core.Distribution(examples.domain.classVar, examples) 
    242244    if not evaluateFunction: 
    243245        evaluateFunction = Orange.core.RuleEvaluator_Laplace() 
    244          
     246 
    245247    for e in examples: 
    246248        if not e[argAtt].isSpecial(): 
    247249            for r in e[argAtt].value.positive_arguments: 
    248250                r.filterAndStore(examples, 0, e[examples.domain.classVar]) 
    249                 r.quality = evaluateFunction(r,examples,0,int(e[examples.domain.classVar]),apriori) 
    250             e[argAtt].value.positive_arguments.sort(lambda x,y: -cmp(x.quality, y.quality)) 
     251                r.quality = evaluateFunction(r, examples, 0, int(e[examples.domain.classVar]), apriori) 
     252            e[argAtt].value.positive_arguments.sort(lambda x, y:-cmp(x.quality, y.quality)) 
    251253 
    252254def isGreater(oper): 
     
    261263        return True 
    262264    return False 
    263  
    264 class ConvertClass: 
    265     """ Converting class variables into dichotomous class variable. """ 
    266     def __init__(self, classAtt, classValue, newClassAtt): 
    267         self.classAtt = classAtt 
    268         self.classValue = classValue 
    269         self.newClassAtt = newClassAtt 
    270  
    271     def __call__(self,example, returnWhat): 
    272         if example[self.classAtt] == self.classValue: 
    273             return Orange.core.Value(self.newClassAtt, self.classValue+"_") 
    274         else: 
    275             return Orange.core.Value(self.newClassAtt, "not " + self.classValue) 
    276  
    277 def createDichotomousClass(domain, att, value, negate, removeAtt = None): 
    278     # create new variable 
    279     newClass = Orange.core.EnumVariable(att.name+"_", values = [str(value)+"_", "not " + str(value)]) 
    280     positive = Orange.core.Value(newClass, str(value)+"_") 
    281     negative = Orange.core.Value(newClass, "not " + str(value)) 
    282     newClass.getValueFrom = ConvertClass(att,str(value),newClass) 
    283      
    284     att = [a for a in domain.attributes] 
    285     newDomain = Orange.core.Domain(att+[newClass]) 
    286     newDomain.addmetas(domain.getmetas()) 
    287     if negate==1: 
    288         return (newDomain, negative) 
    289     else: 
    290         return (newDomain, positive) 
    291  
    292265 
    293266class ConvertCont: 
     
    298271        self.newAtt = newAtt 
    299272 
    300     def __call__(self,example, returnWhat): 
     273    def __call__(self, example, returnWhat): 
    301274        if example[self.position].isSpecial(): 
    302275            return example[self.position] 
    303276        if isLess(self.oper): 
    304             if example[self.position]<self.value: 
     277            if example[self.position] < self.value: 
    305278                return Orange.core.Value(self.newAtt, self.value) 
    306279            else: 
    307280                return Orange.core.Value(self.newAtt, float(example[self.position])) 
    308281        else: 
    309             if example[self.position]>self.value: 
     282            if example[self.position] > self.value: 
    310283                return Orange.core.Value(self.newAtt, self.value) 
    311284            else: 
     
    316289    """ Main task of this function is to add probabilistic errors to examples.""" 
    317290    for ex_i, ex in enumerate(test_data): 
    318         (cl,prob) = classifier(ex,Orange.core.GetBoth) 
    319         ex.setmeta("ProbError", float(ex.getmeta("ProbError")) + 1.-prob[ex.getclass()])  
    320  
    321 def nCrossValidation(data,learner,weightID=0,folds=5,n=4,gen=0,argument_id="Arguments"): 
     291        (cl, prob) = classifier(ex, Orange.core.GetBoth) 
     292        ex.setmeta("ProbError", float(ex.getmeta("ProbError")) + 1. - prob[ex.getclass()]) 
     293 
     294def nCrossValidation(data, learner, weightID=0, folds=5, n=4, gen=0, argument_id="Arguments"): 
    322295    """ Function performs n x fold crossvalidation. For each classifier 
    323296        test set is updated by calling function addErrors. """ 
     
    326299    for d in data: 
    327300        rules[float(d["SerialNumberPE"])] = [] 
    328     pick = Orange.core.MakeRandomIndicesCV(folds=folds, randseed=gen, stratified = Orange.core.MakeRandomIndices.StratifiedIfPossible)     
     301    pick = Orange.core.MakeRandomIndicesCV(folds=folds, randseed=gen, stratified=Orange.core.MakeRandomIndices.StratifiedIfPossible) 
    329302    for n_i in range(n): 
    330         pick.randseed = gen+10*n_i 
     303        pick.randseed = gen + 10 * n_i 
    331304        selection = pick(data) 
    332305        for folds_i in range(folds): 
    333             for data_i,e in enumerate(data): 
     306            for data_i, e in enumerate(data): 
    334307                try: 
    335308                    if e[argument_id]: # examples with arguments do not need to be tested 
    336                         selection[data_i]=folds_i+1 
     309                        selection[data_i] = folds_i + 1 
    337310                except: 
    338311                    pass 
    339             train_data = data.selectref(selection, folds_i,negate=1) 
    340             test_data = data.selectref(selection, folds_i,negate=0) 
    341             classifier = learner(train_data,weightID) 
     312            train_data = data.selectref(selection, folds_i, negate=1) 
     313            test_data = data.selectref(selection, folds_i, negate=0) 
     314            classifier = learner(train_data, weightID) 
    342315            addErrors(test_data, classifier) 
    343316            # add rules 
     
    348321    # normalize prob errors 
    349322    for d in data: 
    350         d["ProbError"]=d["ProbError"]/n 
     323        d["ProbError"] = d["ProbError"] / n 
    351324    return rules 
    352325 
    353 def findProb(learner,examples,weightID=0,folds=5,n=4,gen=0,thr=0.5,argument_id="Arguments"): 
     326def findProb(learner, examples, weightID=0, folds=5, n=4, gen=0, thr=0.5, argument_id="Arguments"): 
    354327    """ General method for calling to find problematic example. 
    355328        It returns all critial examples along with average probabilistic errors that ought to be higher then thr. 
     
    373346 
    374347    # it returns a list of examples now: (index of example-starting with 0, example, prob error, rules covering example 
    375     rules = nCrossValidation(newExamples,learner,weightID=weightID, folds=folds, n=n, gen=gen, argument_id=argument_id) 
     348    rules = nCrossValidation(newExamples, learner, weightID=weightID, folds=folds, n=n, gen=gen, argument_id=argument_id) 
    376349    return [(ei, examples[ei], float(e["ProbError"]), rules[float(e["SerialNumberPE"])]) for ei, e in enumerate(newExamples) if e["ProbError"] > thr] 
    377    
     350 
  • Orange/preprocess/outliers.py

    r9671 r9725  
    3636 
    3737import Orange 
    38 import statc 
     38from Orange import statc 
    3939 
    4040class OutlierDetection: 
  • Orange/projection/linear.py

    r9707 r9725  
    6464 
    6565import Orange 
    66 import orangeom 
     66from Orange import orangeom 
    6767import math 
    6868import random 
  • Orange/projection/mds.py

    r9671 r9725  
    102102 
    103103import Orange.core 
    104 import orangeom as orangemds 
     104from Orange import orangeom as orangemds 
    105105from Orange.misc import deprecated_keywords 
    106106from Orange.misc import deprecated_members 
  • Orange/regression/linear.py

    r9671 r9725  
    5757    from scipy import stats 
    5858except ImportError: 
    59     import statc as stats 
     59    import Orange.statc as stats 
    6060 
    6161from numpy import dot, sqrt 
  • Orange/testing/regression/results_modules/abcn2-rules.py.txt

    r9689 r9741  
    1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  arguments finished ...  
    2 rule learned:  IF sex=['male'] AND status=['second'] AND age=['adult'] THEN survived_=no_<154.000, 14.000> 0.913846611977 
    3 rule learned:  IF sex=['male'] AND status=['third'] AND age=['adult'] THEN survived_=no_<387.000, 75.000> 0.836969733238 
    4 rule learned:  IF sex=['male'] AND status=['third'] THEN survived_=no_<422.000, 88.000> 0.82686316967 
    5 rule learned:  IF sex=['male'] AND age=['adult'] THEN survived_=no_<1329.000, 338.000> 0.797096371651 
    6 rule learned:  IF status=['crew'] THEN survived_=no_<673.000, 212.000> 0.760263741016 
    7 rule learned:  IF status=['third'] AND age=['adult'] THEN survived_=no_<476.000, 151.000> 0.757614195347 
    8 rule learned:  IF status=['third'] THEN survived_=no_<528.000, 178.000> 0.747675061226 
    9 rule learned:  IF age=['adult'] THEN survived_=no_<1438.000, 654.000> 0.687131047249 
    10 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  arguments finished ...  
    11 rule learned:  IF status=['first'] AND sex=['female'] THEN survived_=yes_<141.000, 4.000> 0.963578701019 
    12 rule learned:  IF status=['second'] AND age=['child'] THEN survived_=yes_<24.000, 0.000> 0.947925806046 
    13 rule learned:  IF sex=['female'] AND status=['second'] THEN survived_=yes_<93.000, 13.000> 0.867093265057 
    14 rule learned:  IF sex=['female'] AND status=['crew'] THEN survived_=yes_<20.000, 3.000> 0.820993065834 
    15 rule learned:  IF sex=['female'] AND age=['adult'] THEN survived_=yes_<316.000, 109.000> 0.741559863091 
    16 rule learned:  IF sex=['female'] THEN survived_=yes_<344.000, 126.000> 0.730182349682 
    17 rule learned:  IF status=['first'] AND age=['child'] THEN survived_=yes_<6.000, 0.000> 0.718153715134 
    18 rule learned:  IF status=['first'] THEN survived_=yes_<203.000, 122.000> 0.62277084589 
    19 rule learned:  IF age=['child'] THEN survived_=yes_<57.000, 52.000> 0.517443716526 
    20 rule learned:  IF status=['second'] THEN survived_=yes_<118.000, 167.000> 0.402684390545 
     1<function create_dichotomous_class at 0x1cad758> 
     2IF TRUE THEN survived=no<1490.000, 711.000> 
     3IF sex=['female'] THEN survived=yes<126.000, 344.000> 
     4IF status=['third'] THEN survived=no<528.000, 178.000> 
     5IF status=['first'] THEN survived=yes<122.000, 203.000> 
    216IF status=['crew'] THEN survived=no<673.000, 212.000> 
    22 IF status=['first'] AND sex=['female'] THEN survived=yes<4.000, 141.000> 
     7IF age=['adult'] THEN survived=no<1438.000, 654.000> 
     8IF age=['child'] THEN survived=yes<52.000, 57.000> 
     9IF status=['second'] AND age=['child'] THEN survived=yes<0.000, 24.000> 
     10IF sex=['female'] AND status=['first'] THEN survived=yes<4.000, 141.000> 
     11IF sex=['female'] AND status=['second'] THEN survived=yes<13.000, 93.000> 
    2312IF sex=['female'] AND status=['crew'] THEN survived=yes<3.000, 20.000> 
    24 IF status=['second'] AND age=['child'] THEN survived=yes<0.000, 24.000> 
    25 IF sex=['female'] AND status=['second'] THEN survived=yes<13.000, 93.000> 
    2613IF status=['first'] AND age=['child'] THEN survived=yes<0.000, 6.000> 
     14IF sex=['female'] AND age=['adult'] THEN survived=yes<109.000, 316.000> 
     15IF sex=['male'] AND age=['adult'] THEN survived=no<1329.000, 338.000> 
     16IF status=['third'] AND age=['adult'] THEN survived=no<476.000, 151.000> 
    2717IF sex=['male'] AND status=['third'] THEN survived=no<422.000, 88.000> 
    28 IF sex=['male'] AND age=['adult'] THEN survived=no<1329.000, 338.000> 
    2918IF sex=['male'] AND status=['second'] AND age=['adult'] THEN survived=no<154.000, 14.000> 
    3019IF sex=['male'] AND status=['third'] AND age=['adult'] THEN survived=no<387.000, 75.000> 
    3120***** 
    32 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  arguments finished ...  
    33 rule learned:  IF sex=['male'] AND status=['second'] AND age=['adult'] THEN survived_=no_<154.000, 14.000> 0.913846611977 
    34 rule learned:  IF sex=['male'] AND status=['third'] AND age=['adult'] THEN survived_=no_<387.000, 75.000> 0.836969733238 
    35 rule learned:  IF sex=['male'] AND status=['third'] THEN survived_=no_<422.000, 88.000> 0.82686316967 
    36 rule learned:  IF sex=['male'] AND age=['adult'] THEN survived_=no_<1329.000, 338.000> 0.797096371651 
    37 rule learned:  IF status=['crew'] THEN survived_=no_<673.000, 212.000> 0.760263741016 
    38 rule learned:  IF status=['third'] AND age=['adult'] THEN survived_=no_<476.000, 151.000> 0.757614195347 
    39 rule learned:  IF status=['third'] THEN survived_=no_<528.000, 178.000> 0.747675061226 
    40 rule learned:  IF age=['adult'] THEN survived_=no_<1438.000, 654.000> 0.687131047249 
    41 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  arguments finished ...  
    42 rule learned:  IF status=['first'] AND sex=['female'] THEN survived_=yes_<141.000, 4.000> 0.963578701019 
    43 rule learned:  IF status=['second'] AND age=['child'] THEN survived_=yes_<24.000, 0.000> 0.947925806046 
    44 rule learned:  IF sex=['female'] AND status=['second'] THEN survived_=yes_<93.000, 13.000> 0.867093265057 
    45 rule learned:  IF sex=['female'] AND status=['crew'] THEN survived_=yes_<20.000, 3.000> 0.820993065834 
    46 rule learned:  IF sex=['female'] AND age=['adult'] THEN survived_=yes_<316.000, 109.000> 0.741559863091 
    47 rule learned:  IF sex=['female'] THEN survived_=yes_<344.000, 126.000> 0.730182349682 
    48 rule learned:  IF status=['first'] AND age=['child'] THEN survived_=yes_<6.000, 0.000> 0.718153715134 
    49 rule learned:  IF status=['first'] THEN survived_=yes_<203.000, 122.000> 0.62277084589 
    50 rule learned:  IF age=['child'] THEN survived_=yes_<57.000, 52.000> 0.517443716526 
    51 rule learned:  IF status=['second'] THEN survived_=yes_<118.000, 167.000> 0.402684390545 
    5221***** 
    53 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  arguments finished ...  
    54 rule learned:  IF sex=['male'] AND status=['second'] AND age=['adult'] THEN survived_=no_<154.000, 14.000> 0.913846611977 
    55 rule learned:  IF sex=['male'] AND status=['third'] AND age=['adult'] THEN survived_=no_<387.000, 75.000> 0.836969733238 
    56 rule learned:  IF sex=['male'] AND status=['third'] THEN survived_=no_<422.000, 88.000> 0.82686316967 
    57 rule learned:  IF sex=['male'] AND age=['adult'] THEN survived_=no_<1329.000, 338.000> 0.797096371651 
    58 rule learned:  IF status=['crew'] THEN survived_=no_<673.000, 212.000> 0.760263741016 
    59 rule learned:  IF status=['third'] AND age=['adult'] THEN survived_=no_<476.000, 151.000> 0.757614195347 
    60 rule learned:  IF status=['third'] THEN survived_=no_<528.000, 178.000> 0.747675061226 
    61 rule learned:  IF age=['adult'] THEN survived_=no_<1438.000, 654.000> 0.687131047249 
    62 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99  arguments finished ...  
    63 rule learned:  IF status=['first'] AND sex=['female'] THEN survived_=yes_<141.000, 4.000> 0.963578701019 
    64 rule learned:  IF status=['second'] AND age=['child'] THEN survived_=yes_<24.000, 0.000> 0.947925806046 
    65 rule learned:  IF sex=['female'] AND status=['second'] THEN survived_=yes_<93.000, 13.000> 0.867093265057 
    66 rule learned:  IF sex=['female'] AND status=['crew'] THEN survived_=yes_<20.000, 3.000> 0.820993065834 
    67 rule learned:  IF sex=['female'] AND age=['adult'] THEN survived_=yes_<316.000, 109.000> 0.741559863091 
    68 rule learned:  IF sex=['female'] THEN survived_=yes_<344.000, 126.000> 0.730182349682 
    69 rule learned:  IF status=['first'] AND age=['child'] THEN survived_=yes_<6.000, 0.000> 0.718153715134 
    70 rule learned:  IF status=['first'] THEN survived_=yes_<203.000, 122.000> 0.62277084589 
    71 rule learned:  IF age=['child'] THEN survived_=yes_<57.000, 52.000> 0.517443716526 
    72 rule learned:  IF status=['second'] THEN survived_=yes_<118.000, 167.000> 0.402684390545 
    73 IF status=['crew'] THEN survived=no<673.000, 212.000> 
    74 IF status=['first'] AND sex=['female'] THEN survived=yes<4.000, 141.000> 
    75 IF sex=['female'] AND status=['crew'] THEN survived=yes<3.000, 20.000> 
    76 IF status=['second'] AND age=['child'] THEN survived=yes<0.000, 24.000> 
    77 IF sex=['female'] AND status=['second'] THEN survived=yes<13.000, 93.000> 
    78 IF status=['first'] AND age=['child'] THEN survived=yes<0.000, 6.000> 
    79 IF sex=['male'] AND status=['third'] THEN survived=no<422.000, 88.000> 
    8022IF sex=['male'] AND age=['adult'] THEN survived=no<1329.000, 338.000> 
     23IF age=['adult'] THEN survived=no<1438.000, 654.000> 
    8124IF sex=['male'] AND status=['second'] AND age=['adult'] THEN survived=no<154.000, 14.000> 
    8225IF sex=['male'] AND status=['third'] AND age=['adult'] THEN survived=no<387.000, 75.000> 
     26IF status=['third'] AND age=['adult'] THEN survived=no<476.000, 151.000> 
     27IF sex=['male'] AND status=['third'] THEN survived=no<422.000, 88.000> 
     28IF status=['third'] THEN survived=no<528.000, 178.000> 
     29IF status=['crew'] THEN survived=no<673.000, 212.000> 
     30IF status=['first'] THEN survived=yes<122.000, 203.000> 
     31IF sex=['female'] AND status=['first'] THEN survived=yes<4.000, 141.000> 
     32IF status=['first'] AND age=['child'] THEN survived=yes<0.000, 6.000> 
     33IF status=['second'] THEN survived=yes<167.000, 118.000> 
     34IF sex=['female'] AND status=['second'] THEN survived=yes<13.000, 93.000> 
     35IF status=['second'] AND age=['child'] THEN survived=yes<0.000, 24.000> 
     36IF sex=['female'] AND age=['adult'] THEN survived=yes<109.000, 316.000> 
     37IF age=['child'] THEN survived=yes<52.000, 57.000> 
     38IF sex=['female'] THEN survived=yes<126.000, 344.000> 
     39IF sex=['female'] AND status=['crew'] THEN survived=yes<3.000, 20.000> 
    8340***** 
  • Orange/testing/regression/results_modules/ensemble.py.txt

    r9689 r9739  
    11Classification Accuracy: 
    22           tree: 0.804 
    3    boosted tree: 0.818 
     3   boosted tree: 0.811 
    44    bagged tree: 0.797 
  • Orange/testing/regression/xtest.py

    r9690 r9751  
    141141 
    142142 
    143 iterations = 3 
     143iterations = 1 
    144144directories = [] 
    145145error_status = 0 
  • docs/reference/rst/Orange.classification.rst

    r9708 r9735  
    5656              tuple with both 
    5757 
    58 You can often program learners and classifiers as classes or functions 
    59 written entirely in Python and independent from Orange, as shown in 
    60 Orange for Beginners. Such classes can participate, for instance, in 
    61 the common evaluation functions like those available in modules orngTest 
    62 and orngStat. 
     58You can often program learners and classifiers as classes or functions written 
     59entirely in Python and independent from Orange. Such classes can participate, 
     60for instance, in the common evaluation functions like those available in 
     61modules :obj:`Orange.evaluation.testing` and :obj:`Orange.evaluation.scoring`. 
    6362 
    6463On the other hand, these classes can't be used as components for pure C++ 
    65 classes. For instance, TreeLearner's attribute nodeLearner should contain 
    66 a (wrapped) C++ object derived from Learner, such as MajorityLearner 
    67 or BayesLearner, and Variables's getValueFrom can only store classes 
    68 derived from Classifier, like for instance ClassifierFromVar. They cannot 
    69 accommodate Python's classes or even functions. 
     64classes. For instance, :obj:`Orange.classification.tree.TreeLearner`'s 
     65attribute nodeLearner should contain a (wrapped) C++ object derived from 
     66:obj:`Learner`, such as :obj:`Orange.classification.majority.MajorityLearner` 
     67or :obj:`Orange.classification.bayes.NaiveLearner`. They cannot accommodate 
     68Python's classes or even functions. 
    7069 
    71 There's a workaround, though. You can subtype Orange classes Learner 
    72 or Classifier as if the two classes were defined in Python, but later 
    73 use your derived Python classes as if they were written in Orange's 
    74 core. That is, you can define your class in a Python script like this: 
     70There's a workaround, though. You can subtype Orange classes :obj:`Learner` or 
     71:obj:`Classifier` as if the two classes were defined in Python, but later use your 
     72derived Python classes as if they were written in Orange's core. That is, you 
     73can define your class in a Python script like this:: 
    7574 
    76     class MyLearner(orange.Learner):  
     75    class MyLearner(Orange.classifier.Learner):  
    7776        def __call__(self, examples, weightID = 0):  
    7877            <do something smart here> 
     
    8079Such a learner can then be used as any regular learner written in 
    8180Orange. You can, for instance, construct a tree learner and use your 
    82 learner to learn node classifier: 
     81learner to learn node classifier:: 
    8382 
    84     treeLearner = orange.TreeLearner() 
     83    treeLearner = Orange.classification.tree.TreeLearner() 
    8584    treeLearner.nodeLearner = MyLearner() 
    8685 
    87 If your learner or classifier is simple enough, you even don't need 
    88 to derive a class yourself. You can define the learner or classifier 
    89 as an ordinary Python function and assign it to an attribute of Orange 
    90 class that would expect a Learner or a Classifier. Wrapping into a class 
    91 derived from Learner or Classifier is done by Orange. ::  
    92  
    93     def myLearner(examples, weightID = 0):  
    94         <do something less smart here> 
    95      
    96     treeLearner = orange.TreeLearner() 
    97     treeLearner.nodeLearner = myLearner 
    98  
    99 Finally, if your learner is really simple (that is, trivial :-), you 
    100 can even stuff it into a lambda function. :: 
    101  
    102     treeLearner = orange.TreeLearner() 
    103     treeLearner.nodeLearner = lambda examples, weightID = 0: <do something trivial> 
    104  
    105 Detailed description of the mechanisms involved and example scripts are 
    106 given in a separate documentation on subtyping Orange classes in Python. 
     86----- 
    10787 
    10888Orange contains implementations of various classifiers that are described in 
  • docs/reference/rst/Orange.data.table.rst

    r9636 r9726  
    99(:obj:`Orange.data.Domain`). 
    1010 
    11 Data tables are usually loaded from a file (see :doc:`/Orange.data.formats`):: 
     11Data tables are usually loaded from a file (see :doc:`Orange.data.formats`):: 
    1212 
    1313    import Orange 
  • docs/reference/rst/Orange.data.variable.rst

    r9372 r9727  
    11.. automodule:: Orange.data.variable 
     2 
     3======================== 
     4Variables (``variable``) 
     5======================== 
     6 
     7Data instances in Orange can contain several types of variables: 
     8:ref:`discrete <discrete>`, :ref:`continuous <continuous>`, 
     9:ref:`strings <string>`, and :ref:`Python <Python>` and types derived from it. 
     10The latter represent arbitrary Python objects. 
     11The names, types, values (where applicable), functions for computing the 
     12variable value from values of other variables, and other properties of the 
     13variables are stored in descriptor classes derived from :obj:`Orange.data 
     14.variable.Variable`. 
     15 
     16Orange considers two variables (e.g. in two different data tables) the 
     17same if they have the same descriptor. It is allowed - but not 
     18recommended - to have different variables with the same name. 
     19 
     20Variable descriptors 
     21-------------------- 
     22 
     23Variable descriptors can be constructed either by calling the 
     24corresponding constructors or by a factory function :func:`Orange.data 
     25.variable.make`, which either retrieves an existing descriptor or 
     26constructs a new one. 
     27 
     28.. class:: Variable 
     29 
     30    An abstract base class for variable descriptors. 
     31 
     32    .. attribute:: name 
     33 
     34        The name of the variable. 
     35 
     36    .. attribute:: var_type 
     37 
     38        Variable type; it can be :obj:`~Orange.data.Type.Discrete`, 
     39        :obj:`~Orange.data.Type.Continuous`, 
     40        :obj:`~Orange.data.Type.String` or :obj:`~Orange.data.Type.Other`. 
     41 
     42    .. attribute:: get_value_from 
     43 
     44        A function (an instance of :obj:`~Orange.classification.Classifier`) 
     45        that computes a value of the variable from values of one or more 
     46        other variables. This is used, for instance, in discretization, 
     47        which computes the value of a discretized variable from the 
     48        original continuous variable. 
     49 
     50    .. attribute:: ordered 
     51 
     52        A flag telling whether the values of a discrete variable are ordered. At 
     53        the moment, no built-in method treats ordinal variables differently than 
     54        nominal ones. 
     55 
     56    .. attribute:: random_generator 
     57 
     58        A local random number generator used by method 
     59        :obj:`~Variable.randomvalue()`. 
     60 
     61    .. attribute:: default_meta_id 
     62 
     63        A proposed (but not guaranteed) meta id to be used for that variable. 
     64        For instance, when a tab-delimited contains meta attributes and 
     65        the existing variables are reused, they will have this id 
     66        (instead of a new one assigned by :obj:`Orange.data.new_meta_id()`). 
     67 
     68    .. attribute:: attributes 
     69 
     70        A dictionary which allows the user to store additional information 
     71        about the variable. All values should be strings. See the section 
     72        about :ref:`storing additional information <attributes>`. 
     73 
     74    .. method:: __call__(obj) 
     75 
     76           Convert a string, number, or other suitable object into a variable 
     77           value. 
     78 
     79           :param obj: An object to be converted into a variable value 
     80           :type o: any suitable 
     81           :rtype: :class:`Orange.data.Value` 
     82 
     83    .. method:: randomvalue() 
     84 
     85           Return a random value for the variable. 
     86 
     87           :rtype: :class:`Orange.data.Value` 
     88 
     89    .. method:: compute_value(inst) 
     90 
     91           Compute the value of the variable given the instance by calling 
     92           obj:`~Variable.get_value_from` through a mechanism that 
     93           prevents infinite recursive calls. 
     94 
     95           :rtype: :class:`Orange.data.Value` 
     96 
     97.. _discrete: 
     98.. class:: Discrete 
     99 
     100    Bases: :class:`Variable` 
     101 
     102    Descriptor for discrete variables. 
     103 
     104    .. attribute:: values 
     105 
     106        A list with symbolic names for variables' values. Values are stored as 
     107        indices referring to this list and modifying it instantly 
     108        changes the (symbolic) names of values as they are printed out or 
     109        referred to by user. 
     110 
     111        .. note:: 
     112 
     113            The size of the list is also used to indicate the number of 
     114            possible values for this variable. Changing the size - especially 
     115            shrinking the list - can crash Python. Also, do not add values 
     116            to the list by calling its append or extend method: use 
     117             :obj:`add_value` method instead. 
     118 
     119            It is also assumed that this attribute is always defined (but can 
     120            be empty), so never set it to ``None``. 
     121 
     122    .. attribute:: base_value 
     123 
     124            Stores the base value for the variable as an index in `values`. 
     125            This can be, for instance, a "normal" value, such as "no 
     126            complications" as opposed to abnormal "low blood pressure". The 
     127            base value is used by certain statistics, continuization etc. 
     128            potentially, learning algorithms. The default is -1 which means that 
     129            there is no base value. 
     130 
     131    .. method:: add_value(s) 
     132 
     133            Add a value with symbolic name ``s`` to values. Always call 
     134            this function instead of appending to ``values``. 
     135 
     136.. _continuous: 
     137.. class:: Continuous 
     138 
     139    Bases: :class:`Variable` 
     140 
     141    Descriptor for continuous variables. 
     142 
     143    .. attribute:: number_of_decimals 
     144 
     145        The number of decimals used when the value is printed out, converted to 
     146        a string or saved to a file. 
     147 
     148    .. attribute:: scientific_format 
     149 
     150        If ``True``, the value is printed in scientific format whenever it 
     151        would have more than 5 digits. In this case, :obj:`number_of_decimals` is 
     152        ignored. 
     153 
     154    .. attribute:: adjust_decimals 
     155 
     156        Tells Orange to monitor the number of decimals when the value is 
     157        converted from a string (when the values are read from a file or 
     158        converted by, e.g. ``inst[0]="3.14"``): 
     159 
     160        * 0: the number of decimals is not adjusted automatically; 
     161        * 1: the number of decimals is (and has already) been adjusted; 
     162        * 2: automatic adjustment is enabled, but no values have been 
     163          converted yet. 
     164 
     165        By default, adjustment of the number of decimals goes as follows: 
     166 
     167        * If the variable was constructed when data was read from a file, 
     168          it will be printed with the same number of decimals as the 
     169          largest number of decimals encountered in the file. If 
     170          scientific notation occurs in the file, 
     171          :obj:`scientific_format` will be set to ``True`` and scientific 
     172          format will be used for values too large or too small. 
     173 
     174        * If the variable is created in a script, it will have, 
     175          by default, three decimal places. This can be changed either by 
     176          setting the value from a string (e.g. ``inst[0]="3.14"``, 
     177          but not ``inst[0]=3.14``) or by manually setting the 
     178          :obj:`number_of_decimals`. 
     179 
     180    .. attribute:: start_value, end_value, step_value 
     181 
     182        The range used for :obj:`randomvalue`. 
     183 
     184.. _String: 
     185.. class:: String 
     186 
     187    Bases: :class:`Variable` 
     188 
     189    Descriptor for variables that contain strings. No method can use them for 
     190    learning; some will raise error or warnings, and others will 
     191    silently ignore them. They can be, however, used as meta-attributes; if 
     192    instances in a dataset have unique IDs, the most efficient way to store them 
     193    is to read them as meta-attributes. In general, never use discrete 
     194    attributes with many (say, more than 50) values. Such attributes are 
     195    probably not of any use for learning and should be stored as string 
     196    attributes. 
     197 
     198    When converting strings into values and back, empty strings are treated 
     199    differently than usual. For other types, an empty string denotes 
     200    undefined values, while :obj:`String` will take empty strings 
     201    as empty strings -- except when loading or saving into file. 
     202    Empty strings in files are interpreted as undefined; to specify an empty 
     203    string, enclose the string in double quotes; these are removed when the 
     204    string is loaded. 
     205 
     206.. _Python: 
     207.. class:: Python 
     208 
     209    Bases: :class:`Variable` 
     210 
     211    Base class for descriptors defined in Python. It is fully functional 
     212    and can be used as a descriptor for attributes that contain arbitrary Python 
     213    values. Since this is an advanced topic, PythonVariables are described on a 
     214    separate page. !!TODO!! 
     215 
     216 
     217.. _attributes: 
     218 
     219Storing additional attributes 
     220----------------------------- 
     221 
     222All variables have a field :obj:`~Variable.attributes`, a dictionary 
     223that can store additional string data. 
     224 
     225.. literalinclude:: code/attributes.py 
     226 
     227These attributes can only be saved to a .tab file. They are listed in the 
     228third line in <name>=<value> format, after other attribute specifications 
     229(such as "meta" or "class"), and are separated by spaces. 
     230 
     231.. _variable_descriptor_reuse: 
     232 
     233Reuse of descriptors 
     234-------------------- 
     235 
     236There are situations when variable descriptors need to be reused. Typically, the 
     237user loads some training examples, trains a classifier, and then loads a separate 
     238test set. For the classifier to recognize the variables in the second data set, 
     239the descriptors, not just the names, need to be the same. 
     240 
     241When constructing new descriptors for data read from a file or during unpickling, 
     242Orange checks whether an appropriate descriptor (with the same name and, in case 
     243of discrete variables, also values) already exists and reuses it. When new 
     244descriptors are constructed by explicitly calling the above constructors, this 
     245always creates new descriptors and thus new variables, although a variable with 
     246the same name may already exist. 
     247 
     248The search for an existing variable is based on four attributes: the variable's name, 
     249type, ordered values, and unordered values. As for the latter two, the values can 
     250be explicitly ordered by the user, e.g. in the second line of the tab-delimited 
     251file. For instance, sizes can be ordered as small, medium, or big. 
     252 
     253The search for existing variables can end with one of the following statuses. 
     254 
     255.. data:: Orange.data.variable.MakeStatus.NotFound (4) 
     256 
     257    The variable with that name and type does not exist. 
     258 
     259.. data:: Orange.data.variable.MakeStatus.Incompatible (3) 
     260 
     261    There are variables with matching name and type, but their 
     262    values are incompatible with the prescribed ordered values. For example, 
     263    if the existing variable already has values ["a", "b"] and the new one 
     264    wants ["b", "a"], the old variable cannot be reused. The existing list can, 
     265    however be appended with the new values, so searching for ["a", "b", "c"] would 
     266    succeed. Likewise a search for ["a"] would be successful, since the extra existing value 
     267    does not matter. The formal rule is thus that the values are compatible iff ``existing_values[:len(ordered_values)] == ordered_values[:len(existing_values)]``. 
     268 
     269.. data:: Orange.data.variable.MakeStatus.NoRecognizedValues (2) 
     270 
     271    There is a matching variable, yet it has none of the values that the new 
     272    variable will have (this is obviously possible only if the new variable has 
     273    no prescribed ordered values). For instance, we search for a variable 
     274    "sex" with values "male" and "female", while there is a variable of the same 
     275    name with values "M" and "F" (or, well, "no" and "yes" :). Reuse of this 
     276    variable is possible, though this should probably be a new variable since it 
     277    obviously comes from a different data set. If we do decide to reuse the variable, the 
     278    old variable will get some unneeded new values and the new one will inherit 
     279    some from the old. 
     280 
     281.. data:: Orange.data.variable.MakeStatus.MissingValues (1) 
     282 
     283    There is a matching variable with some of the values that the new one 
     284    requires, but some values are missing. This situation is neither uncommon 
     285    nor suspicious: in case of separate training and testing data sets there may 
     286    be values which occur in one set but not in the other. 
     287 
     288.. data:: Orange.data.variable.MakeStatus.OK (0) 
     289 
     290    There is a perfect match which contains all the prescribed values in the 
     291    correct order. The existing variable may have some extra values, though. 
     292 
     293Continuous variables can obviously have only two statuses, 
     294:obj:`~Orange.data.variable.MakeStatus.NotFound` or :obj:`~Orange.data.variable.MakeStatus.OK`. 
     295 
     296When loading the data using :obj:`Orange.data.Table`, Orange takes the safest 
     297approach and, by default, reuses everything that is compatible up to 
     298and including :obj:`~Orange.data.variable.MakeStatus.NoRecognizedValues`. Unintended reuse would be obvious from the 
     299variable having too many values, which the user can notice and fix. More on that 
     300in the page on :doc:`Orange.data.formats`. 
     301 
     302There are two functions for reusing the variables instead of creating new ones. 
     303 
     304.. function:: Orange.data.variable.make(name, type, ordered_values, unordered_values[, create_new_on]) 
     305 
     306    Find and return an existing variable or create a new one if none of the existing 
     307    variables matches the given name, type and values. 
     308 
     309    The optional `create_new_on` specifies the status at which a new variable is 
     310    created. The status must be at most :obj:`~Orange.data.variable.MakeStatus.Incompatible` since incompatible (or 
     311    non-existing) variables cannot be reused. If it is set lower, for instance 
     312    to :obj:`~Orange.data.variable.MakeStatus.MissingValues`, a new variable is created even if there exists 
     313    a variable which is only missing the same values. If set to :obj:`~Orange.data.variable.MakeStatus.OK`, the function 
     314    always creates a new variable. 
     315 
     316    The function returns a tuple containing a variable descriptor and the 
     317    status of the best matching variable. So, if ``create_new_on`` is set to 
     318    :obj:`~Orange.data.variable.MakeStatus.MissingValues`, and there exists a variable whose status is, say, 
     319    :obj:`~Orange.data.variable.MakeStatus.NoRecognizedValues`, a variable would be created, while the second 
     320    element of the tuple would contain :obj:`~Orange.data.variable.MakeStatus.NoRecognizedValues`. If, on the other 
     321    hand, there exists a variable which is perfectly OK, its descriptor is 
     322    returned and the returned status is :obj:`~Orange.data.variable.MakeStatus.OK`. The function returns no 
     323    indicator whether the returned variable is reused or not. This can be, 
     324    however, read from the status code: if it is smaller than the specified 
     325    ``create_new_on``, the variable is reused, otherwise a new descriptor has been constructed. 
     326 
     327    The exception to the rule is when ``create_new_on`` is OK. In this case, the 
     328    function does not search through the existing variables and cannot know the 
     329    status, so the returned status in this case is always :obj:`~Orange.data.variable.MakeStatus.OK`. 
     330 
     331    :param name: Variable name 
     332    :param type: Variable type 
     333    :type type: Orange.data.variable.Type 
     334    :param ordered_values: a list of ordered values 
     335    :param unordered_values: a list of values, for which the order does not 
     336        matter 
     337    :param create_new_on: gives the condition for constructing a new variable instead 
     338        of using the new one 
     339 
     340    :return_type: a tuple (:class:`~Orange.data.variable.Variable`, int) 
     341 
     342.. function:: Orange.data.variable.retrieve(name, type, ordered_values, onordered_values[, create_new_on]) 
     343 
     344    Find and return an existing variable, or :obj:`None` if no match is found. 
     345 
     346    :param name: variable name. 
     347    :param type: variable type. 
     348    :type type: Orange.data.variable.Type 
     349    :param ordered_values: a list of ordered values 
     350    :param unordered_values: a list of values, for which the order does not 
     351        matter 
     352    :param create_new_on: gives the condition for constructing a new variable instead 
     353        of using the new one 
     354 
     355    :return_type: :class:`~Orange.data.variable.Variable` 
     356 
     357The following examples give the shown results if 
     358executed only once (in a Python session) and in this order. 
     359 
     360:func:`Orange.data.variable.make` can be used for the construction of new variables. :: 
     361 
     362    >>> v1, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, ["a", "b"]) 
     363    >>> print s, v1.values 
     364    NotFound <a, b> 
     365 
     366A new variable was created and the status is :obj:`~Orange.data.variable 
     367.MakeStatus.NotFound`. :: 
     368 
     369    >>> v2, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, ["a"], ["c"]) 
     370    >>> print s, v2 is v1, v1.values 
     371    MissingValues True <a, b, c> 
     372 
     373The status is :obj:`~Orange.data.variable.MakeStatus.MissingValues`, 
     374yet the variable is reused (``v2 is v1``). ``v1`` gets a new value, 
     375``"c"``, which was given as an unordered value. It does 
     376not matter that the new variable does not need the value ``b``. :: 
     377 
     378    >>> v3, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, ["a", "b", "c", "d"]) 
     379    >>> print s, v3 is v1, v1.values 
     380    MissingValues True <a, b, c, d> 
     381 
     382This is like before, except that the new value, ``d`` is not among the 
     383ordered values. :: 
     384 
     385    >>> v4, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, ["b"]) 
     386    >>> print s, v4 is v1, v1.values, v4.values 
     387    Incompatible, False, <b>, <a, b, c, d> 
     388 
     389The new variable needs to have ``b`` as the first value, so it is incompatible 
     390with the existing variables. The status is 
     391:obj:`~Orange.data.variable.MakeStatus.Incompatible` and 
     392a new variable is created; the two variables are not equal and have 
     393different lists of values. :: 
     394 
     395    >>> v5, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, None, ["c", "a"]) 
     396    >>> print s, v5 is v1, v1.values, v5.values 
     397    OK True <a, b, c, d> <a, b, c, d> 
     398 
     399The new variable has values ``c`` and ``a``, but the order is not important, 
     400so the existing attribute is :obj:`~Orange.data.variable.MakeStatus.OK`. :: 
     401 
     402    >>> v6, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, None, ["e"]) "a"]) 
     403    >>> print s, v6 is v1, v1.values, v6.values 
     404    NoRecognizedValues True <a, b, c, d, e> <a, b, c, d, e> 
     405 
     406The new variable has different values than the existing variable (status 
     407is :obj:`~Orange.data.variable.MakeStatus.NoRecognizedValues`), 
     408but the existing one is nonetheless reused. Note that we 
     409gave ``e`` in the list of unordered values. If it was among the ordered, the 
     410reuse would fail. :: 
     411 
     412    >>> v7, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, None, 
     413            ["f"], Orange.data.variable.MakeStatus.NoRecognizedValues))) 
     414    >>> print s, v7 is v1, v1.values, v7.values 
     415    Incompatible False <a, b, c, d, e> <f> 
     416 
     417This is the same as before, except that we prohibited reuse when there are no 
     418recognized values. Hence a new variable is created, though the returned status is 
     419the same as before:: 
     420 
     421    >>> v8, s = Orange.data.variable.make("a", Orange.data.Type.Discrete, 
     422            ["a", "b", "c", "d", "e"], None, Orange.data.variable.MakeStatus.OK) 
     423    >>> print s, v8 is v1, v1.values, v8.values 
     424    OK False <a, b, c, d, e> <a, b, c, d, e> 
     425 
     426Finally, this is a perfect match, but any reuse is prohibited, so a new 
     427variable is created. 
     428 
     429 
     430 
     431Variables computed from other variables 
     432--------------------------------------- 
     433 
     434Values of variables are often computed from other variables, such as in 
     435discretization. The mechanism described below usually functions behind the scenes, 
     436so understanding it is required only for implementing specific transformations. 
     437 
     438Monk 1 is a well-known dataset with target concept ``y := a==b or e==1``. 
     439It can help the learning algorithm if the four-valued attribute ``e`` is 
     440replaced with a binary attribute having values `"1"` and `"not 1"`. The 
     441new variable will be computed from the old one on the fly. 
     442 
     443.. literalinclude:: code/variable-get_value_from.py 
     444    :lines: 7-17 
     445 
     446The new variable is named ``e2``; we define it with a descriptor of type 
     447:obj:`Discrete`, with appropriate name and values ``"not 1"`` and ``1`` (we 
     448chose this order so that the ``not 1``'s index is ``0``, which can be, if 
     449needed, interpreted as ``False``). Finally, we tell e2 to use 
     450``checkE`` to compute its value when needed, by assigning ``checkE`` to 
     451``e2.get_value_from``. 
     452 
     453``checkE`` is a function that is passed an instance and another argument we 
     454do not care about here. If the instance's ``e`` equals ``1``, the function 
     455returns value ``1``, otherwise it returns ``not 1``. Both are returned as 
     456values, not plain strings. 
     457 
     458In most circumstances the value of ``e2`` can be computed on the fly - we can 
     459pretend that the variable exists in the data, although it does not (but 
     460can be computed from it). For instance, we can compute the information gain of 
     461variable ``e2`` or its distribution without actually constructing data containing 
     462the new variable. 
     463 
     464.. literalinclude:: code/variable-get_value_from.py 
     465    :lines: 19-22 
     466 
     467There are methods which cannot compute values on the fly because it would be 
     468too complex or time consuming. In such cases, the data need to be converted 
     469to a new :obj:`Orange.data.Table`:: 
     470 
     471    new_domain = Orange.data.Domain([data.domain["a"], data.domain["b"], e2, data.domain.class_var]) 
     472    new_data = Orange.data.Table(new_domain, data) 
     473 
     474Automatic computation is useful when the data is split into training and 
     475testing examples. Training instances can be modified by adding, removing 
     476and transforming variables (in a typical setup, continuous variables 
     477are discretized prior to learning, therefore the original variables are 
     478replaced by new ones). Test instances, on the other hand, are left as they 
     479are. When they are classified, the classifier automatically converts the 
     480testing instances into the new domain, which includes recomputation of 
     481transformed variables. 
     482 
     483.. literalinclude:: code/variable-get_value_from.py 
     484    :lines: 24- 
  • docs/reference/rst/code/ensemble-forest.py

    r9638 r9734  
    88 
    99forest = Orange.ensemble.forest.RandomForestLearner(trees=50, name="forest") 
    10 tree = Orange.classification.tree.TreeLearner(minExamples=2, mForPrunning=2, \ 
    11                             sameMajorityPruning=True, name='tree') 
     10tree = Orange.classification.tree.TreeLearner(min_examples=2, m_prunning=2, \ 
     11                            same_majority_pruning=True, name='tree') 
    1212learners = [tree, forest] 
    1313 
  • docs/reference/rst/code/exclude-from-regression.txt

    r9656 r9750  
    11network-widget.py 
    22network-widget-nx.py 
     3serverfiles2.py 
     4statistics-contingency6.py 
  • docs/reference/rst/code/statistics-contingency6.py

    r9372 r9749  
    1515 
    1616 
    17 midkey = (cont.keys()[0] + cont.keys()[1])/2.0 
     17midkey = (cont.keys()[0] + cont.keys()[1]) / 2.0 
    1818print "cont[%5.3f] =" % midkey, cont[midkey] 
    1919 
  • docs/reference/rst/conf.py

    r9708 r9735  
    255255 
    256256# Example configuration for intersphinx: refer to the Python standard library. 
    257 intersphinx_mapping = {'http://docs.python.org/': None, '../tutorial': None} 
     257intersphinx_mapping = {'http://docs.python.org/': None} 
    258258 
    259259import types 
  • docs/reference/rst/index.rst

    r9534 r9729  
    66   :maxdepth: 3 
    77 
     8   Orange.data 
     9 
    810   Orange.associate 
    911 
     
    1113 
    1214   Orange.clustering 
    13  
    14    Orange.data 
    1515 
    1616   Orange.distance 
  • docs/tutorial/rst/code/bagging_test.py

    r9374 r9742  
    66 
    77import orange, orngTree, orngStat, orngTest, orngStat, bagging 
    8 data = orange.ExampleTable("../../datasets/adult_sample") 
     8data = orange.ExampleTable("adult_sample.tab") 
    99 
    1010tree = orngTree.TreeLearner(mForPrunning=10, minExamples=30) 
  • docs/tutorial/rst/code/data_characteristics.py

    r9374 r9743  
    55 
    66import orange 
    7 data = orange.ExampleTable("../../datasets/adult_sample") 
     7data = orange.ExampleTable("adult_sample.tab") 
    88print "Classes:", len(data.domain.classVar.values) 
    99print "Attributes:", len(data.domain.attributes), ",", 
    1010 
    1111# count number of continuous and discrete attributes 
    12 ncont=0; ndisc=0 
     12ncont = 0; ndisc = 0 
    1313for a in data.domain.attributes: 
    1414    if a.varType == orange.VarTypes.Discrete: 
  • docs/tutorial/rst/code/data_characteristics2.py

    r9374 r9743  
    55 
    66import orange 
    7 data = orange.ExampleTable("../../datasets/adult_sample") 
     7data = orange.ExampleTable("adult_sample.tab") 
    88print "Classes:", len(data.domain.classVar.values) 
    99print "Attributes:", len(data.domain.attributes), ",", 
    1010 
    1111# count number of continuous and discrete attributes 
    12 ncont=0; ndisc=0 
     12ncont = 0; ndisc = 0 
    1313for a in data.domain.attributes: 
    1414    if a.varType == orange.VarTypes.Discrete: 
     
    2525r = [0.] * len(c) 
    2626for i in range(len(c)): 
    27     r[i] = c[i]*100./len(data) 
     27    r[i] = c[i] * 100. / len(data) 
    2828for i in range(len(data.domain.classVar.values)): 
    2929    print ", %d(%4.1f%s) with class %s" % (c[i], r[i], '%', data.domain.classVar.values[i]), 
  • docs/tutorial/rst/code/data_characteristics3.py

    r9374 r9743  
    66 
    77import orange 
    8 data = orange.ExampleTable("../../datasets/adult_sample") 
     8data = orange.ExampleTable("adult_sample.tab") 
    99 
    1010print "Continuous attributes:" 
     
    1616                d += e[a] 
    1717                n += 1 
    18         print "  %s, mean=%3.2f" % (data.domain.attributes[a].name, d/n) 
     18        print "  %s, mean=%3.2f" % (data.domain.attributes[a].name, d / n) 
    1919 
    2020print "\nNominal attributes (contingency matrix for classes:", data.domain.classVar.values, ")" 
  • docs/tutorial/rst/code/data_characteristics4.py

    r9374 r9743  
    55 
    66import orange 
    7 data = orange.ExampleTable("../../datasets/adult_sample") 
     7data = orange.ExampleTable("adult_sample.tab") 
    88dist = orange.DomainDistributions(data) 
    99 
  • docs/tutorial/rst/code/disc1.py

    r9374 r9744  
    1010def show_values(data, heading): 
    1111  for a in data.domain.attributes: 
    12     print "%s/%d: %s" % (a.name, len(a.values), reduce(lambda x,y: x+', '+y, [i for i in a.values])) 
    13          
    14 data = orange.ExampleTable("../../datasets/wdbc") 
     12    print "%s/%d: %s" % (a.name, len(a.values), reduce(lambda x, y: x + ', ' + y, [i for i in a.values])) 
     13 
     14data = orange.ExampleTable("wdbc.tab") 
    1515print '%d features in original data set, discretized:' % len(data.domain.attributes) 
    1616data_ent = orange.Preprocessor_discretize(data, method=orange.EntropyDiscretization()) 
     
    1919print '\nFeatures with sole value after discretization:' 
    2020for a in data_ent.domain.attributes: 
    21   if len(a.values)==1: 
     21  if len(a.values) == 1: 
    2222    print a.name 
    2323 
  • docs/tutorial/rst/code/domain12.py

    r9374 r9745  
    66 
    77import orange 
    8 data = orange.ExampleTable('../../datasets/car') 
     8data = orange.ExampleTable('car.tab') 
    99 
    1010# add attribute price = f(buying, maint) 
    1111# see also http://www.ailab.si/hint/car_dataset.asp 
    1212 
    13 priceTable={} 
     13priceTable = {} 
    1414priceTable['v-high:v-high'] = 'v-high' 
    1515priceTable['high:v-high'] = 'v-high' 
     
    3434price = orange.EnumVariable("price", values=["v-high", "high", "med", "low"]) 
    3535price.getValueFrom = lambda e, getWhat: f(price, e['buying'], e['maint']) 
    36 newdomain = orange.Domain(data.domain.attributes+[price, data.domain.classVar]) 
     36newdomain = orange.Domain(data.domain.attributes + [price, data.domain.classVar]) 
    3737newdata = data.select(newdomain) 
    3838 
     
    4141  print "%10s" % a.name, 
    4242print "%10s" % newdata.domain.classVar.name 
    43 for i in [1,200,300,1200,1700]: 
     43for i in [1, 200, 300, 1200, 1700]: 
    4444  for a in newdata.domain.attributes: 
    4545    print "%10s" % newdata[i][a], 
  • docs/tutorial/rst/code/domain4.py

    r9374 r9746  
    1010  n = 0 
    1111  for i in data: 
    12     if int(i.getclass())==0: 
     12    if int(i.getclass()) == 0: 
    1313      n = n + 1 
    14   print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n)/len(data)) 
     14  print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n) / len(data)) 
    1515 
    16 filename = "../../datasets/adult_sample.tab" 
     16filename = "adult_sample.tab" 
    1717data = orange.ExampleTable(filename) 
    1818report_prob('original data set', data) 
  • docs/tutorial/rst/code/domain5.py

    r9374 r9746  
    88 
    99def report_prob(header, data): 
    10   print 'Size of %s: %i instances; ' % (header, len(data)),  
     10  print 'Size of %s: %i instances; ' % (header, len(data)), 
    1111  n = 0 
    1212  for i in data: 
    13     if int(i.getclass())==0: 
     13    if int(i.getclass()) == 0: 
    1414      n = n + 1 
    1515  if len(data): 
    16     print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n)/len(data)) 
     16    print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n) / len(data)) 
    1717  else: 
    1818    print 
    1919 
    20 filename = "../../datasets/adult_sample.tab" 
     20filename = "adult_sample.tab" 
    2121data = orange.ExampleTable(filename) 
    2222report_prob('data', data) 
  • docs/tutorial/rst/code/domain6.py

    r9374 r9746  
    88 
    99def report_prob(header, data): 
    10   print 'Size of %s: %i instances; ' % (header, len(data)),  
     10  print 'Size of %s: %i instances; ' % (header, len(data)), 
    1111  n = 0 
    1212  for i in data: 
    13     if int(i.getclass())==0: 
     13    if int(i.getclass()) == 0: 
    1414      n = n + 1 
    1515  if len(data): 
    16     print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n)/len(data)) 
     16    print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n) / len(data)) 
    1717  else: 
    1818    print 
    1919 
    20 filename = "../../datasets/adult_sample.tab" 
     20filename = "adult_sample.tab" 
    2121data = orange.ExampleTable(filename) 
    2222report_prob('data', data) 
    2323 
    24 data1 = data.select(age=(30,40)) 
     24data1 = data.select(age=(30, 40)) 
    2525report_prob('data1, age from 30 to 40', data1) 
    2626 
    27 data2 = data.select(age=(40,30)) 
     27data2 = data.select(age=(40, 30)) 
    2828report_prob('data2, younger than 30 or older than 40', data2) 
  • docs/tutorial/rst/code/domain7.py

    r9374 r9746  
    77 
    88def report_prob(header, data): 
    9   print 'Size of %s: %i instances; ' % (header, len(data)),  
     9  print 'Size of %s: %i instances; ' % (header, len(data)), 
    1010  n = 0 
    1111  for i in data: 
    12     if int(i.getclass())==0: 
     12    if int(i.getclass()) == 0: 
    1313      n = n + 1 
    1414  if len(data): 
    15     print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n)/len(data)) 
     15    print "p(%s)=%5.3f" % (data.domain.classVar.values[0], float(n) / len(data)) 
    1616  else: 
    1717    print 
    1818 
    19 filename = "../../datasets/adult_sample.tab" 
     19filename = "adult_sample.tab" 
    2020data = orange.ExampleTable(filename) 
    2121report_prob('data', data) 
    2222 
    23 selection = [1]*10 + [0]*(len(data)-10) 
     23selection = [1] * 10 + [0] * (len(data) - 10) 
    2424data1 = data.select(selection) 
    2525report_prob('data1, first ten instances', data1) 
     
    2828report_prob('data2, other than first ten instances', data2) 
    2929 
    30 selection = [1]*12 + [2]*12 + [3]*12 + [0]*(len(data)-12*3) 
     30selection = [1] * 12 + [2] * 12 + [3] * 12 + [0] * (len(data) - 12 * 3) 
    3131data3 = data.select(selection, 3) 
    3232report_prob('data3, third dozen of instances', data3) 
  • docs/tutorial/rst/code/report_missing.py

    r9374 r9747  
    55 
    66import orange 
    7 data = orange.ExampleTable("../../datasets/adult_sample") 
     7data = orange.ExampleTable("adult_sample.tab") 
    88 
    99natt = len(data.domain.attributes) 
     
    1313        if i[j].isSpecial(): 
    1414            missing[j] += 1 
    15 missing = map(lambda x, l=len(data):x/l*100., missing) 
     15missing = map(lambda x, l=len(data):x / l * 100., missing) 
    1616 
    1717print "Missing values per attribute:" 
  • docs/tutorial/rst/code/sample_adult.py

    r9374 r9747  
    66 
    77import orange 
    8 data = orange.ExampleTable("../../datasets/adult_sample") 
     8data = orange.ExampleTable("adult_sample.tab") 
    99selection = orange.MakeRandomIndices2(data, 0.03) 
    1010sample = data.select(selection, 0) 
  • install-scripts/createCommonAddOns__.btm

    r8055 r9730  
    1818  echo ************************************* 
    1919  echo *** Compiling Orange Bioinformatics for Python %pyver 
    20   cdd %TMPDIR\add-ons\Bioinformatics 
     20  cdd %TMPDIR\Bioinformatics 
    2121  del /syeq build 
    2222  del /syeq dist 
     
    2828  %PYTHON\python setup.py build -c mingw32 bdist_wininst > %COMPILELOG 
    2929  break_on_error 
    30 rem when compiled:  move /z %TMPDIR\add-ons\Bioinformatics\dist\*.win32-py%npver.exe %TMPDIR\%PKG_BIOINFORMATICS-py%npver.exe 
    31   move /z %TMPDIR\add-ons\Bioinformatics\dist\*.win32.exe %TMPDIR\%PKG_BIOINFORMATICS-py%npver.exe 
     30rem when compiled:  move /z %TMPDIR\Bioinformatics\dist\*.win32-py%npver.exe %TMPDIR\%PKG_BIOINFORMATICS-py%npver.exe 
     31  move /z %TMPDIR\Bioinformatics\dist\*.win32.exe %TMPDIR\%PKG_BIOINFORMATICS-py%npver.exe 
    3232 
    3333  REM # publish, add record to stamps_pyd.txt, needed for update from web (accessed by updateFromSVN.bat)   
     
    3535  if not direxist %TMPBINDIR mkdir /s %TMPBINDIR 
    3636   
    37   cdd %TMPDIR\add-ons\Bioinformatics\build\lib.win32-%npver 
     37  cdd %TMPDIR\Bioinformatics\build\lib.win32-%npver 
    3838  for %pydf in (*.pyd) do ( 
    3939    copy %pydf %TMPBINDIR 
     
    4949  echo ************************************* 
    5050  echo *** Compiling TEXT MINING for Python %pyver  
    51   cdd %TMPDIR\add-ons\Text 
     51  cdd %TMPDIR\Text 
    5252  del /syeq build 
    5353  del /syeq dist 
     
    5959  %PYTHON\python setup.py build -c mingw32 bdist_wininst > %COMPILELOG 
    6060  rem break_on_error 
    61   move /z %TMPDIR\add-ons\Text\dist\*.win32-py%npver.exe %TMPDIR\%PKG_TEXT-py%npver.exe 
     61  move /z %TMPDIR\Text\dist\*.win32-py%npver.exe %TMPDIR\%PKG_TEXT-py%npver.exe 
    6262 
    6363  REM # publish, add record to stamps_pyd.txt, needed for update from web (accessed by updateFromSVN.bat)   
     
    6565  if not direxist %TMPBINDIR mkdir /s %TMPBINDIR 
    6666 
    67   cdd %TMPDIR\add-ons\Text\build\lib.win32-%npver 
     67  cdd %TMPDIR\Text\build\lib.win32-%npver 
    6868  for %pydf in (*.pyd) do ( 
    6969    copy %pydf %TMPBINDIR 
  • install-scripts/createSnapshot.btm

    r8976 r9730  
    44 
    55call updateSetVariables__.btm snapshot 
    6 set WIN_SNAPSHOT=orange-win-snapshot-%daystr 
    7 set WIN_PYTHON_SNAPSHOT=orange-win-w-python-snapshot-%daystr 
     6set WIN_SNAPSHOT=orange-win-snapshot-hg-%daystr 
     7set WIN_PYTHON_SNAPSHOT=orange-win-w-python-snapshot-hg-%daystr 
    88set ADDON_BIOINFORMATICS_SNAPSHOT=orangeAddOn-bioinformatics-snapshot-%daystr 
    99set ADDON_TEXT_SNAPSHOT=orangeAddOn-text-snapshot-%daystr 
     
    1212rem # update source(s) to revision HEAD 
    1313cdd %TMPDIR 
    14 svn cleanup 
    15 svn update --ignore-externals 
     14 
     15hg pull --update 
    1616 
    1717rem # build core 
     
    2727rem # if no errors then publish on web (everything at the same time) 
    2828rem # remove any old files 
    29 except (%DOWNLOADDIR\orange*-snapshot-%daystr-*.exe) del %DOWNLOADDIR\orange*-snapshot-????-??-??-*.exe 
     29REM except (%DOWNLOADDIR\orange*-snapshot-%daystr-*.exe) del %DOWNLOADDIR\orange*-snapshot-????-??-??-*.exe 
    3030 
    3131rem # pack sources 
    3232cdd %TMPDIR 
    3333del /syeqtx sourcestopack 
    34 mkdir sourcestopack 
     34 
     35hg archive sourcestopack 
     36 
    3537cd sourcestopack 
    36 svn export --native-eol LF -q http://orange.biolab.si/svn/orange/trunk/orange 
    37 cd orange 
    38 del *.pyd *.dll *.bat 
    39 svn export --native-eol LF -q http://orange.biolab.si/svn/orange/trunk/source  
    40 copy doc\LICENSES . 
    41 copy doc\COPYING . 
    42 copy doc\LICENSES source 
    43 copy doc\COPYING source 
     38 
    4439rem # build source distribution 
    45 e:\Python26\python.exe setup.py sdist  
    46 del %DOWNLOADDIR\orange-source-snapshot-????-??-??.zip 
     40e:\Python27\python.exe setup.py sdist 
     41rem # build msi file 
     42e:\Python27\python.exe setup.py bdist_msi 
     43rem del %DOWNLOADDIR\orange-source-snapshot-????-??-??.zip 
    4744move /z dist\Orange-?.*.zip %DOWNLOADDIR\%SOURCE_SNAPSHOT 
     45move /z dist\Orange-?.*.msi %DOWNLOADDIR\%WIN_SNAPSHOT.msi 
    4846 
    4947rem # publish 
     
    5553rem # remember new filenames 
    5654cdd %SCRIPTDIR 
    57 call updateVersionsPy__.btm 
     55rem # Don't update the visible versions for now 
     56rem call updateVersionsPy__.btm 
  • install-scripts/mac/bundle-daily-build.sh

    r8908 r9731  
    1919    exit 2 
    2020fi 
     21 
     22# Clone hg repo if not yet local. 
     23if [ ! -e orange ]; then 
     24    hg clone https://bitbucket.org/biolab/orange 
     25fi 
     26 
     27cd orange 
     28hg pull --update 
     29 
     30if [ -e ../orange_archive ]; then 
     31    rm -rf ../orange_archive 
     32fi 
     33 
     34hg archive ../orange_archive 
     35cd .. 
     36 
     37ORANGE_REPO=`pwd`/orange 
     38ORANGE_ARCHIVE=`pwd`/orange_archive 
    2139 
    2240# Defaults are current latest revisions in stable branch and trunk 
     
    3250    STABLE_REVISION=$STABLE_REVISION_2 
    3351fi 
    34 DAILY_REVISION_1=${2:-`svn info --non-interactive http://orange.biolab.si/svn/orange/trunk/ | grep 'Last Changed Rev:' | cut -d ' ' -f 4`} 
    35 # svn info does not return proper exit status on an error so we check it this way 
    36 [ "$DAILY_REVISION_1" ] || exit 4 
    37 DAILY_REVISION_2=${2:-`svn info --non-interactive http://orange.biolab.si/svn/orange/externals/trunk/ | grep 'Last Changed Rev:' | cut -d ' ' -f 4`} 
    38 # svn info does not return proper exit status on an error so we check it this way 
    39 [ "$DAILY_REVISION_2" ] || exit 4 
    40 if [[ $DAILY_REVISION_1 -gt $DAILY_REVISION_2 ]]; then 
    41     DAILY_REVISION=$DAILY_REVISION_1 
    42 else 
    43     DAILY_REVISION=$DAILY_REVISION_2 
    44 fi 
     52 
     53DAILY_REVISION_1 = `hg log -l1 daily | grep 'changeset:' | cut -d ' ' -f 4 | cut -d ':' -f 1` 
     54 
     55#TODO: versions of hg and svn repos are no longer in sync 
     56 
     57#DAILY_REVISION_2=${2:-`svn info --non-interactive http://orange.biolab.si/svn/orange/externals/trunk/ | grep 'Last Changed Rev:' | cut -d ' ' -f 4`} 
     58## svn info does not return proper exit status on an error so we check it this way 
     59#[ "$DAILY_REVISION_2" ] || exit 4 
     60#if [[ $DAILY_REVISION_1 -gt $DAILY_REVISION_2 ]]; then 
     61#    DAILY_REVISION=$DAILY_REVISION_1 
     62#else 
     63#    DAILY_REVISION=$DAILY_REVISION_2 
     64#fi 
    4565 
    4666echo "Preparing temporary directory." 
     
    5474export CXXFLAGS="-arch ppc -arch i386" 
    5575export LDFLAGS="-arch ppc -arch i386" 
     76 
     77 
     78########################### 
     79# Stable orange-1.0  bundle 
     80########################### 
    5681 
    5782if [ ! -e /Volumes/download/orange-bundle-1.0b.$STABLE_REVISION.dmg ]; then 
     
    174199/Users/ailabc/mount-dirs.sh 
    175200 
    176 if [ ! -e /Volumes/download/orange-bundle-svn-0.0.$DAILY_REVISION.dmg ]; then 
     201######################### 
     202# Daily orange 2.* bundle 
     203######################### 
     204 
     205if [ ! -e /Volumes/download/orange-bundle-hg-0.0.$DAILY_REVISION.dmg ]; then 
    177206    echo "Downloading bundle template." 
    178207    svn export --non-interactive --revision $DAILY_REVISION http://orange.biolab.si/svn/orange/externals/trunk/install-scripts/mac/bundle/ /private/tmp/bundle/ 
    179208     
    180     echo "Downloading Orange daily source code revision $DAILY_REVISION." 
    181     svn export --non-interactive --revision $DAILY_REVISION http://orange.biolab.si/svn/orange/trunk/orange/ /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/ 
    182     svn export --non-interactive --revision $DAILY_REVISION http://orange.biolab.si/svn/orange/trunk/source/ /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/source/ 
    183     svn export --non-interactive --revision $DAILY_REVISION http://orange.biolab.si/svn/orange/trunk/add-ons/orngCRS/src/ /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/source/crs/ 
    184      
    185     [ -e /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/doc/COPYING ] || svn export --non-interactive --revision $DAILY_REVISION http://orange.biolab.si/svn/orange/trunk/COPYING /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/doc/COPYING 
    186     [ -e /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/doc/LICENSES ] || svn export --non-interactive --revision $DAILY_REVISION http://orange.biolab.si/svn/orange/trunk/LICENSES /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/doc/LICENSES 
    187      
    188     ln -s ../Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/ /private/tmp/bundle/Orange.app/Contents/Resources/orange 
    189     ln -s ../Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/doc/ /private/tmp/bundle/Orange.app/Contents/Resources/doc 
    190      
    191     echo "Compiling." 
    192     cd /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/source/ 
    193     make EXCLUDE_ORANGEQT=1 
    194     cd /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/source/crs/ 
    195     make 
    196     mv _orngCRS.so ../../ 
    197     cd /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/ 
    198      
    199     echo "Correcting install names for modules." 
    200     for module in *.so ; do 
    201         [ -L $module ] && continue 
    202          
    203         install_name_tool -id @executable_path/../Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/$module $module 
    204          
    205         perl -MFile::Spec::Functions=abs2rel -e ' 
    206         for (`/usr/bin/otool -L -X $ARGV[0]`) { 
    207             next unless m|^\s+(/private/tmp/bundle/Orange.app/.*) \(.*\)$|; 
    208             system("/usr/bin/install_name_tool", "-change", $1, "\@loader_path/" . abs2rel($1), $ARGV[0]);  
    209         } 
    210         ' $module 
    211     done 
    212      
    213     echo "Cleaning up." 
    214     rm -rf source/ c45.dll liborange_include.a updateOrange.py 
     209    echo "Building and installing orange into the bundle." 
     210    cd $ORANGE_ARCHIVE 
     211    /private/tmp/bundle/Orange.app/Contents/MacOS/python setup.py install 
     212         
     213#   echo "Correcting install names for modules." 
     214#   for module in *.so ; do 
     215#       [ -L $module ] && continue 
     216#        
     217#       install_name_tool -id @executable_path/../Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange/$module $module 
     218#        
     219#       perl -MFile::Spec::Functions=abs2rel -e ' 
     220#       for (`/usr/bin/otool -L -X $ARGV[0]`) { 
     221#           next unless m|^\s+(/private/tmp/bundle/Orange.app/.*) \(.*\)$|; 
     222#           system("/usr/bin/install_name_tool", "-change", $1, "\@loader_path/" . abs2rel($1), $ARGV[0]);  
     223#       } 
     224#       ' $module 
     225#   done 
     226     
     227#   echo "Cleaning up." 
     228#   rm -rf source/ c45.dll liborange_include.a updateOrange.py 
    215229     
    216230    # Installation registration 
    217     echo "orange" > /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange.pth 
    218      
     231#   echo "orange" > /private/tmp/bundle/Orange.app/Contents/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/orange.pth 
     232     
     233    # TODO: hg repos for addons 
    219234    for addon in $DAILY_ADDONS ; do 
    220235        echo "Downloading Orange add-on $addon daily source code revision $DAILY_REVISION." 
     
    245260        fi 
    246261         
    247         echo "Cleaning up." 
    248         rm -rf source/ setup.py 
     262#       echo "Cleaning up." 
     263#       rm -rf source/ setup.py 
    249264         
    250265        # Installation registration 
     
    282297     
    283298    echo "Converting temporary image to a compressed image." 
    284     rm -f /private/tmp/orange-bundle-svn-0.0.$DAILY_REVISION.dmg 
    285     hdiutil convert /private/tmp/bundle.dmg -format UDZO -imagekey zlib-level=9 -o /private/tmp/orange-bundle-svn-0.0.$DAILY_REVISION.dmg 
     299    rm -f /private/tmp/orange-bundle-hg-0.0.$DAILY_REVISION.dmg 
     300    hdiutil convert /private/tmp/bundle.dmg -format UDZO -imagekey zlib-level=9 -o /private/tmp/orange-bundle-hg-0.0.$DAILY_REVISION.dmg 
    286301     
    287302    echo "Cleaning up." 
     
    295310echo "Removing old versions of bundles." 
    296311# (Keeps last 5 versions.) 
    297 perl -e 'unlink ((reverse sort </Volumes/download/orange-bundle-svn-0*.dmg>)[5..10000])' 
     312perl -e 'unlink ((reverse sort </Volumes/download/orange-bundle-hg-0*.dmg>)[5..10000])' 
    298313perl -e 'unlink ((reverse sort </Volumes/download/orange-bundle-1*.dmg>)[5..10000])' 
    299314 
    300 if [ -e /private/tmp/orange-bundle-svn-0.0.$DAILY_REVISION.dmg ] || [ -e /private/tmp/orange-bundle-svn-0.0.$DAILY_REVISION.dmg ]; then 
     315if [ -e /private/tmp/orange-bundle-hg-0.0.$DAILY_REVISION.dmg ] || [ -e /private/tmp/orange-bundle-hg-0.0.$DAILY_REVISION.dmg ]; then 
    301316    echo "Moving bundles to the download directory." 
    302317    [ -e /private/tmp/orange-bundle-1.0b.$STABLE_REVISION.dmg ] && mv /private/tmp/orange-bundle-1.0b.$STABLE_REVISION.dmg /Volumes/download/ 
    303     [ -e /private/tmp/orange-bundle-svn-0.0.$DAILY_REVISION.dmg ] && mv /private/tmp/orange-bundle-svn-0.0.$DAILY_REVISION.dmg /Volumes/download/ 
     318    [ -e /private/tmp/orange-bundle-hg-0.0.$DAILY_REVISION.dmg ] && mv /private/tmp/orange-bundle-hg-0.0.$DAILY_REVISION.dmg /Volumes/download/ 
    304319     
    305320    echo "Setting permissions." 
    306321    chmod +r /Volumes/download/orange-bundle-1.0b.$STABLE_REVISION.dmg 
    307     chmod +r /Volumes/download/orange-bundle-svn-0.0.$DAILY_REVISION.dmg 
    308      
    309     echo "Registering new bundles." 
    310     egrep -v '^(MAC_STABLE|MAC_DAILY)=' /Volumes/download/filenames_mac.set > /Volumes/download/filenames_mac.set.new 
    311     echo "MAC_STABLE=orange-bundle-1.0b.$STABLE_REVISION.dmg" >> /Volumes/download/filenames_mac.set.new 
    312     echo "MAC_DAILY=orange-bundle-svn-0.0.$DAILY_REVISION.dmg" >> /Volumes/download/filenames_mac.set.new 
    313     mv /Volumes/download/filenames_mac.set.new /Volumes/download/filenames_mac.set 
    314 fi 
     322    chmod +r /Volumes/download/orange-bundle-hg-0.0.$DAILY_REVISION.dmg 
     323 
     324# Don't register the bundles until hg version stabilizes 
     325     
     326#   echo "Registering new bundles." 
     327#   egrep -v '^(MAC_STABLE|MAC_DAILY)=' /Volumes/download/filenames_mac.set > /Volumes/download/filenames_mac.set.new 
     328#   echo "MAC_STABLE=orange-bundle-1.0b.$STABLE_REVISION.dmg" >> /Volumes/download/filenames_mac.set.new 
     329#   echo "MAC_DAILY=orange-bundle-svn-0.0.$DAILY_REVISION.dmg" >> /Volumes/download/filenames_mac.set.new 
     330#   mv /Volumes/download/filenames_mac.set.new /Volumes/download/filenames_mac.set 
     331fi 
  • install-scripts/mac/update-all-scripts.sh

    r7694 r9731  
    44# 
    55 
    6 curl --silent --output update-all-scripts.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/update-all-scripts.sh 
    7 curl --silent --output bundle-64bit-daily-build.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/bundle-64bit-daily-build.sh 
    8 curl --silent --output bundle-daily-build.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/bundle-daily-build.sh 
    9 curl --silent --output dailyrun.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/dailyrun.sh 
    10 curl --silent --output dailyrun-finkonly-withsource.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/dailyrun-finkonly-withsource.sh 
    11 curl --silent --output dailyrun-finkonly.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/dailyrun-finkonly.sh 
    12 curl --silent --output dailyrun-bundleonly.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/dailyrun-bundleonly.sh 
    13 curl --silent --output fink-daily-build.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/fink-daily-build.sh 
    14 curl --silent --output fink-restore-selections.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/fink-restore-selections.sh 
    15 curl --silent --output fink-selfupdate-orange.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/fink-selfupdate-orange.sh 
    16 curl --silent --output force-fink-daily-build.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/force-fink-daily-build.sh 
    17 curl --silent --output mount-dirs.sh http://orange.biolab.si/svn/orange/trunk/install-scripts/mac/mount-dirs.sh 
     6# Clone the orange repo if not already present 
     7if [ ! -e orange ]; then 
     8    hg clone https://bitbucket.org/biolab/orange 
     9fi 
     10 
     11# Pull all changesets and update to latest 
     12cd orange 
     13hg pull --update 
     14cd .. 
     15 
     16cp orange/install-scripts/mac/update-all-scripts.sh ./ 
     17cp orange/install-scripts/mac/bundle-64bit-daily-build.sh ./ 
     18cp orange/install-scripts/mac/bundle-daily-build.sh ./ 
     19cp orange/install-scripts/mac/dailyrun.sh ./ 
     20cp orange/install-scripts/mac/dailyrun-finkonly-withsource.sh ./ 
     21cp orange/install-scripts/mac/dailyrun-finkonly.sh ./ 
     22cp orange/install-scripts/mac/dailyrun-bundleonly.sh ./ 
     23cp orange/install-scripts/mac/fink-daily-build.sh ./ 
     24cp orange/install-scripts/mac/fink-restore-selections.sh ./ 
     25cp orange/install-scripts/mac/fink-selfupdate-orange.sh ./ 
     26cp orange/install-scripts/mac/force-fink-daily-build.sh ./ 
     27cp orange/install-scripts/mac/mount-dirs.sh ./ 
    1828 
    1929chmod +x *.sh 
  • install-scripts/updateAndCall.btm

    r7692 r9730  
    1 net use o: \\ailab.si\download 
     1 
    22cdd e:\orange\scripts 
    3 svn update -N 
    4 svn export http://orange.biolab.si/svn/orange/trunk/orange/doc/LICENSES license.txt 
    5 svn  
     3 
     4 
     5REM # Until orange-install-scripts repo is up this does not yet run 
     6REM hg clone https://bitbucket.org/biolab/orange-install-scripts . 
     7REM hg pull --update  
     8 
     9REM hg clone https://bitbucket.org/biolab/orange snapshot 
     10cdd snapshot 
     11hg pull --update 
     12 
     13REM hg clone https://bitbucket.org/biolab/orange-addon-bioinformatics Bioinformatics 
     14cdd Bioinformatics 
     15hg pull --update 
     16 
     17cdd  e:\orange\scripts\snapshot 
     18 
     19REM hg clone https://bitbucket.org/biolab/orange-addon-text Text 
     20cdd Text 
     21hg pull --update 
     22 
     23cdd e:\orange\scripts 
     24 
     25copy /r snapshot\install-scripts\* . 
     26 
     27#svn update -N 
     28#svn export http://orange.biolab.si/svn/orange/trunk/orange/doc/LICENSES license.txt 
     29#svn 
     30  
    631call callCreateSnapshot.btm 
    732shutdown -s 
  • install-scripts/updateSetVariables__.btm

    r8739 r9730  
    77set SCRIPTDIR=%_CWD 
    88set TMPDIR=%SCRIPTDIR\%1 
     9set SOURCEDIR=%TMPDIR\source 
    910set DOWNLOADDIR=Z:\Volumes\download\ 
    1011 
  • source/orangeqt/Makefile

    r9752 r9753  
    1 # CMAKE generated file: DO NOT EDIT! 
    2 # Generated by "Unix Makefiles" Generator, CMake Version 2.8 
     1ORANGEQT_BUILD_DIR=build 
     2ifndef OLD 
     3  OLD=.. 
     4endif 
     5ifndef PYTHON 
     6  PYTHON=$(shell which python) 
     7endif 
    38 
    4 # Default target executed when no arguments are given to make. 
    5 default_target: all 
    6 .PHONY : default_target 
     9PYTHON_VERSION = $(shell $(PYTHON) -c 'import sys; print "%s.%s" % sys.version_info[:2]') 
     10OS = $(shell uname) 
    711 
    8 #============================================================================= 
    9 # Special targets provided by cmake. 
     12all: 
     13    mkdir -p $(ORANGEQT_BUILD_DIR) 
     14    cd $(ORANGEQT_BUILD_DIR); cmake -DCMAKE_BUILD_TYPE=Release -DORANGE_LIB_DIR=$(abspath $(OLD)) -DPYTHON_EXECUTABLE=$(PYTHON) -DCMAKE_USE_PYTHON_VERSION=$(PYTHON_VERSION) $(EXTRA_ORANGEQT_CMAKE_ARGS) .. 
     15    if ! $(MAKE) $@ -C $(ORANGEQT_BUILD_DIR); then exit 1; fi; 
     16ifeq ($(OS), Darwin) 
     17    install_name_tool -id $(DESTDIR)/orangeqt.so $(OLD)/orangeqt.so 
     18endif 
     19     
    1020 
    11 # Disable implicit rules so canoncical targets will work. 
    12 .SUFFIXES: 
     21cleantemp: 
     22    rm -rf $(ORANGEQT_BUILD_DIR) 
    1323 
    14 # Remove some rules from gmake that .SUFFIXES does not remove. 
    15 SUFFIXES = 
    16  
    17 .SUFFIXES: .hpux_make_needs_suffix_list 
    18  
    19 # Suppress display of executed commands. 
    20 $(VERBOSE).SILENT: 
    21  
    22 # A target that is always out of date. 
    23 cmake_force: 
    24 .PHONY : cmake_force 
    25  
    26 #============================================================================= 
    27 # Set environment variables for the build. 
    28  
    29 # The shell in which to execute make rules. 
    30 SHELL = /bin/sh 
    31  
    32 # The CMake executable. 
    33 CMAKE_COMMAND = /usr/bin/cmake 
    34  
    35 # The command to remove a file. 
    36 RM = /usr/bin/cmake -E remove -f 
    37  
    38 # The top-level source directory on which CMake was run. 
    39 CMAKE_SOURCE_DIR = /home/marko/orangehg/source/orangeqt 
    40  
    41 # The top-level build directory on which CMake was run. 
    42 CMAKE_BINARY_DIR = /home/marko/orangehg/source/orangeqt 
    43  
    44 #============================================================================= 
    45 # Targets provided globally by CMake. 
    46  
    47 # Special rule for the target edit_cache 
    48 edit_cache: 
    49     @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running interactive CMake command-line interface..." 
    50     /usr/bin/cmake -i . 
    51 .PHONY : edit_cache 
    52  
    53 # Special rule for the target edit_cache 
    54 edit_cache/fast: edit_cache 
    55 .PHONY : edit_cache/fast 
    56  
    57 # Special rule for the target install 
    58 install: preinstall 
    59     @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." 
    60     /usr/bin/cmake -P cmake_install.cmake 
    61 .PHONY : install 
    62  
    63 # Special rule for the target install 
    64 install/fast: preinstall/fast 
    65     @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..." 
    66     /usr/bin/cmake -P cmake_install.cmake 
    67 .PHONY : install/fast 
    68  
    69 # Special rule for the target install/local 
    70 install/local: preinstall 
    71     @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..." 
    72     /usr/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake 
    73 .PHONY : install/local 
    74  
    75 # Special rule for the target install/local 
    76 install/local/fast: install/local 
    77 .PHONY : install/local/fast 
    78  
    79 # Special rule for the target install/strip 
    80 install/strip: preinstall 
    81     @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..." 
    82     /usr/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake 
    83 .PHONY : install/strip 
    84  
    85 # Special rule for the target install/strip 
    86 install/strip/fast: install/strip 
    87 .PHONY : install/strip/fast 
    88  
    89 # Special rule for the target list_install_components 
    90 list_install_components: 
    91     @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\"" 
    92 .PHONY : list_install_components 
    93  
    94 # Special rule for the target list_install_components 
    95 list_install_components/fast: list_install_components 
    96 .PHONY : list_install_components/fast 
    97  
    98 # Special rule for the target rebuild_cache 
    99 rebuild_cache: 
    100     @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..." 
    101     /usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) 
    102 .PHONY : rebuild_cache 
    103  
    104 # Special rule for the target rebuild_cache 
    105 rebuild_cache/fast: rebuild_cache 
    106 .PHONY : rebuild_cache/fast 
    107  
    108 # The main all target 
    109 all: cmake_check_build_system 
    110     $(CMAKE_COMMAND) -E cmake_progress_start /home/marko/orangehg/source/orangeqt/CMakeFiles /home/marko/orangehg/source/orangeqt/CMakeFiles/progress.marks 
    111     $(MAKE) -f CMakeFiles/Makefile2 all 
    112     $(CMAKE_COMMAND) -E cmake_progress_start /home/marko/orangehg/source/orangeqt/CMakeFiles 0 
    113 .PHONY : all 
    114  
    115 # The main clean target 
    116 clean: 
    117     $(MAKE) -f CMakeFiles/Makefile2 clean 
    118 .PHONY : clean 
    119  
    120 # The main clean target 
    121 clean/fast: clean 
    122 .PHONY : clean/fast 
    123  
    124 # Prepare targets for installation. 
    125 preinstall: all 
    126     $(MAKE) -f CMakeFiles/Makefile2 preinstall 
    127 .PHONY : preinstall 
    128  
    129 # Prepare targets for installation. 
    130 preinstall/fast: 
    131     $(MAKE) -f CMakeFiles/Makefile2 preinstall 
    132 .PHONY : preinstall/fast 
    133  
    134 # clear depends 
    135 depend: 
    136     $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1 
    137 .PHONY : depend 
    138  
    139 #============================================================================= 
    140 # Target rules for targets named python_module_orangeqt 
    141  
    142 # Build rule for target. 
    143 python_module_orangeqt: cmake_check_build_system 
    144     $(MAKE) -f CMakeFiles/Makefile2 python_module_orangeqt 
    145 .PHONY : python_module_orangeqt 
    146  
    147 # fast build rule for target. 
    148 python_module_orangeqt/fast: 
    149     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/build 
    150 .PHONY : python_module_orangeqt/fast 
    151  
    152 canvas3d.o: canvas3d.cpp.o 
    153 .PHONY : canvas3d.o 
    154  
    155 # target to build an object file 
    156 canvas3d.cpp.o: 
    157     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/canvas3d.cpp.o 
    158 .PHONY : canvas3d.cpp.o 
    159  
    160 canvas3d.i: canvas3d.cpp.i 
    161 .PHONY : canvas3d.i 
    162  
    163 # target to preprocess a source file 
    164 canvas3d.cpp.i: 
    165     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/canvas3d.cpp.i 
    166 .PHONY : canvas3d.cpp.i 
    167  
    168 canvas3d.s: canvas3d.cpp.s 
    169 .PHONY : canvas3d.s 
    170  
    171 # target to generate assembly for a file 
    172 canvas3d.cpp.s: 
    173     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/canvas3d.cpp.s 
    174 .PHONY : canvas3d.cpp.s 
    175  
    176 curve.o: curve.cpp.o 
    177 .PHONY : curve.o 
    178  
    179 # target to build an object file 
    180 curve.cpp.o: 
    181     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/curve.cpp.o 
    182 .PHONY : curve.cpp.o 
    183  
    184 curve.i: curve.cpp.i 
    185 .PHONY : curve.i 
    186  
    187 # target to preprocess a source file 
    188 curve.cpp.i: 
    189     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/curve.cpp.i 
    190 .PHONY : curve.cpp.i 
    191  
    192 curve.s: curve.cpp.s 
    193 .PHONY : curve.s 
    194  
    195 # target to generate assembly for a file 
    196 curve.cpp.s: 
    197     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/curve.cpp.s 
    198 .PHONY : curve.cpp.s 
    199  
    200 glextensions.o: glextensions.cpp.o 
    201 .PHONY : glextensions.o 
    202  
    203 # target to build an object file 
    204 glextensions.cpp.o: 
    205     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/glextensions.cpp.o 
    206 .PHONY : glextensions.cpp.o 
    207  
    208 glextensions.i: glextensions.cpp.i 
    209 .PHONY : glextensions.i 
    210  
    211 # target to preprocess a source file 
    212 glextensions.cpp.i: 
    213     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/glextensions.cpp.i 
    214 .PHONY : glextensions.cpp.i 
    215  
    216 glextensions.s: glextensions.cpp.s 
    217 .PHONY : glextensions.s 
    218  
    219 # target to generate assembly for a file 
    220 glextensions.cpp.s: 
    221     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/glextensions.cpp.s 
    222 .PHONY : glextensions.cpp.s 
    223  
    224 multicurve.o: multicurve.cpp.o 
    225 .PHONY : multicurve.o 
    226  
    227 # target to build an object file 
    228 multicurve.cpp.o: 
    229     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/multicurve.cpp.o 
    230 .PHONY : multicurve.cpp.o 
    231  
    232 multicurve.i: multicurve.cpp.i 
    233 .PHONY : multicurve.i 
    234  
    235 # target to preprocess a source file 
    236 multicurve.cpp.i: 
    237     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/multicurve.cpp.i 
    238 .PHONY : multicurve.cpp.i 
    239  
    240 multicurve.s: multicurve.cpp.s 
    241 .PHONY : multicurve.s 
    242  
    243 # target to generate assembly for a file 
    244 multicurve.cpp.s: 
    245     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/multicurve.cpp.s 
    246 .PHONY : multicurve.cpp.s 
    247  
    248 networkcurve.o: networkcurve.cpp.o 
    249 .PHONY : networkcurve.o 
    250  
    251 # target to build an object file 
    252 networkcurve.cpp.o: 
    253     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/networkcurve.cpp.o 
    254 .PHONY : networkcurve.cpp.o 
    255  
    256 networkcurve.i: networkcurve.cpp.i 
    257 .PHONY : networkcurve.i 
    258  
    259 # target to preprocess a source file 
    260 networkcurve.cpp.i: 
    261     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/networkcurve.cpp.i 
    262 .PHONY : networkcurve.cpp.i 
    263  
    264 networkcurve.s: networkcurve.cpp.s 
    265 .PHONY : networkcurve.s 
    266  
    267 # target to generate assembly for a file 
    268 networkcurve.cpp.s: 
    269     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/networkcurve.cpp.s 
    270 .PHONY : networkcurve.cpp.s 
    271  
    272 plot.o: plot.cpp.o 
    273 .PHONY : plot.o 
    274  
    275 # target to build an object file 
    276 plot.cpp.o: 
    277     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plot.cpp.o 
    278 .PHONY : plot.cpp.o 
    279  
    280 plot.i: plot.cpp.i 
    281 .PHONY : plot.i 
    282  
    283 # target to preprocess a source file 
    284 plot.cpp.i: 
    285     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plot.cpp.i 
    286 .PHONY : plot.cpp.i 
    287  
    288 plot.s: plot.cpp.s 
    289 .PHONY : plot.s 
    290  
    291 # target to generate assembly for a file 
    292 plot.cpp.s: 
    293     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plot.cpp.s 
    294 .PHONY : plot.cpp.s 
    295  
    296 plot3d.o: plot3d.cpp.o 
    297 .PHONY : plot3d.o 
    298  
    299 # target to build an object file 
    300 plot3d.cpp.o: 
    301     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plot3d.cpp.o 
    302 .PHONY : plot3d.cpp.o 
    303  
    304 plot3d.i: plot3d.cpp.i 
    305 .PHONY : plot3d.i 
    306  
    307 # target to preprocess a source file 
    308 plot3d.cpp.i: 
    309     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plot3d.cpp.i 
    310 .PHONY : plot3d.cpp.i 
    311  
    312 plot3d.s: plot3d.cpp.s 
    313 .PHONY : plot3d.s 
    314  
    315 # target to generate assembly for a file 
    316 plot3d.cpp.s: 
    317     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plot3d.cpp.s 
    318 .PHONY : plot3d.cpp.s 
    319  
    320 plotitem.o: plotitem.cpp.o 
    321 .PHONY : plotitem.o 
    322  
    323 # target to build an object file 
    324 plotitem.cpp.o: 
    325     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plotitem.cpp.o 
    326 .PHONY : plotitem.cpp.o 
    327  
    328 plotitem.i: plotitem.cpp.i 
    329 .PHONY : plotitem.i 
    330  
    331 # target to preprocess a source file 
    332 plotitem.cpp.i: 
    333     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plotitem.cpp.i 
    334 .PHONY : plotitem.cpp.i 
    335  
    336 plotitem.s: plotitem.cpp.s 
    337 .PHONY : plotitem.s 
    338  
    339 # target to generate assembly for a file 
    340 plotitem.cpp.s: 
    341     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/plotitem.cpp.s 
    342 .PHONY : plotitem.cpp.s 
    343  
    344 point.o: point.cpp.o 
    345 .PHONY : point.o 
    346  
    347 # target to build an object file 
    348 point.cpp.o: 
    349     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/point.cpp.o 
    350 .PHONY : point.cpp.o 
    351  
    352 point.i: point.cpp.i 
    353 .PHONY : point.i 
    354  
    355 # target to preprocess a source file 
    356 point.cpp.i: 
    357     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/point.cpp.i 
    358 .PHONY : point.cpp.i 
    359  
    360 point.s: point.cpp.s 
    361 .PHONY : point.s 
    362  
    363 # target to generate assembly for a file 
    364 point.cpp.s: 
    365     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/point.cpp.s 
    366 .PHONY : point.cpp.s 
    367  
    368 siporangeqtpart0.o: siporangeqtpart0.cpp.o 
    369 .PHONY : siporangeqtpart0.o 
    370  
    371 # target to build an object file 
    372 siporangeqtpart0.cpp.o: 
    373     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/siporangeqtpart0.cpp.o 
    374 .PHONY : siporangeqtpart0.cpp.o 
    375  
    376 siporangeqtpart0.i: siporangeqtpart0.cpp.i 
    377 .PHONY : siporangeqtpart0.i 
    378  
    379 # target to preprocess a source file 
    380 siporangeqtpart0.cpp.i: 
    381     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/siporangeqtpart0.cpp.i 
    382 .PHONY : siporangeqtpart0.cpp.i 
    383  
    384 siporangeqtpart0.s: siporangeqtpart0.cpp.s 
    385 .PHONY : siporangeqtpart0.s 
    386  
    387 # target to generate assembly for a file 
    388 siporangeqtpart0.cpp.s: 
    389     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/siporangeqtpart0.cpp.s 
    390 .PHONY : siporangeqtpart0.cpp.s 
    391  
    392 unconnectedlinescurve.o: unconnectedlinescurve.cpp.o 
    393 .PHONY : unconnectedlinescurve.o 
    394  
    395 # target to build an object file 
    396 unconnectedlinescurve.cpp.o: 
    397     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/unconnectedlinescurve.cpp.o 
    398 .PHONY : unconnectedlinescurve.cpp.o 
    399  
    400 unconnectedlinescurve.i: unconnectedlinescurve.cpp.i 
    401 .PHONY : unconnectedlinescurve.i 
    402  
    403 # target to preprocess a source file 
    404 unconnectedlinescurve.cpp.i: 
    405     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/unconnectedlinescurve.cpp.i 
    406 .PHONY : unconnectedlinescurve.cpp.i 
    407  
    408 unconnectedlinescurve.s: unconnectedlinescurve.cpp.s 
    409 .PHONY : unconnectedlinescurve.s 
    410  
    411 # target to generate assembly for a file 
    412 unconnectedlinescurve.cpp.s: 
    413     $(MAKE) -f CMakeFiles/python_module_orangeqt.dir/build.make CMakeFiles/python_module_orangeqt.dir/unconnectedlinescurve.cpp.s 
    414 .PHONY : unconnectedlinescurve.cpp.s 
    415  
    416 # Help Target 
    417 help: 
    418     @echo "The following are some of the valid targets for this Makefile:" 
    419     @echo "... all (the default if no target is provided)" 
    420     @echo "... clean" 
    421     @echo "... depend" 
    422     @echo "... edit_cache" 
    423     @echo "... install" 
    424     @echo "... install/local" 
    425     @echo "... install/strip" 
    426     @echo "... list_install_components" 
    427     @echo "... python_module_orangeqt" 
    428     @echo "... rebuild_cache" 
    429     @echo "... canvas3d.o" 
    430     @echo "... canvas3d.i" 
    431     @echo "... canvas3d.s" 
    432     @echo "... curve.o" 
    433     @echo "... curve.i" 
    434     @echo "... curve.s" 
    435     @echo "... glextensions.o" 
    436     @echo "... glextensions.i" 
    437     @echo "... glextensions.s" 
    438     @echo "... multicurve.o" 
    439     @echo "... multicurve.i" 
    440     @echo "... multicurve.s" 
    441     @echo "... networkcurve.o" 
    442     @echo "... networkcurve.i" 
    443     @echo "... networkcurve.s" 
    444     @echo "... plot.o" 
    445     @echo "... plot.i" 
    446     @echo "... plot.s" 
    447     @echo "... plot3d.o" 
    448     @echo "... plot3d.i" 
    449     @echo "... plot3d.s" 
    450     @echo "... plotitem.o" 
    451     @echo "... plotitem.i" 
    452     @echo "... plotitem.s" 
    453     @echo "... point.o" 
    454     @echo "... point.i" 
    455     @echo "... point.s" 
    456     @echo "... siporangeqtpart0.o" 
    457     @echo "... siporangeqtpart0.i" 
    458     @echo "... siporangeqtpart0.s" 
    459     @echo "... unconnectedlinescurve.o" 
    460     @echo "... unconnectedlinescurve.i" 
    461     @echo "... unconnectedlinescurve.s" 
    462 .PHONY : help 
    463  
    464  
    465  
    466 #============================================================================= 
    467 # Special targets to cleanup operation of make. 
    468