Ignore:
Files:
3 added
14 deleted
28 edited

Legend:

Unmodified
Added
Removed
  • Orange/OrangeWidgets/OWNxHist.py

    r10499 r10516  
    3030        self.andor = 0 
    3131        self.matrix = None 
    32         self.excludeLimit = 1 
     32        self.excludeLimit = 2 
    3333        self.percentil = 0 
     34 
     35        self.graph = None 
     36        self.graph_matrix = None 
    3437 
    3538        if parent is None: 
     
    5861        hb = OWGUI.widgetBox(ribg, None, orientation="horizontal", addSpace=False) 
    5962        OWGUI.appendRadioButton(ribg, self, "netOption", "Large components only. Min nodes:", insertInto=hb, callback=self.generateGraph) 
    60         OWGUI.spin(hb, self, "excludeLimit", 1, 100, 1, callback=(lambda h=True: self.generateGraph(h))) 
     63        OWGUI.spin(hb, self, "excludeLimit", 2, 100, 1, callback=(lambda h=True: self.generateGraph(h))) 
    6164        OWGUI.appendRadioButton(ribg, self, "netOption", "Largest connected component only", callback=self.generateGraph) 
    6265        OWGUI.appendRadioButton(ribg, self, "netOption", "Connected component with vertex") 
     
    7881 
    7982    def setPercentil(self): 
     83        if self.matrix is None or self.percentil <= 0: 
     84            return 
     85 
    8086        self.spinLowerThreshold = self.histogram.minValue 
    8187        # flatten matrix, sort values and remove identities (self.matrix[i][i]) 
     
    94100    def setMatrix(self, data): 
    95101        if data == None: return 
     102 
     103        if not hasattr(data, "items") or data.items is None: 
     104            setattr(data, "items", [i for i in range(data.dim)]) 
    96105 
    97106        self.matrix = data 
     
    105114        upp = max(values) 
    106115        self.spinLowerThreshold = self.spinUpperThreshold = math.floor(low - (0.03 * (upp - low))) 
    107         self.generateGraph() 
     116 
    108117        self.attributeCombo.clear() 
    109118        vars = [] 
     
    125134            except: 
    126135                print "error adding ", var, " to the attribute combo" 
     136 
     137        self.setPercentil() 
     138        self.generateGraph() 
    127139 
    128140    def changeLowerSpin(self): 
     
    180192            matrix = self.matrix 
    181193 
    182             if hasattr(self.matrix, "items"): 
     194            if hasattr(self.matrix, "items") and self.matrix.items is not None: 
    183195                if type(self.matrix.items) == Orange.data.Table: 
    184196                    graph.set_items(self.matrix.items) 
     
    202214            # exclude unconnected 
    203215            if str(self.netOption) == '1': 
    204                 components = [x for x in Orange.network.nx.algorithms.components.connected_components(graph) if len(x) > self.excludeLimit] 
     216                components = [x for x in Orange.network.nx.algorithms.components.connected_components(graph) if len(x) >= self.excludeLimit] 
    205217                if len(components) > 0: 
    206218                    include = reduce(lambda x, y: x + y, components) 
     
    218230                component = Orange.network.nx.algorithms.components.connected_components(graph)[0] 
    219231                if len(component) > 1: 
    220                     self.graph = graph.subgraph(include) 
     232                    self.graph = graph.subgraph(component) 
    221233                    matrix = self.matrix.getitems(component) 
    222234                else: 
  • Orange/OrangeWidgets/Prototypes/OWBR.py

    r9671 r10502  
    5959 
    6060        if not Orange.multilabel.is_multilabel(data): 
    61             self.warning(0, "Multi-label data is expected on the input.") 
     61            self.warning(0, "Multi-label data with class values 0 and 1 is " 
     62                            "expected on the input.") 
    6263            return 
    6364        self.warning(0, None) 
  • Orange/OrangeWidgets/Prototypes/OWBRkNN.py

    r9671 r10502  
    6363 
    6464        if not Orange.multilabel.is_multilabel(data): 
    65             self.warning(0, "Multi-label data is expected on the input.") 
     65            self.warning(0, "Multi-label data with class values 0 and 1 is " 
     66                            "expected on the input.") 
    6667            return 
    6768        self.warning(0, None) 
  • Orange/OrangeWidgets/Prototypes/OWLP.py

    r9671 r10502  
    5959 
    6060        if not Orange.multilabel.is_multilabel(data): 
    61             self.warning(0, "Multi-label data is expected on the input.") 
     61            self.warning(0, "Multi-label data with class values 0 and 1 is " 
     62                            "expected on the input.") 
    6263            return 
    6364        self.warning(0, None) 
  • Orange/OrangeWidgets/Prototypes/OWMLkNN.py

    r9671 r10502  
    7272 
    7373        if not Orange.multilabel.is_multilabel(data): 
    74             self.warning(0, "Multi-label data is expected on the input.") 
     74            self.warning(0, "Multi-label data with class values 0 and 1 is " 
     75                            "expected on the input.") 
    7576            return 
    7677        self.warning(0, None) 
  • Orange/OrangeWidgets/Unsupervised/OWNxAnalysis.py

    r10046 r10510  
    66<priority>6425</priority> 
    77""" 
     8from PyQt4.QtCore import QMutex 
    89import numpy 
    910import networkx as nx 
     
    6667        self.outputs = [("Network", Orange.network.Graph),  
    6768                        ("Items", Orange.data.Table)] 
    68      
     69 
    6970        self.methods = [ 
    7071            ("number_of_nodes", True, "Number of nodes", GRAPHLEVEL, lambda G: G.number_of_nodes()), 
     
    7576            ("average_shortest_path_length", False, "Average shortest path length", GRAPHLEVEL, nx.average_shortest_path_length), 
    7677            ("density", True, "Density", GRAPHLEVEL, nx.density), 
    77             ("degree_assortativity_coefficient", False, "Degree assortativity coefficient", GRAPHLEVEL, nx.degree_assortativity_coefficient), 
     78            ("degree_assortativity_coefficient", False, \ 
     79                "Degree assortativity coefficient", GRAPHLEVEL, \ 
     80                    nx.degree_assortativity_coefficient if \ 
     81                    hasattr(nx, "degree_assortativity_coefficient") else None), 
    7882            # additional attr needed 
    7983            #("attribute_assortativity_coefficient", False, "Attribute assortativity coefficient", GRAPHLEVEL, nx.attribute_assortativity_coefficient), 
    8084            #("numeric_assortativity_coefficient", False, "Numeric assortativity coefficient", GRAPHLEVEL, nx.numeric_assortativity_coefficient), 
    81             ("degree_pearson_correlation_coefficient", False, "Degree pearson correlation coefficient", GRAPHLEVEL, nx.degree_pearson_correlation_coefficient), 
    82             ("estrada_index", False, "Estrada index", GRAPHLEVEL, nx.estrada_index), 
     85            ("degree_pearson_correlation_coefficient", False, \ 
     86                "Degree pearson correlation coefficient", GRAPHLEVEL, \ 
     87                nx.degree_pearson_correlation_coefficient if\ 
     88                hasattr(nx, "degree_pearson_correlation_coefficient") else None), 
     89            ("estrada_index", False, "Estrada index", GRAPHLEVEL, \ 
     90                nx.estrada_index if hasattr(nx, "estrada_index") else None), 
    8391            ("graph_clique_number", False, "Graph clique number", GRAPHLEVEL, nx.graph_clique_number), 
    8492            ("graph_number_of_cliques", False, "Graph number of cliques", GRAPHLEVEL, nx.graph_number_of_cliques), 
     
    112120            ("current_flow_closeness_centrality", False, "Information centrality", NODELEVEL, nx.current_flow_closeness_centrality), 
    113121            ("current_flow_betweenness_centrality", False, "Random-walk betweenness centrality", NODELEVEL, nx.current_flow_betweenness_centrality), 
    114             ("approximate_current_flow_betweenness_centrality", False, "Approx. random-walk betweenness centrality", NODELEVEL, nx.approximate_current_flow_betweenness_centrality), 
     122            ("approximate_current_flow_betweenness_centrality", False, \ 
     123                "Approx. random-walk betweenness centrality", NODELEVEL, \ 
     124                nx.approximate_current_flow_betweenness_centrality if \ 
     125                hasattr(nx, "approximate_current_flow_betweenness_centrality") \ 
     126                    else None), 
    115127            ("eigenvector_centrality", False, "Eigenvector centrality", NODELEVEL, nx.eigenvector_centrality), 
    116128            ("eigenvector_centrality_numpy", False, "Eigenvector centrality (NumPy)", NODELEVEL, nx.eigenvector_centrality_numpy), 
     
    120132            ("closeness_vitality", False, "Closeness vitality", NODELEVEL, nx.closeness_vitality),                     
    121133        ] 
     134 
     135        self.methods = [method for method in self.methods if method[-1] is not None] 
    122136         
    123137        self.auto_commit = False 
  • Orange/classification/rules.py

    r10407 r10519  
    3939Validator_LRS = Orange.core.RuleValidator_LRS 
    4040     
     41from Orange.orng.orngABML import \ 
     42    ArgumentFilter_hasSpecial, \ 
     43    create_dichotomous_class, \ 
     44    evaluateAndSortArguments 
    4145from Orange.misc import deprecated_keywords 
    4246from Orange.misc import deprecated_members 
    4347 
    44  
    45 class ConvertClass: 
    46     """ Converting class variables into dichotomous class variable. """ 
    47     def __init__(self, classAtt, classValue, newClassAtt): 
    48         self.classAtt = classAtt 
    49         self.classValue = classValue 
    50         self.newClassAtt = newClassAtt 
    51  
    52     def __call__(self, example, returnWhat): 
    53         if example[self.classAtt] == self.classValue: 
    54             return Orange.data.Value(self.newClassAtt, self.classValue + "_") 
    55         else: 
    56             return Orange.data.Value(self.newClassAtt, "not " + self.classValue) 
    57  
    58  
    59 def create_dichotomous_class(domain, att, value, negate, removeAtt=None): 
    60     # create new variable 
    61     newClass = Orange.feature.Discrete(att.name + "_", values=[str(value) + "_", "not " + str(value)]) 
    62     positive = Orange.data.Value(newClass, str(value) + "_") 
    63     negative = Orange.data.Value(newClass, "not " + str(value)) 
    64     newClass.getValueFrom = ConvertClass(att, str(value), newClass) 
    65  
    66     att = [a for a in domain.attributes] 
    67     newDomain = Orange.data.Domain(att + [newClass]) 
    68     newDomain.addmetas(domain.getmetas()) 
    69     if negate == 1: 
    70         return (newDomain, negative) 
    71     else: 
    72         return (newDomain, positive) 
    7348 
    7449 
     
    559534                 rule_sig=1.0, att_sig=1.0, postpruning=None, min_quality=0., min_coverage=1, min_improved=1, min_improved_perc=0.0, 
    560535                 learn_for_class=None, learn_one_rule=False, evd=None, evd_arguments=None, prune_arguments=False, analyse_argument= -1, 
    561                  alternative_learner=None, min_cl_sig=0.5, min_beta=0.0, set_prefix_rules=False, add_sub_rules=False, debug=False, 
     536                 alternative_learner=None, min_cl_sig=0.5, min_beta=0.0, set_prefix_rules=False, add_sub_rules=True, debug=False, 
    562537                 **kwds): 
    563538 
     
    652627            while aes: 
    653628                if self.analyse_argument > -1 and \ 
    654                    (isinstance(self.analyse_argument, Orange.data.Instance) and not Orange.data.Instance(dich_data.domain, self.analyse_argument) == aes[0] or \ 
     629                   (isinstance(self.analyse_argument, Orange.core.Example) and not Orange.core.Example(dich_data.domain, self.analyse_argument) == aes[0] or \ 
    655630                    isinstance(self.analyse_argument, int) and not dich_data[self.analyse_argument] == aes[0]): 
    656631                    aes = aes[1:] 
     
    667642                else: 
    668643                    aes = aes[1:] 
    669                 aes = aes[1:] 
    670644 
    671645            if not progress and self.debug: 
     
    674648            # remove all examples covered by rules 
    675649            for rule in rules: 
    676                 dich_data = self.remove_covered_examples(rule, dich_data, weight_id) 
     650                dich_data = self.remove_covered_examples(rule, dich_data, weight_id, True) 
    677651            if progress: 
    678652                progress(self.remaining_probability(dich_data), None) 
     
    683657                while dich_data: 
    684658                    # learn a rule 
    685                     rule = self.learn_normal_rule(dich_data, weight_id, self.apriori) 
     659                    rule, good_rule = self.learn_normal_rule(dich_data, weight_id, self.apriori) 
    686660                    if not rule: 
    687661                        break 
    688662                    if self.debug: 
    689                         print "rule learned: ", Orange.classification.rules.rule_to_string(rule), rule.quality 
    690                     dich_data = self.remove_covered_examples(rule, dich_data, weight_id) 
     663                        if good_rule: 
     664                            print "rule learned: ", rule_to_string(rule), rule.quality 
     665                        else: 
     666                            print "rule only to influence learning: ", rule_to_string(rule), rule.quality 
     667                             
     668                    dich_data = self.remove_covered_examples(rule, dich_data, weight_id, good_rule) 
     669 
    691670                    if progress: 
    692671                        progress(self.remaining_probability(dich_data), None) 
    693                     rules.append(rule) 
     672                    if good_rule: 
     673                        rules.append(rule) 
    694674                    if self.learn_one_rule: 
    695675                        break 
     
    715695        if not positive_args: # something wrong 
    716696            raise "There is a problem with argumented example %s" % str(ae) 
     697            return None 
     698        if False in [p(ae) for p in positive_args]: # a positive argument is not covering this example 
     699            raise "One argument does not cover critical example: %s!"%str(ae) 
    717700            return None 
    718701        negative_args = self.init_neg_args(ae, examples, weight_id) 
     
    807790        if hasattr(self.rule_finder.evaluator, "bestRule"): 
    808791            self.rule_finder.evaluator.bestRule = None 
    809         rule = self.rule_finder(examples, weight_id, 0, RuleList()) 
     792        rule = self.rule_finder(examples,weight_id,0,RuleList()) 
    810793        if hasattr(self.rule_finder.evaluator, "bestRule") and self.rule_finder.evaluator.returnExpectedProb: 
     794            if not self.rule_finder.evaluator.bestRule and rule.quality > 0: 
     795                return (rule, False) 
    811796            rule = self.rule_finder.evaluator.bestRule 
    812797            self.rule_finder.evaluator.bestRule = None 
    813798        if self.postpruning: 
    814             rule = self.postpruning(rule, examples, weight_id, 0, aprior) 
    815         return rule 
    816  
    817     def remove_covered_examples(self, rule, examples, weight_id): 
    818         nexamples, nweight = self.cover_and_remove(rule, examples, weight_id, 0) 
     799            rule = self.postpruning(rule,examples,weight_id,0, aprior) 
     800        return (rule, True) 
     801     
     802 
     803    def remove_covered_examples(self, rule, examples, weight_id, good_rule): 
     804        if good_rule: 
     805            nexamples, nweight = self.cover_and_remove(rule, examples, weight_id, 0) 
     806        else: 
     807            nexamples, nweight = self.cover_and_remove.mark_examples_solved(rule,examples,weight_id,0) 
    819808        return nexamples 
    820809 
     
    859848                    self.rule_finder.evaluator.returnExpectedProb = oldREP 
    860849                tmpList.sort(lambda x, y:-cmp(x.quality, y.quality)) 
    861                 tmpList = tmpList[:self.rule_filter.width] 
     850                tmpList = tmpList[:self.ruleFilter.width] 
    862851 
    863852                for tmpRule in tmpList: 
     
    873862                            tmpRule2.filterAndStore(examples, weight_id, r.classifier.default_val) 
    874863                            tmpRule2.complexity += 1 
    875                             if tmpRule2.class_distribution.abs < tmprule.class_distribution.abs: 
     864                            if tmpRule2.class_distribution.abs < tmpRule.class_distribution.abs: 
    876865                                tmpList2.append(tmpRule2) 
    877866                tmpList = tmpList2 
     
    12251214            if r and not rule_in_set(r, best_rules) and int(examples[r_i].getclass()) == int(r.classifier.default_value): 
    12261215                if hasattr(r.learner, "arg_example"): 
    1227                     setattr(r, "best_example", r.learner.arg_example) 
     1216                    r.setattr("best_example", r.learner.arg_example) 
    12281217                else: 
    1229                     setattr(r, "best_example", examples[r_i]) 
     1218                    r.setattr("best_example", examples[r_i]) 
    12301219                best_rules.append(r) 
    12311220        return best_rules 
     
    12341223        """ if example has an argument, then the rule must be consistent with the argument. """ 
    12351224        example = getattr(rule.learner, "arg_example", None) 
     1225        if example: 
     1226            for ei, e in enumerate(examples): 
     1227                if e == example: 
     1228                    e[self.prob_attribute] = rule.quality+0.001 # 0.001 is added to avoid numerical errors 
     1229                    self.best_rule[ei]=rule 
     1230        else:         
     1231            for ei, e in enumerate(examples): 
     1232                if rule(e) and rule.quality>e[self.prob_attribute]: 
     1233                    e[self.prob_attribute] = rule.quality+0.001 # 0.001 is added to avoid numerical errors 
     1234                    self.best_rule[ei]=rule 
     1235        return (examples, weights) 
     1236 
     1237    def mark_examples_solved(self, rule, examples, weights, target_class): 
    12361238        for ei, e in enumerate(examples): 
    1237             if e == example: 
     1239            if rule(e): 
    12381240                e[self.prob_attribute] = 1.0 
    1239                 self.best_rule[ei] = rule 
    1240             elif rule(e) and rule.quality > e[self.prob_attribute]: 
    1241                 e[self.prob_attribute] = rule.quality + 0.001 # 0.001 is added to avoid numerical errors 
    1242                 self.best_rule[ei] = rule 
    12431241        return (examples, weights) 
    1244  
    1245     def filter_covers_example(self, example, filter): 
    1246         filter_indices = CoversArguments.filterIndices(filter) 
    1247         if filter(example): 
    1248             try: 
    1249                 if example[self.argument_id].value and len(example[self.argument_id].value.positive_arguments) > 0: # example has positive arguments 
    1250                     # conditions should cover at least one of the positive arguments 
    1251                     one_arg_covered = False 
    1252                     for pA in example[self.argument_id].value.positive_arguments: 
    1253                         arg_covered = [self.condIn(c, filter_indices) for c in pA.filter.conditions] 
    1254                         one_arg_covered = one_arg_covered or len(arg_covered) == sum(arg_covered) #arg_covered 
    1255                         if one_arg_covered: 
    1256                             break 
    1257                     if not one_arg_covered: 
    1258                         return False 
    1259                 if example[self.argument_id].value and len(example[self.argument_id].value.negative_arguments) > 0: # example has negative arguments 
    1260                     # condition should not cover neither of negative arguments 
    1261                     for pN in example[self.argument_id].value.negative_arguments: 
    1262                         arg_covered = [self.condIn(c, filter_indices) for c in pN.filter.conditions] 
    1263                         if len(arg_covered) == sum(arg_covered): 
    1264                             return False 
    1265             except: 
    1266                 return True 
    1267             return True 
    1268         return False 
    1269  
    1270     def condIn(self, cond, filter_indices): # is condition in the filter? 
    1271         condInd = CoversArguments.conditionIndex(cond) 
    1272         if operator.or_(condInd, filter_indices[cond.position]) == filter_indices[cond.position]: 
    1273             return True 
    1274         return False 
    1275  
    12761242 
    12771243    def covered_percentage(self, examples): 
     
    17421708# This filter is the ugliest code ever! Problem is with Orange, I had some problems with inheriting deepCopy 
    17431709# I should take another look at it. 
    1744 class ArgFilter(Orange.data.filter.Filter): 
     1710class ArgFilter(Orange.core.Filter): 
    17451711    """ This class implements AB-covering principle. """ 
    1746     def __init__(self, argument_id=None, filter=Orange.data.filter.Values(), arg_example=None): 
     1712    def __init__(self, argument_id=None, filter = Orange.core.Filter_values(), arg_example = None): 
    17471713        self.filter = filter 
    1748         self.indices = getattr(filter, "indices", []) 
    1749         if not self.indices and len(filter.conditions) > 0: 
    1750             self.indices = CoversArguments.filterIndices(filter) 
     1714        self.indices = getattr(filter,"indices",[]) 
     1715        if not self.indices and len(filter.conditions)>0: 
     1716            self.indices = RuleCoversArguments.filterIndices(filter) 
    17511717        self.argument_id = argument_id 
    17521718        self.domain = self.filter.domain 
    17531719        self.conditions = filter.conditions 
    17541720        self.arg_example = arg_example 
    1755  
    1756     def condIn(self, cond): # is condition in the filter? 
    1757         condInd = ruleCoversArguments.conditionIndex(cond) 
    1758         if operator.or_(condInd, self.indices[cond.position]) == self.indices[cond.position]: 
     1721        self.only_arg_example = True 
     1722         
     1723    def condIn(self,cond): # is condition in the filter? 
     1724        condInd = RuleCoversArguments.conditionIndex(cond) 
     1725        if operator.or_(condInd,self.indices[cond.position]) == self.indices[cond.position]: 
    17591726            return True 
    17601727        return False 
    1761  
    1762     def __call__(self, example): 
    1763 ##        print "in", self.filter(example)#, self.filter.conditions[0](example) 
    1764 ##        print self.filter.conditions[1].values 
    1765         if self.filter(example) and example != self.arg_example: 
    1766             return True 
    1767         elif self.filter(example): 
    1768             try: 
    1769                 if example[self.argument_id].value and len(example[self.argument_id].value.positiveArguments) > 0: # example has positive arguments 
    1770                     # conditions should cover at least one of the positive arguments 
    1771                     oneArgCovered = False 
    1772                     for pA in example[self.argument_id].value.positiveArguments: 
    1773                         argCovered = [self.condIn(c) for c in pA.filter.conditions] 
    1774                         oneArgCovered = oneArgCovered or len(argCovered) == sum(argCovered) #argCovered 
    1775                         if oneArgCovered: 
    1776                             break 
    1777                     if not oneArgCovered: 
     1728     
     1729    def __call__(self,example): 
     1730        if not self.filter(example): 
     1731            return False 
     1732        elif (not self.only_arg_example or example == self.arg_example): 
     1733            if example[self.argument_id].value and len(example[self.argument_id].value.positive_arguments)>0: # example has positive arguments 
     1734                # conditions should cover at least one of the positive arguments 
     1735                oneArgCovered = False 
     1736                for pA in example[self.argument_id].value.positive_arguments: 
     1737                    argCovered = [self.condIn(c) for c in pA.filter.conditions] 
     1738                    oneArgCovered = oneArgCovered or len(argCovered) == sum(argCovered) #argCovered 
     1739                    if oneArgCovered: 
     1740                        break 
     1741                if not oneArgCovered: 
     1742                    return False 
     1743            if example[self.argument_id].value and len(example[self.argument_id].value.negative_arguments)>0: # example has negative arguments 
     1744                # condition should not cover neither of negative arguments 
     1745                for pN in example[self.argument_id].value.negative_arguments: 
     1746                    argCovered = [self.condIn(c) for c in pN.filter.conditions] 
     1747                    if len(argCovered)==sum(argCovered): 
    17781748                        return False 
    1779                 if example[self.argument_id].value and len(example[self.argument_id].value.negativeArguments) > 0: # example has negative arguments 
    1780                     # condition should not cover neither of negative arguments 
    1781                     for pN in example[self.argument_id].value.negativeArguments: 
    1782                         argCovered = [self.condIn(c) for c in pN.filter.conditions] 
    1783                         if len(argCovered) == sum(argCovered): 
    1784                             return False 
    1785             except: 
    1786                 return True 
    1787             return True 
    1788         else: 
    1789             return False 
    1790  
    1791     def __setattr__(self, name, obj): 
    1792         self.__dict__[name] = obj 
    1793         self.filter.setattr(name, obj) 
     1749        return True 
     1750 
     1751    def __setattr__(self,name,obj): 
     1752        self.__dict__[name]=obj 
     1753        self.filter.setattr(name,obj) 
    17941754 
    17951755    def deep_copy(self): 
    17961756        newFilter = ArgFilter(argument_id=self.argument_id) 
    1797         newFilter.filter = Orange.data.filter.Values() #self.filter.deepCopy() 
     1757        newFilter.filter = Orange.core.Filter_values() #self.filter.deepCopy() 
    17981758        newFilter.filter.conditions = self.filter.conditions[:] 
    17991759        newFilter.domain = self.filter.domain 
     
    18031763        newFilter.conditions = newFilter.filter.conditions 
    18041764        newFilter.indices = self.indices[:] 
     1765        newFilter.arg_example = self.arg_example 
    18051766        return newFilter 
    1806  
    18071767ArgFilter = deprecated_members({"argumentID": "argument_id"})(ArgFilter) 
    18081768 
     
    18811841    PILAR (Probabilistic improvement of learning algorithms with rules). 
    18821842    """ 
    1883     def __init__(self, alternative_learner=None, min_cl_sig=0.5, min_beta=0.0, set_prefix_rules=False, optimize_betas=True): 
     1843    def __init__(self, alternative_learner=None, min_cl_sig=0.5, min_beta=0.0, penalty=0.01, set_prefix_rules=False, optimize_betas=True): 
    18841844        self.alternative_learner = alternative_learner 
    18851845        self.min_cl_sig = min_cl_sig 
     
    18881848        self.optimize_betas = optimize_betas 
    18891849        self.selected_evaluation = CrossValidation(folds=5) 
     1850        self.penalty = penalty 
    18901851 
    18911852    def __call__(self, rules, examples, weight=0): 
     
    18971858##            for e in examples: 
    18981859##                prob_dist.append(classifier(e,Orange.core.GetProbabilities)) 
    1899             cl = RuleClassifier_logit(rules, self.min_cl_sig, self.min_beta, examples, weight, self.set_prefix_rules, self.optimize_betas, classifier, prob_dist) 
     1860            cl = Orange.core.RuleClassifier_logit(rules, self.min_cl_sig, self.min_beta, self.penalty, examples, weight, self.set_prefix_rules, self.optimize_betas, classifier, prob_dist) 
    19001861        else: 
    1901             cl = RuleClassifier_logit(rules, self.min_cl_sig, self.min_beta, examples, weight, self.set_prefix_rules, self.optimize_betas) 
    1902  
    1903 ##        print "result" 
     1862            cl = Orange.core.RuleClassifier_logit(rules, self.min_cl_sig, self.min_beta, self.penalty, examples, weight, self.set_prefix_rules, self.optimize_betas) 
     1863 
    19041864        for ri, r in enumerate(cl.rules): 
    19051865            cl.rules[ri].setattr("beta", cl.ruleBetas[ri]) 
    1906 ##            if cl.ruleBetas[ri] > 0: 
    1907 ##                print Orange.classification.rules.rule_to_string(r), r.quality, cl.ruleBetas[ri] 
    1908         cl.all_rules = cl.rules 
     1866        cl.setattr("all_rules", cl.rules) 
    19091867        cl.rules = self.sort_rules(cl.rules) 
    19101868        cl.ruleBetas = [r.beta for r in cl.rules] 
  • Orange/data/io.py

    r10255 r10532  
    480480    elif cell == "": 
    481481        return variable.Descriptor 
    482     elif len(cell.split(",")) > 1: 
    483         return variable.Discrete, cell.split(",") 
     482    elif len(split_escaped_str(cell, " ")) > 1: 
     483        return variable.Discrete, split_escaped_str(cell, " ") 
    484484    else: 
    485485        raise ValueError("Unknown variable type definition %r." % cell) 
     
    531531            specifier = "class" 
    532532            items = items[1:] 
     533        elif items[0] == "multiclass": 
     534            specifier = "multiclass" 
     535            items = items[1:] 
     536        elif items[0] in ["i", "ignore"]: 
     537            specifier = "ignore" 
     538            items = items[1:] 
    533539        return specifier, dict(map(_var_attribute_label_parse, items)) 
    534540    else: 
     
    536542 
    537543def var_attributes(row): 
    538     """ Return variable specifiers and label definitions for row 
     544    """ Return variable specifiers and label definitions for row. 
    539545    """ 
    540546    return map(var_attribute, row) 
     
    581587    return False 
    582588 
    583 def load_csv(file, create_new_on=MakeStatus.Incompatible, **kwargs): 
     589def load_csv(file, create_new_on=MakeStatus.Incompatible,  
     590             delimiter=None, quotechar=None, escapechar=None, 
     591             skipinitialspace=None, has_header=None,  
     592             has_types=None, has_annotations=None, DK=None, **kwargs): 
    584593    """ Load an Orange.data.Table from s csv file. 
    585594    """ 
     
    589598    sample = file.read(5 * 2 ** 20) # max 5MB sample TODO: What if this is not enough. Try with a bigger sample 
    590599    dialect = snifer.sniff(sample) 
    591     has_header = snifer.has_header(sample) 
     600     
     601    if has_header is None: 
     602        has_header = snifer.has_header(sample) 
     603     
    592604    file.seek(0) # Rewind 
    593     reader = csv.reader(file, dialect=dialect) 
     605     
     606    def kwparams(**kwargs): 
     607        """Return not None kwargs. 
     608        """ 
     609        return dict([(k, v) for k, v in kwargs.items() if v is not None]) 
     610     
     611    fmtparam = kwparams(delimiter=delimiter, 
     612                        quotechar=quotechar, 
     613                        escapechar=escapechar, 
     614                        skipinitialspace=skipinitialspace) 
     615     
     616    reader = csv.reader(file, dialect=dialect, 
     617                        **fmtparam) 
    594618 
    595619    header = types = var_attrs = None 
    596620 
    597 #    if not has_header: 
    598 #        raise ValueError("No header in the data file.") 
    599  
    600     header = reader.next() 
    601  
    602     if header: 
    603         # Try to get variable definitions 
    604         types_row = reader.next() 
    605         if is_var_types_row(types_row): 
    606             types = var_types(types_row) 
    607  
    608     if types: 
    609         # Try to get the variable attributes 
    610         # (third line in the standard orange tab format). 
    611         labels_row = reader.next() 
    612         if is_var_attributes_row(labels_row): 
    613             var_attrs = var_attributes(labels_row) 
    614  
    615     # If definitions not present fill with blanks 
     621    row = first_row = reader.next() 
     622     
     623    if has_header: 
     624        header = row 
     625        # Eat this row and move to the next 
     626        row = reader.next() 
     627 
     628    # Guess types row 
     629    if has_types is None: 
     630        has_types = has_header and is_var_types_row(row) 
     631         
     632    if has_types: 
     633        types = var_types(row) 
     634        # Eat this row and move to the next 
     635        row = reader.next() 
     636 
     637    # Guess variable annotations row 
     638    if has_annotations is None: 
     639        has_annotations = has_header and has_types and \ 
     640                          is_var_attributes_row(row) 
     641         
     642    if has_annotations: 
     643        labels_row = row 
     644        var_attrs = var_attributes(row) 
     645        # Eat this row and move to the next 
     646        row = reader.next() 
     647 
     648    if not header: 
     649        # Create a default header 
     650        header = ["F_%i" % i for i in range(len(first_row))] 
     651         
    616652    if not types: 
     653        # Create blank variable types 
    617654        types = [None] * len(header) 
     655         
    618656    if not var_attrs: 
     657        # Create blank variable attributes 
    619658        var_attrs = [None] * len(header) 
    620659 
    621660    # start from the beginning 
    622661    file.seek(0) 
    623     reader = csv.reader(file, dialect=dialect) 
    624     for defined in [header, types, var_attrs]: 
    625         if any(defined): # skip definition rows if present in the file 
     662    reader = csv.reader(file, dialect=dialect, **fmtparam) 
     663     
     664    for defined in [has_header, has_types, has_annotations]: 
     665        if defined:  
     666            # skip definition rows if present in the file 
    626667            reader.next() 
    627  
     668     
    628669    variables = [] 
    629670    undefined_vars = [] 
     671    # Missing value flags  
     672    missing_flags = DK.split(",") if DK is not None else ["?", "", "NA", "~", "*"] 
     673    missing_map = dict.fromkeys(missing_flags, "?") 
     674    missing_translate = lambda val: missing_map.get(val, val) 
     675        
     676    # Create domain variables or corresponding place holders 
    630677    for i, (name, var_t) in enumerate(zip(header, types)): 
    631         if var_t == variable.Discrete:# We do not have values yet. 
     678        if var_t == variable.Discrete: 
     679            # We do not have values yet 
    632680            variables.append(_disc_placeholder(name)) 
    633681            undefined_vars.append((i, variables[-1])) 
     
    641689            var_t, values = var_t 
    642690            if var_t == variable.Discrete: 
     691                # We have values for discrete variable 
    643692                variables.append(make(name, Orange.feature.Type.Discrete, values, [], create_new_on)) 
    644693            elif var_t == variable.Python: 
     694                # Python variables are not supported yet 
    645695                raise NotImplementedError() 
    646696        elif var_t is None: 
     697            # Unknown variable type, to be deduced at the end 
    647698            variables.append(_var_placeholder(name)) 
    648699            undefined_vars.append((i, variables[-1])) 
    649700 
    650701    data = [] 
     702    # Read all the rows 
    651703    for row in reader: 
    652         data.append(row) 
    653         for ind, var_def in undefined_vars: 
    654             var_def.values.add(row[ind]) 
    655  
     704        # check for final newline. 
     705        if row: 
     706            row = map(missing_translate, row) 
     707            data.append(row) 
     708            # For undefined variables collect all their values 
     709            for ind, var_def in undefined_vars: 
     710                var_def.values.add(row[ind]) 
     711     
     712    # Process undefined variables now that we can deduce their type  
    656713    for ind, var_def in undefined_vars: 
    657714        values = var_def.values - set(["?", ""]) # TODO: Other unknown strings? 
     
    669726                raise ValueError("Strange column in the data") 
    670727 
    671     vars = [] 
    672     vars_load_status = [] 
    673728    attribute_load_status = [] 
    674729    meta_attribute_load_status = {} 
    675730    class_var_load_status = [] 
    676     for var, status in vars: 
    677         vars.append(var) 
    678         vars_load_status.append(status) 
     731    multiclass_var_load_status = [] 
    679732 
    680733    attributes = [] 
    681734    class_var = [] 
     735    class_vars = [] 
    682736    metas = {} 
    683737    attribute_indices = [] 
    684738    variable_indices = [] 
    685739    class_indices = [] 
     740    multiclass_indices = [] 
    686741    meta_indices = [] 
     742    ignore_indices = [] 
    687743    for i, ((var, status), var_attr) in enumerate(zip(variables, var_attrs)): 
    688744        if var_attr: 
     
    692748                class_var_load_status.append(status) 
    693749                class_indices.append(i) 
     750            elif flag == "multiclass": 
     751                class_vars.append(var) 
     752                multiclass_var_load_status.append(status) 
     753                multiclass_indices.append(i) 
    694754            elif flag == "meta": 
    695755                mid = Orange.feature.Descriptor.new_meta_id() 
     
    697757                meta_attribute_load_status[mid] = status 
    698758                meta_indices.append((i, var)) 
     759            elif flag == "ignore": 
     760                ignore_indices.append(i) 
    699761            else: 
    700762                attributes.append(var) 
     
    709771    if len(class_var) > 1: 
    710772        raise ValueError("Multiple class variables defined") 
     773    if class_var and class_vars: 
     774        raise ValueError("Both 'class' and 'multiclass' used.") 
    711775 
    712776    class_var = class_var[0] if class_var else None 
    713  
     777     
    714778    attribute_load_status += class_var_load_status 
    715779    variable_indices = attribute_indices + class_indices 
    716     domain = Orange.data.Domain(attributes, class_var) 
     780    domain = Orange.data.Domain(attributes, class_var, class_vars=class_vars) 
    717781    domain.add_metas(metas) 
    718782    normal = [[row[i] for i in variable_indices] for row in data] 
    719783    meta_part = [[row[i] for i, _ in meta_indices] for row in data] 
     784    multiclass_part = [[row[i] for i in multiclass_indices] for row in data] 
    720785    table = Orange.data.Table(domain, normal) 
    721     for ex, m_part in zip(table, meta_part): 
     786    for ex, m_part, mc_part in zip(table, meta_part, multiclass_part): 
    722787        for (column, var), val in zip(meta_indices, m_part): 
    723788            ex[var] = var(val) 
     789        if mc_part: 
     790            ex.set_classes(mc_part) 
    724791 
    725792    table.setattr("metaAttributeLoadStatus", meta_attribute_load_status) 
  • Orange/ensemble/forest.py

    r9919 r10530  
    3434    split is  (on average) as specified.""" 
    3535 
    36     def __new__(cls, instances = None, weight_id = 0, **argkw): 
    37         self = Orange.core.Learner.__new__(cls, **argkw) 
    38         if instances: 
    39             self.__init__(**argkw) 
    40             return self.__call__(instances, weight_id) 
    41         else: 
    42             return self 
    43        
     36    __new__ = Orange.misc._orange__new__(Orange.core.Learner) 
     37 
    4438    def __init__(self, base, rand): 
    4539        self.base = base 
     
    5448        self.base.skip_prob, self.base.random_generator = osp, orand 
    5549        return r 
     50 
    5651_RandomForestSimpleTreeLearner = Orange.misc.deprecated_members({"weightID":"weight_id", "examples":"instances"})(_RandomForestSimpleTreeLearner) 
    5752    
    58 class RandomForestLearner(orange.Learner): 
    59     """ 
    60     Just like in bagging, classifiers in random forests are trained from bootstrap 
    61     samples of training data. Here, the classifiers are trees. However, to increase 
    62     randomness, at each node of the tree the best feature is 
    63     chosen from a subset of features in the data. We closely follow the 
    64     original algorithm (Brieman, 2001) both in implementation and parameter 
     53class RandomForestLearner(Orange.core.Learner): 
     54    """ 
     55    Trains an ensemble predictor consisting of trees trained 
     56    on bootstrap 
     57    samples of training data. To increase 
     58    randomness, the tree learner considers only a subset of 
     59    candidate features at each node. The algorithm closely follows 
     60    the original procedure (Brieman, 2001) both in implementation and parameter 
    6561    defaults. 
    6662         
     
    6965 
    7066    :param attributes: number of randomly drawn features among 
    71             which to select the best to split the nodes in tree 
    72             induction. The default, None, means the square root of 
     67            which to select the best one to split the data sets 
     68            in tree nodes. The default, None, means the square root of 
    7369            the number of features in the training data. Ignored if 
    7470            :obj:`learner` is specified. 
     
    9490 
    9591    :param callback: a function to be called after every iteration of 
    96             induction of classifier. This is called with parameter  
    97             (from 0.0 to 1.0) that gives estimates on learning progress. 
     92            induction of classifier. The call includes a parameter 
     93            (from 0.0 to 1.0) that provides an estimate 
     94            of completion of the learning progress. 
    9895 
    9996    :param name: name of the learner. 
     
    105102    """ 
    106103 
    107     def __new__(cls, instances=None, weight = 0, **kwds): 
    108         self = orange.Learner.__new__(cls, **kwds) 
    109         if instances: 
    110             self.__init__(**kwds) 
    111             return self.__call__(instances, weight) 
    112         else: 
    113             return self 
     104    __new__ = Orange.misc._orange__new__(Orange.core.Learner) 
    114105 
    115106    def __init__(self, trees=100, attributes=None,\ 
     
    485476    a new split constructor. 
    486477    """ 
    487     @deprecated_keywords({"weightID":"weight_id", "examples":"instances"}) 
    488     def __new__(cls, instances = None, weight_id = 0, **argkw): 
    489         self = Orange.core.Learner.__new__(cls, **argkw) 
    490         if instances: 
    491             self.__init__(**argkw) 
    492             return self.__call__(instances, weight_id) 
    493         else: 
    494             return self 
    495        
     478 
     479    __new__ = Orange.misc._orange__new__(Orange.core.Learner) 
     480      
    496481    def __init__(self, base, rand): 
    497482        self.base = base 
  • Orange/feature/selection.py

    r10172 r10523  
    11__docformat__ = 'restructuredtext' 
     2 
     3from operator import itemgetter 
    24 
    35import Orange.core as orange 
     
    1719 
    1820    """ 
    19     return [x[0] for x in sorted(scores)[:n]] 
     21    return [x[0] for x in \ 
     22            sorted(scores, key=itemgetter(1), reverse=True)[:n] 
     23            ] 
    2024 
    2125bestNAtts = best_n 
  • Orange/misc/__init__.py

    r10327 r10521  
    911911    @wraps(base.__new__) 
    912912    def _orange__new_wrapped(cls, data=None, **kwargs): 
    913         self = base.__new__(cls, **kwargs) 
     913        if base == object: 
     914            self = base.__new__(cls) 
     915        else: 
     916            self = base.__new__(cls, **kwargs) 
     917 
    914918        if data: 
    915919            self.__init__(**kwargs) 
  • Orange/multilabel/br.py

    r9994 r10502  
    7575    def __call__(self, instances, weight_id = 0, **kwds): 
    7676        if not Orange.multilabel.is_multilabel(instances): 
    77             raise TypeError("The given data set is not a multi-label data set.") 
     77            raise TypeError("The given data set is not a multi-label data set" 
     78                            " with class values 0 and 1.") 
    7879         
    7980        for k in kwds.keys(): 
  • Orange/multilabel/brknn.py

    r9994 r10502  
    9494    def __call__(self, instances, weight_id = 0, **kwds): 
    9595        if not Orange.multilabel.is_multilabel(instances): 
    96             raise TypeError("The given data set is not a multi-label data set.") 
     96            raise TypeError("The given data set is not a multi-label data set" 
     97                            " with class values 0 and 1.") 
    9798 
    9899        for k in kwds.keys(): 
  • Orange/multilabel/lp.py

    r9994 r10502  
    8484    def __call__(self, instances, base_learner = None, weight_id = 0, **kwds): 
    8585        if not Orange.multilabel.is_multilabel(instances): 
    86             raise TypeError("The given data set is not a multi-label data set.") 
     86            raise TypeError("The given data set is not a multi-label data set" 
     87                            " with class values 0 and 1.") 
    8788 
    8889        self.__dict__.update(kwds) 
  • Orange/multilabel/mlknn.py

    r10417 r10502  
    143143    def __call__(self, instances, weight_id = 0, **kwds): 
    144144        if not Orange.multilabel.is_multilabel(instances): 
    145             raise TypeError("The given data set is not a multi-label data set.") 
     145            raise TypeError("The given data set is not a multi-label data set" 
     146                            " with class values 0 and 1.") 
    146147         
    147148        self.__dict__.update(kwds) 
  • Orange/orng/orngABML.py

    r9737 r10518  
    99import math 
    1010 
    11 from Orange.classification.rules import create_dichotomous_class as createDichotomousClass 
    12 from Orange.classification.rules import ConvertClass 
    1311# regular expressions 
    1412# exppression for testing validity of a set of arguments: 
     
    286284 
    287285 
     286 
     287class ConvertClass: 
     288    """ Converting class variables into dichotomous class variable. """ 
     289    def __init__(self, classAtt, classValue, newClassAtt): 
     290        self.classAtt = classAtt 
     291        self.classValue = classValue 
     292        self.newClassAtt = newClassAtt 
     293 
     294    def __call__(self, example, returnWhat): 
     295        if example[self.classAtt] == self.classValue: 
     296            return Orange.data.Value(self.newClassAtt, self.classValue + "_") 
     297        else: 
     298            return Orange.data.Value(self.newClassAtt, "not " + self.classValue) 
     299 
     300 
     301def create_dichotomous_class(domain, att, value, negate, removeAtt=None): 
     302    # create new variable 
     303    newClass = Orange.feature.Discrete(att.name + "_", values=[str(value) + "_", "not " + str(value)]) 
     304    positive = Orange.data.Value(newClass, str(value) + "_") 
     305    negative = Orange.data.Value(newClass, "not " + str(value)) 
     306    newClass.getValueFrom = ConvertClass(att, str(value), newClass) 
     307 
     308    att = [a for a in domain.attributes] 
     309    newDomain = Orange.data.Domain(att + [newClass]) 
     310    newDomain.addmetas(domain.getmetas()) 
     311    if negate == 1: 
     312        return (newDomain, negative) 
     313    else: 
     314        return (newDomain, positive) 
     315 
     316 
     317 
    288318def addErrors(test_data, classifier): 
    289319    """ Main task of this function is to add probabilistic errors to examples.""" 
  • Orange/testing/regression/results_tests_20/modules_abcn2-rules.py.txt

    r9951 r10520  
    11IF TRUE THEN survived=no<1490.000, 711.000> 
    22IF sex=['female'] THEN survived=yes<126.000, 344.000> 
     3IF status=['first'] THEN survived=yes<122.000, 203.000> 
     4IF sex=['male'] THEN survived=no<1364.000, 367.000> 
     5IF status=['crew'] THEN survived=no<673.000, 212.000> 
    36IF status=['third'] THEN survived=no<528.000, 178.000> 
    4 IF status=['first'] THEN survived=yes<122.000, 203.000> 
    5 IF status=['crew'] THEN survived=no<673.000, 212.000> 
    67IF age=['adult'] THEN survived=no<1438.000, 654.000> 
    78IF age=['child'] THEN survived=yes<52.000, 57.000> 
     9IF status=['second'] THEN survived=yes<167.000, 118.000> 
    810IF status=['second'] AND age=['child'] THEN survived=yes<0.000, 24.000> 
    911IF sex=['female'] AND status=['first'] THEN survived=yes<4.000, 141.000> 
     
    1214IF status=['first'] AND age=['child'] THEN survived=yes<0.000, 6.000> 
    1315IF sex=['female'] AND age=['adult'] THEN survived=yes<109.000, 316.000> 
     16IF status=['second'] AND sex=['male'] THEN survived=no<154.000, 25.000> 
    1417IF sex=['male'] AND age=['adult'] THEN survived=no<1329.000, 338.000> 
    1518IF status=['third'] AND age=['adult'] THEN survived=no<476.000, 151.000> 
     
    2730IF status=['third'] THEN survived=no<528.000, 178.000> 
    2831IF status=['crew'] THEN survived=no<673.000, 212.000> 
     32IF sex=['male'] THEN survived=no<1364.000, 367.000> 
     33IF status=['second'] AND sex=['male'] THEN survived=no<154.000, 25.000> 
    2934IF status=['first'] THEN survived=yes<122.000, 203.000> 
    3035IF sex=['female'] AND status=['first'] THEN survived=yes<4.000, 141.000> 
  • install-scripts/createSnapshot.btm

    r10275 r10503  
    99set ADDON_TEXT_SNAPSHOT=orangeAddOn-text-snapshot-hg-%daystr 
    1010set SOURCE_SNAPSHOT=orange-source-snapshot-hg-%daystr.zip 
    11  
    12 rem # update source(s) to revision HEAD 
    13 cdd %TMPDIR 
    1411 
    1512rem # build core 
     
    2724del /syeqtx sourcestopack 
    2825 
    29 call hg archive sourcestopack 
     26call hg clone . sourcestopack 
    3027 
    3128cd sourcestopack 
     
    3330rem # build source distribution 
    3431e:\Python27\python.exe setup.py sdist 
     32 
    3533rem # build msi file 
     34rem # build_msi only handles StrictVersion so we change Orange\version.py 
     35rem # and remove the .hg dir so the short_version is used 
     36e:\Python27\python.exe -c"print open('Orange/version.py', 'rb').read().replace('if not release:', 'if not release and False:')" > version.py.1 
     37move /z version.py.1 Orange\version.py 
     38del /syeqtx .hg 
     39 
    3640e:\Python27\python.exe setup.py bdist_msi 
    3741 
    38 rem del %DOWNLOADDIR\orange-source-snapshot-????-??-??.zip 
     42break_on_error 
     43 
     44rem # if no errors then publish on web (everything at the same time) 
     45rem # remove any old files   
     46rem # leave 10 latest versions.  
     47e:\Python27\python.exe -c"import os,glob; [os.remove(f) for f in sorted(glob.glob('%DOWNLOADDIR\orange-win-snapshot-hg-*.exe'), reverse=True)[30:]]" 
     48e:\Python27\python.exe -c"import os,glob; [os.remove(f) for f in sorted(glob.glob('%DOWNLOADDIR\orange-win-w-python-snapshot-hg-*.exe'), reverse=True)[30:]]" 
     49e:\Python27\python.exe -c"import os,glob; [os.remove(f) for f in sorted(glob.glob('%DOWNLOADDIR\orangeAddOn-bioinformatics-snapshot-hg-*.exe'), reverse=True)[30:]]" 
     50e:\Python27\python.exe -c"import os,glob; [os.remove(f) for f in sorted(glob.glob('%DOWNLOADDIR\orangeAddOn-text-snapshot-hg-*.exe'), reverse=True)[30:]]" 
     51 
     52e:\Python27\python.exe -c"import os,glob; [os.remove(f) for f in sorted(glob.glob('%DOWNLOADDIR\orange-source-snapshot-hg-*.zip'), reverse=True)[10:]]" 
     53e:\Python27\python.exe -c"import os,glob; [os.remove(f) for f in sorted(glob.glob('%DOWNLOADDIR\orange-win-snapshot-hg-*.exe'), reverse=True)[10:]]" 
     54e:\Python27\python.exe -c"import os,glob; [os.remove(f) for f in sorted(glob.glob('%DOWNLOADDIR\orange-win-snapshot-hg-*.msi'), reverse=True)[10:]]" 
     55 
     56rem except (%DOWNLOADDIR\orange*-snapshot-%daystr-*.exe) del %DOWNLOADDIR\orange*-snapshot-????-??-??-*.exe 
     57 
     58rem # publish 
     59 
    3960move /z dist\Orange-?.*.zip %DOWNLOADDIR\%SOURCE_SNAPSHOT 
    4061move /z dist\Orange-?.*.msi %DOWNLOADDIR\%WIN_SNAPSHOT.msi 
    4162 
    42  
    43 rem # if no errors then publish on web (everything at the same time) 
    44 rem # remove any old files     
    45  
    46 except (%DOWNLOADDIR\orange*-snapshot-%daystr-*.exe) del %DOWNLOADDIR\orange*-snapshot-????-??-??-*.exe 
    47  
    48 rem # publish 
    4963cdd %TMPDIR 
    5064move /z *.exe %DOWNLOADDIR 
  • install-scripts/mac/build-source.sh

    r10445 r10508  
    3535 
    3636# Build the source distribution 
    37 hg parent --template="{latesttag}{latesttagdistance}.dev-{node|short}" > VERSION.txt 
    38 python setup.py sdist 
     37BUILD_TAG=`hg parent --template=".dev-r{rev}-{node|short}"` 
     38python setup.py egg_info --tag-build=$BUILD_TAG sdist 
    3939 
    4040# Copy the source an egg info to workdir 
  • install-scripts/mac/bundle-build-hg.sh

    r10488 r10504  
    2020 
    2121echo "Preaparing the bundle template" 
    22 curl --silent http://orange.biolab.si/download/bundle-templates/Orange-template-2.0a2.tar.gz | tar -xz -C $WORK_DIR 
     22TEMPLATE_VERSION=`curl --silent http://orange.biolab.si/download/bundle-templates/CURRENT.txt` 
     23curl --silent http://orange.biolab.si/download/bundle-templates/Orange-template-${TEMPLATE_VERSION}.tar.gz | tar -xz -C $WORK_DIR 
    2324#svn export --non-interactive http://orange.biolab.si/svn/orange/externals/trunk/install-scripts/mac/bundle/ $TMP_BUNDLE_DIR 
    2425 
  • install-scripts/mac/dailyrun.sh

    r10345 r10534  
    1 #!/bin/bash 
     1#!/bin/bash -e 
    22# 
    33# Should be run as: sudo ./dailyrun.sh 
    44# 
     5 
     6#FORCE=true 
     7#LOCAL=true 
    58 
    69test -r /sw/bin/init.sh && . /sw/bin/init.sh 
     
    811export PATH=$HOME/bin:$PATH 
    912 
    10 STABLE_REVISION_1=`svn info --non-interactive http://orange.biolab.si/svn/orange/branches/ver1.0/ | grep 'Last Changed Rev:' | cut -d ' ' -f 4` 
    11 # svn info does not return proper exit status on an error so we check it this way 
    12 [ "$STABLE_REVISION_1" ] || exit 1 
    13 STABLE_REVISION_2=`svn info --non-interactive http://orange.biolab.si/svn/orange/externals/branches/ver1.0/ | grep 'Last Changed Rev:' | cut -d ' ' -f 4` 
    14 # svn info does not return proper exit status on an error so we check it this way 
    15 [ "$STABLE_REVISION_2" ] || exit 1 
     13WORK_DIR=/private/tmp/repos 
    1614 
    17 if [[ $STABLE_REVISION_1 -gt $STABLE_REVISION_2 ]]; then 
    18     STABLE_REVISION=$STABLE_REVISION_1 
     15if [ $LOCAL ]; then 
     16    PUBLISH_DIR=/private/tmp/download 
     17    mkdir -p $PUBLISH_DIR 
    1918else 
    20     STABLE_REVISION=$STABLE_REVISION_2 
     19    PUBLISH_DIR=/Volumes/download 
    2120fi 
    2221 
    23 DAILY_REVISION_1=`svn info --non-interactive http://orange.biolab.si/svn/orange/trunk/ | grep 'Last Changed Rev:' | cut -d ' ' -f 4` 
    24 # svn info does not return proper exit status on an error so we check it this way 
    25 [ "$DAILY_REVISION_1" ] || exit 1 
    26 DAILY_REVISION_2=`svn info --non-interactive http://orange.biolab.si/svn/orange/externals/trunk/ | grep 'Last Changed Rev:' | cut -d ' ' -f 4` 
    27 # svn info does not return proper exit status on an error so we check it this way 
    28 [ "$DAILY_REVISION_2" ] || exit 1 
     22if [ ! -e $WORK_DIR ]; then 
     23    mkdir -p $WORK_DIR 
     24fi 
    2925 
    30 if [[ $DAILY_REVISION_1 -gt $DAILY_REVISION_2 ]]; then 
    31     DAILY_REVISION=$DAILY_REVISION_1 
    32 else 
    33     DAILY_REVISION=$DAILY_REVISION_2 
     26SOURCE_LOG=/private/tmp/sources-daily-build.log 
     27 
     28# Build source packages 
     29./build-source.sh https://bitbucket.org/biolab/orange orange tip $WORK_DIR Orange > $SOURCE_LOG 2>&1 
     30EXIT_VALUE1=$? 
     31./build-source.sh https://bitbucket.org/biolab/orange-addon-bioinformatics bioinformatics tip $WORK_DIR Orange-Bioinformatics >> $SOURCE_LOG 2>&1 
     32EXIT_VALUE2=$? 
     33./build-source.sh https://bitbucket.org/biolab/orange-addon-text text tip $WORK_DIR Orange-Text-Mining >> $SOURCE_LOG 2>&1 
     34EXIT_VALUE3=$? 
     35 
     36if [ ! $LOCAL ]; then 
     37    /Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
    3438fi 
     39 
     40echo "Orange (sources) [$EXIT_VALUE1 $EXIT_VALUE2 $EXIT_VALUE3]" > "/Volumes/download/buildLogs/osx/source-daily-build-hg.log" 
     41date >> "/Volumes/download/buildLogs/osx/source-daily-build-hg.log" 
     42cat $SOURCE_LOG > "/Volumes/download/buildLogs/osx/source-daily-build-hg.log" 
     43(($EXIT_VALUE1 + $EXIT_VALUE2 + $EXIT_VALUE3)) && echo "Daily sources failed" 
     44 
     45# Get versions from PKG-INFO files 
     46ORANGE_VERSION=`grep "^Version:" $WORK_DIR/Orange.egg-info/PKG-INFO | cut -d " " -f 2` 
     47BIOINFORMATICS_VERSION=`grep "^Version:" $WORK_DIR/Orange_Bioinformatics.egg-info/PKG-INFO | cut -d " " -f 2` 
     48TEXT_VERSION=`grep "^Version:" $WORK_DIR/Orange_Text_Mining.egg-info/PKG-INFO | cut -d " " -f 2` 
     49 
     50 
     51# Source filenames 
     52ORANGE_SOURCE="Orange-${ORANGE_VERSION}.tar.gz" 
     53BIOINFORMATICS_SOURCE="Orange-Bioinformatics-${BIOINFORMATICS_VERSION}.tar.gz" 
     54TEXT_SOURCE="Orange-Text-Mining-${TEXT_VERSION}.tar.gz" 
     55 
     56 
     57# Get source packages md5 checksum 
     58ORANGE_SOURCE_MD5=`md5 -q $WORK_DIR/$ORANGE_SOURCE` 
     59BIOINFORMATICS_SOURCE_MD5=`md5 -q $WORK_DIR/$BIOINFORMATICS_SOURCE` 
     60TEXT_SOURCE_MD5=`md5 -q $WORK_DIR/$TEXT_SOURCE` 
     61 
    3562 
    3663MAC_VERSION=`sw_vers -productVersion | cut -d '.' -f 2` 
     
    3966defaults write com.apple.desktopservices DSDontWriteNetworkStores true 
    4067 
    41 /Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
     68if [ ! $LOCAL ]; then 
     69    /Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
     70fi 
    4271 
    43 ## Daily build from hg 
    44 /Users/ailabc/bundle-daily-build-hg.sh &> /private/tmp/bundle-daily-build.log 
    45 EXIT_VALUE=$? 
     72# Base url for sources 
     73if [ $LOCAL ]; then 
     74    BASE_URL="file://$PUBLISH_DIR/sources" 
     75else 
     76    BASE_URL="http://orange.biolab.si/download/sources" 
     77fi 
    4678 
    47 /Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
     79# Base dir for sources 
     80SOURCES_DIR=$PUBLISH_DIR/sources 
     81 
     82 
     83# Publish sources 
     84 
     85if [ ! -e $SOURCES_DIR ]; then 
     86    mkdir -p $SOURCES_DIR 
     87fi 
     88 
     89if [[ ! -e $SOURCES_DIR/$ORANGE_SOURCE || $FORCE ]]; then 
     90    cp $WORK_DIR/$ORANGE_SOURCE $SOURCES_DIR/$ORANGE_SOURCE 
     91    NEW_ORANGE=1 
     92fi 
     93 
     94if [[ ! -e $SOURCES_DIR/BIOINFORMATICS_SOURCE || $FORCE ]]; then 
     95    cp $WORK_DIR/$BIOINFORMATICS_SOURCE $SOURCES_DIR/$BIOINFORMATICS_SOURCE 
     96    NEW_BIOINFORMATICS=1 
     97fi 
     98 
     99if [[ ! -e $SOURCES_DIR/TEXT_SOURCE || $FORCE ]]; then 
     100    cp $WORK_DIR/$TEXT_SOURCE $SOURCES_DIR/$TEXT_SOURCE 
     101    NEW_TEXT=1 
     102fi 
     103 
     104FINK_ROOT=/sw 
     105 
     106# Update the local finkinfo  
     107# Local info files will be copied to biolab/main/finkinfo in fink-daily-build-packages.sh 
     108FINK_INFO_DIR="$FINK_ROOT/fink/dists/local/main/finkinfo" 
     109 
     110if [ ! -e $FINK_INFO_DIR ]; then 
     111    mkdir -p $FINK_INFO_DIR 
     112fi 
     113 
     114# Directory where fink .info templates are 
     115FINK_TEMPLATES=$WORK_DIR/orange/install-scripts/mac/fink 
     116 
     117FINK_LOG=/private/tmp/bundle-daily-build.log 
     118echo "" > $FINK_LOG 
     119 
     120if [[ $NEW_ORANGE || $FORCE ]]; then 
     121    FINK_ORANGE_SOURCE_TEMPLATE="Orange-%v.tar.gz" 
     122    ./fink-register-info.sh "$FINK_TEMPLATES/orange-gui-hg-py.info" $BASE_URL/$FINK_ORANGE_SOURCE_TEMPLATE $ORANGE_SOURCE_MD5 $ORANGE_VERSION $FINK_INFO_DIR/orange-gui-hg-py.info >> $FINK_LOG 2>&1 
     123fi 
     124 
     125if [[ $NEW_BIOINFORMATICS || $FORCE ]]; then 
     126    FINK_BIOINFORMATICS_SOURCE_TEMPLATE="Orange-Bioinformatics-%v.tar.gz" 
     127    ./fink-register-info.sh "$FINK_TEMPLATES/orange-bioinformatics-gui-hg-py.info" $BASE_URL/$FINK_BIOINFORMATICS_SOURCE_TEMPLATE $BIOINFORMATICS_SOURCE_MD5 $BIOINFORMATICS_VERSION $FINK_INFO_DIR/orange-bioinformatics-gui-hg-py.info >> $FINK_LOG 2>&1 
     128fi 
     129 
     130if [[ $NEW_TEXT || $FORCE ]]; then 
     131    FINK_TEXT_SOURCE_TEMPLATE="Orange-Text-Mining-%v.tar.gz" 
     132    ./fink-register-info.sh "$FINK_TEMPLATES/orange-text-gui-hg-py.info" $BASE_URL/$FINK_TEXT_SOURCE_TEMPLATE $TEXT_SOURCE_MD5 $TEXT_VERSION $FINK_INFO_DIR/orange-text-gui-hg-py.info >> $FINK_LOG 2>&1 
     133fi 
     134 
     135if [ ! $LOCAL ]; then 
     136    /Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
     137fi 
     138 
     139 
     140## Daily bundle build from hg 
     141if [[ $NEW_ORANGE || $NEW_BIOINFORMATICS || $NEW_TEXT || $FORCE ]]; then 
     142    /Users/ailabc/bundle-daily-build-hg.sh &> /private/tmp/bundle-daily-build.log 
     143    EXIT_VALUE=$? 
     144fi 
     145 
     146if [ ! $LOCAL ]; then 
     147    /Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
     148fi 
    48149 
    49150echo "Orange (bundle $MAC_VERSION from hg) [$EXIT_VALUE]" > "/Volumes/download/buildLogs/osx/bundle-$MAC_VERSION-daily-build-hg.log" 
     
    53154 
    54155 
    55 #/Users/ailabc/bundle-daily-build.sh $STABLE_REVISION $DAILY_REVISION &> /private/tmp/bundle-daily-build.log 
    56 #EXIT_VALUE=$? 
    57 # 
    58 #/Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
    59 # 
    60 #echo "Orange (bundle $MAC_VERSION) [$EXIT_VALUE]" > "/Volumes/download/buildLogs/osx/bundle-$MAC_VERSION-daily-build.log" 
    61 #date >> "/Volumes/download/buildLogs/osx/bundle-$MAC_VERSION-daily-build.log" 
    62 #cat /private/tmp/bundle-daily-build.log >> "/Volumes/download/buildLogs/osx/bundle-$MAC_VERSION-daily-build.log" 
    63 #(($EXIT_VALUE)) && echo "Running bundle-daily-build.sh failed" 
    64 # 
    65 #/Users/ailabc/bundle-64bit-daily-build.sh $DAILY_REVISION &> /private/tmp/bundle-64bit-daily-build.log 
    66 #EXIT_VALUE=$? 
     156## daily fink build 
    67157 
    68 #/Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
    69 # 
    70 #echo "Orange (bundle $MAC_VERSION 64bit) [$EXIT_VALUE]" > "/Volumes/download/buildLogs/osx/bundle-$MAC_VERSION-64bit-daily-build.log" 
    71 #date >> "/Volumes/download/buildLogs/osx/bundle-$MAC_VERSION-64bit-daily-build.log" 
    72 #cat /private/tmp/bundle-64bit-daily-build.log >> "/Volumes/download/buildLogs/osx/bundle-$MAC_VERSION-64bit-daily-build.log" 
    73 #(($EXIT_VALUE)) && echo "Running bundle-64bit-daily-build.sh failed" 
    74  
    75 /Users/ailabc/fink-daily-build.sh $STABLE_REVISION $DAILY_REVISION &> /private/tmp/fink-daily-build.log 
     158/Users/ailabc/fink-daily-build-packages.sh &> /private/tmp/fink-daily-build-packages.log 
    76159EXIT_VALUE=$? 
    77160 
    78 /Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
     161if [ ! $LOCAL ]; then 
     162    /Users/ailabc/mount-dirs.sh || { echo "Mounting failed." ; exit 1 ; } 
     163fi 
    79164 
    80165echo "Orange (fink $MAC_VERSION $ARCH) [$EXIT_VALUE]" > "/Volumes/download/buildLogs/osx/fink-$MAC_VERSION-$ARCH-daily-build.log" 
    81166date >> "/Volumes/download/buildLogs/osx/fink-$MAC_VERSION-$ARCH-daily-build.log" 
    82 cat /private/tmp/fink-daily-build.log >> "/Volumes/download/buildLogs/osx/fink-$MAC_VERSION-$ARCH-daily-build.log" 
     167cat /private/tmp/fink-daily-build-packages.log >> "/Volumes/download/buildLogs/osx/fink-$MAC_VERSION-$ARCH-daily-build.log" 
    83168(($EXIT_VALUE)) && echo "Running fink-daily-build.sh failed" 
    84169 
  • install-scripts/mac/update-all-scripts.sh

    r10342 r10505  
    2222curl --silent --output bundle-inject-pypi.sh https://bitbucket.org/biolab/orange/raw/tip/install-scripts/mac/bundle-inject-pypi.sh 
    2323curl --silent --output dailyrun-bundleonly-hg.sh https://bitbucket.org/biolab/orange/raw/tip/install-scripts/mac/dailyrun-bundleonly-hg.sh 
     24curl --silent --output fink-daily-build-packages.sh https://bitbucket.org/biolab/orange/raw/tip/install-scripts/mac/fink-daily-build-packages.sh 
     25curl --silent --output fink-register-info.sh https://bitbucket.org/biolab/orange/raw/tip/install-scripts/mac/fink-register-info.sh 
     26curl --silent --output build-source.sh https://bitbucket.org/biolab/orange/raw/tip/install-scripts/mac/build-source.sh 
    2427 
    2528chmod +x *.sh 
  • setup.py

    r10471 r10507  
    676676    version = full_version 
    677677""" 
    678     global VERSION 
    679      
    680678    FULLVERSION = VERSION 
    681679    if os.path.exists('.hg'): 
     
    700698    finally: 
    701699        a.close() 
    702      
    703     if not ISRELEASED: 
    704         VERSION = FULLVERSION  
    705700 
    706701def setup_package(): 
  • source/orange/lib_learner.cpp

    r10377 r10517  
    20992099    bool setPrefixRules; 
    21002100    bool optimizeBetasFlag; 
    2101  
    2102     if (!PyArg_ParseTuple(args, "O&ffO&|O&iiO&O&:RuleClassifier.call", cc_RuleList, &rules, &minSignificance, &minBeta, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &setPrefixRules, &optimizeBetasFlag, cc_Classifier, &classifier, cc_DistributionList, &probList)) 
    2103       return PYNULL; 
    2104  
    2105     TRuleClassifier *rc = new TRuleClassifier_logit(rules, minSignificance, minBeta, gen, weightID, classifier, probList,setPrefixRules, optimizeBetasFlag); 
     2101    float penalty = 0.01f; 
     2102 
     2103    if (!PyArg_ParseTuple(args, "O&fffO&|O&iiO&O&:RuleClassifier.call", cc_RuleList, &rules, &minSignificance, &minBeta, &penalty, pt_ExampleGenerator, &gen, pt_weightByGen(gen), &weightID, &setPrefixRules, &optimizeBetasFlag, cc_Classifier, &classifier, cc_DistributionList, &probList)) 
     2104      return PYNULL; 
     2105 
     2106    TRuleClassifier *rc = new TRuleClassifier_logit(rules, minSignificance, minBeta, penalty, gen, weightID, classifier, probList, setPrefixRules, optimizeBetasFlag); 
    21062107    PRuleClassifier ruleClassifier = rc; 
    21072108//    ruleClassifier = new SELF_AS(TRuleClassifier)(rules, gen, weightID); 
  • source/orange/rulelearner.cpp

    r8735 r10531  
    4545: weightID(0), 
    4646  quality(ILLEGAL_FLOAT), 
    47   complexity(-1), 
     47  complexity(0), 
    4848  coveredExamples(NULL), 
    4949  coveredExamplesLength(-1), 
     
    9393 
    9494TRule::~TRule() 
    95 { delete coveredExamples; } 
     95{   delete coveredExamples; } 
    9696 
    9797bool TRule::operator ()(const TExample &ex) 
     
    986986           improved/rule->classDistribution->atint(targetClass) > min_improved_perc*0.01 && 
    987987           quality > (aprioriProb + 1e-3)) 
    988     futureQuality = quality; 
    989 //    futureQuality = 1.0 + quality; 
     988//    futureQuality = quality; 
     989    futureQuality = 1.0 + quality; 
    990990  else { 
    991991    PDistribution oldRuleDist = rule->classDistribution; 
     
    10161016      futureQuality = -1.0; 
    10171017    else { 
    1018       futureQuality = 0.0; 
     1018      futureQuality = 0.0;  
    10191019      PEITERATE(ei, rule->examples) { 
    10201020        if ((*ei).getClass().intV != targetClass) 
     
    10231023          continue; 
    10241024        } 
    1025         float x = ((*ei)[probVar].floatV-quality); //*rule->classDistribution->abs; 
    1026         if ((*ei)[probVar].floatV > quality) 
     1025      /*  float x = ((*ei)[probVar].floatV-quality); //*rule->classDistribution->abs; 
     1026        if ((*ei)[probVar].floatV > quality)  
    10271027          x *= (1.0-quality)/(bestQuality-quality); 
    10281028        x /= sqrt(quality*(1.0-quality)); // rule->classDistribution->abs* 
    1029         futureQuality += log(1.0-max(1e-12,1.0-2*zprob(x))); 
    1030       } 
    1031       futureQuality = 1.0 - exp(futureQuality); 
     1029        futureQuality += log(1.0-max(1e-12,1.0-2*zprob(x))); */ 
     1030        float x; 
     1031        if ((*ei)[probVar].floatV > quality) 
     1032        { 
     1033            x = 1.0 - ((*ei)[probVar].floatV-quality) / (bestQuality-quality); 
     1034        } 
     1035        else 
     1036        { 
     1037            x = 1.0 + quality - (*ei)[probVar].floatV; 
     1038        } 
     1039        futureQuality += x; 
     1040      } 
     1041//      futureQuality = 1.0 - exp(futureQuality); 
     1042      futureQuality /= rule->classDistribution->atint(targetClass); 
    10321043    } 
    10331044  } 
     
    19591970{ 
    19601971    PITERATE(TIntList, ind, ruleIndices[rule_i]) 
    1961   { 
    1962     float bestQuality = 0.0; 
    1963         PITERATE(TIntList, fr, prefixRules) { 
    1964               if (rules->at(*fr)->call(examples->at(*ind)) && rules->at(*fr)->quality > bestQuality) { 
    1965           bestQuality = rules->at(*fr)->quality; 
    1966                   p[getClassIndex(rules->at(*fr))][*ind] = rules->at(*fr)->quality; 
    1967                   for (int ci=0; ci<examples->domain->classVar->noOfValues(); ci++) 
    1968                       if (ci!=getClassIndex(rules->at(*fr))) 
    1969                           p[ci][*ind] = (1.0-rules->at(*fr)->quality)/(examples->domain->classVar->noOfValues()-1); 
    1970                   break; 
    1971               } 
    1972       } 
    1973   } 
     1972    { 
     1973        float bestQuality = 0.0; 
     1974        PITERATE(TIntList, fr, prefixRules) { 
     1975            if (rules->at(*fr)->call(examples->at(*ind)) && rules->at(*fr)->quality > bestQuality) { 
     1976                bestQuality = rules->at(*fr)->quality; 
     1977                p[getClassIndex(rules->at(*fr))][*ind] = rules->at(*fr)->quality; 
     1978                for (int ci=0; ci<examples->domain->classVar->noOfValues(); ci++) 
     1979                if (ci!=getClassIndex(rules->at(*fr))) 
     1980                    p[ci][*ind] = (1.0-rules->at(*fr)->quality)/(examples->domain->classVar->noOfValues()-1); 
     1981                break; 
     1982            } 
     1983        } 
     1984    } 
    19741985} 
    19751986 
     
    20182029void TLogitClassifierState::setPrefixRule(int rule_i) //, int position) 
    20192030{ 
    2020     prefixRules->push_back(rule_i); 
    2021     setFixed(rule_i); 
    2022     updateFixedPs(rule_i); 
    2023     betas[rule_i] = 0.0; 
    2024   computeAvgProbs(); 
    2025   computePriorProbs(); 
     2031    prefixRules->push_back(rule_i); 
     2032    setFixed(rule_i); 
     2033    updateFixedPs(rule_i); 
     2034    betas[rule_i] = 0.0; 
     2035    computeAvgProbs(); 
     2036    computePriorProbs(); 
    20262037} 
    20272038 
     
    20302041{} 
    20312042 
    2032 TRuleClassifier_logit::TRuleClassifier_logit(PRuleList arules, const float &minSignificance, const float &minBeta, PExampleTable anexamples, const int &aweightID, const PClassifier &classifier, const PDistributionList &probList, bool setPrefixRules, bool optimizeBetasFlag) 
     2043TRuleClassifier_logit::TRuleClassifier_logit(PRuleList arules, const float &minSignificance, const float &minBeta, const float &penalty, PExampleTable anexamples, const int &aweightID, const PClassifier &classifier, const PDistributionList &probList, bool setPrefixRules, bool optimizeBetasFlag) 
    20332044: TRuleClassifier(arules, anexamples, aweightID), 
    20342045  minSignificance(minSignificance), 
     
    20362047  setPrefixRules(setPrefixRules), 
    20372048  optimizeBetasFlag(optimizeBetasFlag), 
    2038   minBeta(minBeta) 
     2049  minBeta(minBeta), 
     2050  penalty(penalty) 
    20392051{ 
    20402052  initialize(probList); 
    20412053  float step = 2.0; 
    2042   minStep = (float)0.01; 
    20432054 
    20442055  // initialize prior betas 
     
    20512062  if (setPrefixRules) 
    20522063  { 
    2053       bool changed = setBestPrefixRule(); 
    2054       while (changed) { 
    2055         if (optimizeBetasFlag) 
    2056             optimizeBetas(); 
    2057         changed = setBestPrefixRule(); 
    2058       } 
     2064    bool changed = setBestPrefixRule(); 
     2065    while (changed) { 
     2066        if (optimizeBetasFlag) 
     2067            optimizeBetas(); 
     2068        changed = setBestPrefixRule(); 
     2069    } 
    20592070  } 
    20602071 
     
    22072218  wsig = sig; 
    22082219  PITERATE(TRuleList, ri, rules) { 
    2209     float maxDiff = (*ri)->classDistribution->atint(getClassIndex(*ri))/(*ri)->classDistribution->abs; 
    2210       maxDiff -= (*ri)->quality; 
    2211       wsig->push_back(maxDiff); 
    2212    float n = (*ri)->examples->numberOfExamples(); 
     2220    float maxDiff = (*ri)->classDistribution->atint(getClassIndex(*ri))/(*ri)->classDistribution->abs; 
     2221    maxDiff -= (*ri)->quality; 
     2222    wsig->push_back(maxDiff); 
     2223    float n = (*ri)->examples->numberOfExamples(); 
    22132224    float a = n*(*ri)->quality; 
    22142225    float b = n*(1.0-(*ri)->quality); 
     
    22722283        if ((*ri)->call(*ei)) { 
    22732284          //int vv = (*ei).getClass().intV; 
    2274               //if ((*ei).getClass().intV == getClassIndex(*ri)) 
    2275                 coverages[getClassIndex(*ri)][j] += 1.0; 
     2285          //if ((*ei).getClass().intV == getClassIndex(*ri)) 
     2286          coverages[getClassIndex(*ri)][j] += 1.0; 
    22762287        } 
    2277           j++; 
     2288        j++; 
    22782289      } 
    22792290      i++; 
     
    23132324 
    23142325    float step = 0.1f; 
    2315     float gamma = 0.01f; 
    23162326    float error = 1e+20f; 
    23172327    float old_error = 1e+21f; 
    23182328 
     2329    int nsteps = 0; 
    23192330    while (old_error > error || step > 0.00001) 
    23202331    { 
    23212332        // reduce step if improvement failed 
    2322         if (old_error < error) 
     2333        nsteps++; 
     2334        if (old_error < error && nsteps > 20 || nsteps > 1000) 
    23232335        { 
     2336            nsteps = 0; 
    23242337            step /= 10; 
    23252338            finalState->copyTo(currentState); 
     
    23352348 
    23362349            float der = 0.0; 
    2337             if (currentState->avgProb->at(i) < rules->at(i)->quality) 
    2338                 der -= rules->at(i)->quality - currentState->avgProb->at(i); 
    2339             der += 2*gamma*currentState->betas[i]; 
     2350            if (currentState->avgProb->at(i) > rules->at(i)->quality) 
     2351            { 
     2352                der += pow(rules->at(i)->quality - currentState->avgProb->at(i),2); 
     2353                der -= 2 * (rules->at(i)->quality - currentState->avgProb->at(i)) * currentState->betas[i]; 
     2354            } 
     2355            else 
     2356                der -= 2 * (rules->at(i)->quality - currentState->avgProb->at(i)); 
     2357            der += 2 * penalty * currentState->betas[i]; 
     2358//            if (currentState->avgProb->at(i) > rules->at(i)->quality) 
     2359//                der = max(0.01f / step, der); 
    23402360            currentState->newBeta(i,max(0.0f, currentState->betas[i]-step*der)); 
    23412361        } 
     
    23432363        error = 0; 
    23442364        for (int i=0; i<rules->size(); i++) { 
    2345             if (currentState->avgProb->at(i) < rules->at(i)->quality) 
    2346                 error += rules->at(i)->quality - currentState->avgProb->at(i); 
    2347             error += gamma*pow(currentState->betas[i],2); 
     2365//            if (currentState->avgProb->at(i) < rules->at(i)->quality) 
     2366            if (currentState->avgProb->at(i) > rules->at(i)->quality) 
     2367                error += pow(rules->at(i)->quality - currentState->avgProb->at(i),2) * currentState->betas[i]; 
     2368            else 
     2369                error += pow(rules->at(i)->quality - currentState->avgProb->at(i),2); 
     2370            error += penalty*pow(currentState->betas[i],2); 
    23482371        } 
    23492372        //printf("error = %4.4f\n", error); 
     
    23532376        //printf("\n");  
    23542377    } 
     2378 
    23552379    finalState->copyTo(currentState); 
    23562380} 
    2357  
    2358 /* 
    2359 void TRuleClassifier_logit::updateRuleBetas2(float step_) 
    2360 { 
    2361  
    2362   stabilizeAndEvaluate(step_,-1); 
    2363   PLogitClassifierState finalState, tempState; 
    2364   currentState->copyTo(finalState); 
    2365  
    2366   float step = 2.0; 
    2367   int changed; 
    2368   float worst_underestimate, underestimate; 
    2369   float auc = currentState->getAUC(); 
    2370   float brier = currentState->getBrierScore(); 
    2371   float temp_auc, temp_brier; 
    2372   int worst_rule_index; 
    2373   while (step > 0.001) 
    2374   { 
    2375       step /= 2; 
    2376       changed = 0; 
    2377       while (changed < 100) 
    2378       { 
    2379         changed = 0; 
    2380         worst_underestimate = (float)0.01; 
    2381         worst_rule_index = -1; 
    2382         // find rule with greatest underestimate in probability 
    2383         for (int i=0; i<rules->size(); i++) { 
    2384             if (currentState->avgProb->at(i) >= rules->at(i)->quality) 
    2385                 continue; 
    2386             if (skipRule[i]) 
    2387                 continue; 
    2388  
    2389             underestimate = (rules->at(i)->quality - currentState->avgProb->at(i));//*rules->at(i)->classDistribution->abs; 
    2390             // if under estimate error is big enough 
    2391             if (underestimate > worst_underestimate) 
    2392             { 
    2393                 worst_underestimate = underestimate; 
    2394                 worst_rule_index = i; 
    2395             } 
    2396         } 
    2397         if (worst_rule_index > -1) 
    2398         { 
    2399             currentState->newBeta(worst_rule_index,currentState->betas[worst_rule_index]+step); 
    2400             if (currentState->avgProb->at(worst_rule_index) > rules->at(worst_rule_index)->quality) 
    2401             { 
    2402                 finalState->copyTo(currentState); 
    2403                 changed = 100; 
    2404             } 
    2405             else 
    2406             { 
    2407               stabilizeAndEvaluate(step,-1); 
    2408               temp_auc = currentState->getAUC(); 
    2409               temp_brier = currentState->getBrierScore(); 
    2410               if (temp_auc >= auc && temp_brier < brier) 
    2411               { 
    2412                 currentState->copyTo(finalState); 
    2413                 changed = 0; 
    2414                 auc = temp_auc; 
    2415                 brier = temp_brier; 
    2416               } 
    2417               else 
    2418                 changed ++; 
    2419             } 
    2420          // } 
    2421         } 
    2422         else 
    2423         { 
    2424           changed = 100; 
    2425           finalState->copyTo(currentState); 
    2426         } 
    2427       } 
    2428   } 
    2429   finalState->copyTo(currentState); 
    2430 } 
    2431 */ 
    2432  
    2433 void TRuleClassifier_logit::stabilizeAndEvaluate(float & step, int last_changed_rule_index) 
    2434 { 
    2435     PLogitClassifierState tempState; 
    2436     currentState->copyTo(tempState); 
    2437     bool changed = true; 
    2438     while (changed) 
    2439     { 
    2440         changed = false; 
    2441         for (int i=0; i<rules->size(); i++) 
    2442         { 
    2443             if (currentState->avgProb->at(i) > (rules->at(i)->quality + 0.01) && currentState->betas[i] > 0.0 && 
    2444                 i != last_changed_rule_index) 
    2445             { 
    2446                 float new_beta = currentState->betas[i]-step > 0 ? currentState->betas[i]-step : 0.0; 
    2447                 currentState->newBeta(i,new_beta); 
    2448                 if (currentState->avgProb->at(i) < rules->at(i)->quality + 1e-6) 
    2449                 { 
    2450                     tempState->copyTo(currentState); 
    2451                 } 
    2452                 else 
    2453                 { 
    2454                     currentState->copyTo(tempState); 
    2455                     changed = true; 
    2456                 } 
    2457             } 
    2458         } 
    2459     } 
    2460 } 
    2461  
    24622381 
    24632382void TRuleClassifier_logit::addPriorClassifier(const TExample &ex, double * priorFs) { 
     
    25162435  bool foundPrefixRule = false; 
    25172436  float bestQuality = 0.0; 
    2518   PITERATE(TRuleList, rs, prefixRules) { 
    2519       if ((*rs)->call(ex) && (*rs)->quality > bestQuality) { 
    2520       bestQuality = (*rs)->quality; 
    2521           dist->setint(getClassIndex(*rs),(*rs)->quality); 
    2522           for (int ci=0; ci<examples->domain->classVar->noOfValues(); ci++) 
    2523             if (ci!=getClassIndex(*rs)) 
    2524                 dist->setint(ci,(1.0-(*rs)->quality)/(examples->domain->classVar->noOfValues()-1)); 
    2525       foundPrefixRule = true; 
    2526       break; 
    2527       } 
     2437  PITERATE(TRuleList, rs, prefixRules) {     
     2438    if ((*rs)->call(ex) && (*rs)->quality > bestQuality) { 
     2439        bestQuality = (*rs)->quality; 
     2440        dist->setint(getClassIndex(*rs),(*rs)->quality); 
     2441            for (int ci=0; ci<examples->domain->classVar->noOfValues(); ci++) 
     2442            if (ci!=getClassIndex(*rs)) 
     2443                dist->setint(ci,(1.0-(*rs)->quality)/(examples->domain->classVar->noOfValues()-1)); 
     2444        foundPrefixRule = true; 
     2445        break; 
     2446      } 
    25282447  } 
    25292448  if (foundPrefixRule) 
     
    25452464      if ((*r)->call(cexample)) { 
    25462465        if (getClassIndex(*r) == i) 
    2547             f += (*b); 
     2466            f += (*b); 
    25482467        else if (getClassIndex(*r) == res->noOfElements()-1) 
    2549           f -= (*b); 
     2468            f -= (*b); 
    25502469      } 
    25512470    dist->addint(i,exp(f)); 
  • source/orange/rulelearner.hpp

    r8735 r10517  
    482482  __REGISTER_CLASS 
    483483 
    484   PRuleList rules; 
    485   PExampleTable examples; 
     484  PRuleList rules; //P 
     485  PExampleTable examples; //P 
    486486  int weightID; 
    487487 
    488488  float eval, **f, **p, *betas, *priorBetas; 
    489489  bool *isExampleFixed; 
    490   PFloatList avgProb, avgPriorProb; 
    491   PIntList *ruleIndices, prefixRules; 
     490  PFloatList avgProb; //P 
     491  PFloatList avgPriorProb; //P 
     492  PIntList *ruleIndices; //P 
     493  PIntList prefixRules; //P 
    492494 
    493495  TLogitClassifierState(PRuleList, PExampleTable, const int &); 
     
    515517  PDomain domain; //P Domain 
    516518  PFloatList ruleBetas; //P Rule betas 
    517   float minStep; //P minimal step value 
    518519  float minSignificance; //P minimum requested significance for betas.  
    519520  float minBeta; //P minimum beta by rule to be included in the model.  
    520   bool setPrefixRules; // P should we order prefix rules ?  
    521   bool optimizeBetasFlag; // P should we assign betas to rules ?  
     521  bool setPrefixRules; //P should we order prefix rules ?  
     522  bool optimizeBetasFlag; //P should we assign betas to rules ?  
     523  float penalty; //P 
    522524 
    523525  PClassifier priorClassifier; //P prior classifier used if provided 
    524   PLogitClassifierState currentState; 
     526  PLogitClassifierState currentState; //P 
    525527  bool *skipRule; 
    526   PFloatList wsd, wavgCov, wSatQ, wsig; // standard deviations of rule quality 
     528  // standard deviations of rule quality 
     529  PFloatList wsd; //P 
     530  PFloatList wavgCov; //P 
     531  PFloatList wSatQ; //P 
     532  PFloatList wsig; //P 
    527533  PRuleList prefixRules; //P rules that trigger before logit sum. 
    528534 
    529535  TRuleClassifier_logit(); 
    530   TRuleClassifier_logit(PRuleList rules, const float &minSignificance, const float &minBeta, PExampleTable examples, const int &weightID = 0, const PClassifier &classifer = NULL, const PDistributionList &probList = NULL, bool setPrefixRules = false, bool optimizeBetasFlag = true); 
     536  TRuleClassifier_logit(PRuleList rules, const float &minSignificance, const float &minBeta, const float &penalty, PExampleTable examples, const int &weightID = 0, const PClassifier &classifer = NULL, const PDistributionList &probList = NULL, bool setPrefixRules = false, bool optimizeBetasFlag = true); 
    531537 
    532538  void initialize(const PDistributionList &); 
  • source/orangeqt/CMakeLists.txt

    r9252 r10515  
    99find_package(SIP REQUIRED) 
    1010find_package(PythonLibrary REQUIRED) 
    11 find_package(OpenGL) 
     11#find_package(OpenGL) 
    1212find_package(Numpy) 
    1313include(SIPMacros) 
     
    2929    multicurve.cpp 
    3030    plot.cpp  
    31     plot3d.cpp 
    32     canvas3d.cpp 
    33     glextensions.cpp 
     31#    plot3d.cpp 
     32#    canvas3d.cpp 
     33#    glextensions.cpp 
    3434) 
    3535qt4_automoc(${orangeqt_SRCS}) 
     
    5151set(SIP_EXTRA_OPTIONS "-k") 
    5252 
    53 set(SIP_EXTRA_LINK_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${OPENGL_gl_LIBRARY}) 
     53#set(SIP_EXTRA_LINK_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY} ${QT_QTOPENGL_LIBRARY} ${OPENGL_gl_LIBRARY}) 
     54set(SIP_EXTRA_LINK_LIBRARIES ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) 
    5455set(SIP_EXTRA_SOURCES ${orangeqt_SRCS}) 
    5556 
  • source/orangeqt/orangeqt.sip

    r9057 r10515  
    22 
    33%Import QtGui/QtGuimod.sip 
    4 %Import QtOpenGL/QtOpenGLmod.sip  
     4/*%Import QtOpenGL/QtOpenGLmod.sip*/ 
    55 
    66%Include types.sip 
    77%Include plot.sip 
    8 %Include plot3d.sip 
    9 %Include canvas3d.sip 
     8/*%Include plot3d.sip 
     9%Include canvas3d.sip*/ 
    1010%Include plotitem.sip 
    1111%Include point.sip 
Note: See TracChangeset for help on using the changeset viewer.