def score(dealer): if rule() == player_card_rule: score_list[0] += -75 if rule() == ad1_card_rule: score_list[1] += -75 if rule() == ad2_card_rule: score_list[2] += -75 if rule() == ad3_card_rule: score_list[3] += -75 return score_list[0]
def __call__(self, example, resultType = orange.GetValue): # 1. calculate sum of distributions of examples that cover the example num_cover = 0.0 distribution = [0]* len(self.data.domain.classVar.values) for rsc in self.rulesClass: for rule in rsc.rules.rules: if rule.covers(example): num_cover += 1 tmp_dist = rule(example, orange.GetProbabilities) for i in range(len(distribution)): distribution[i] += tmp_dist[i] # 2. calculate average of distributions of rules that cover example if num_cover != 0: max_index = 0 for i in range(len(distribution)): distribution[i] = distribution[i]/num_cover if distribution[i] > distribution[max_index]: max_index = i dist = orange.DiscDistribution(distribution) value = orange.Value(self.data.domain.classVar ,self.data.domain.classVar.values[max_index]) # if no rule fiers else: value,dist = self.majorityClassifier(example, orange.GetBoth) # 3. -----------return if resultType == orange.GetValue : return value elif resultType == orange.GetBoth : return (value, dist) else : return dist
def _enforce_rules(self, link): """ enforce the rules to a link, with short-circuit execution; return whether the link satisfies the rules """ for rule in self.rules: if not rule(link): return False return True
def construct(self, data_dir): # create rule set rule_list = [rule() for rule in Rule.__subclasses__()] for root, dirs, files in os.walk(data_dir): for fn in files: if fn[-3:] == 'csv': driver_id = root.split('/')[-1] trip_id = fn.split('.')[0] vertex = extract_trips(driver_id, trip_id) self.vertices.append(vertex) # apply the rules for rule in rule_list: output = rule.classify(vertex) if output: vertex.add_rule(output) self.edges = [ edge for rule in rule_list for edge in rule.edges()]
def parse(self, raw, headOnly = False): assert isinstance(raw, bytes) self.next = None # In case of unfinished parsing self.raw = raw dlen = len(raw) if dlen < ctrl_frm.MIN_LEN: self.msg('warning CTRL packet data too short to parse header: data len %u' % (dlen,)) return (self.ver, self.type, self.len) \ = struct.unpack('!BBH', raw[:ctrl_frm.MIN_LEN]) if self.ver != ctrl_frm.VER: self.msg('(ctrl_frm parse) warning version %u not exp(%u)' % (self.ver, ctrl_frm.VER)) return # At this point, we are reasonably certain that we have an ctrl_frm # packet self.parsed = True length = self.len + ctrl_frm.MIN_LEN if headOnly: self.next = raw[ctrl_frm.MIN_LEN:length] return if length > dlen: length = dlen # Clamp to what we've got if self.type == ctrl_frm.IPGW_PACKET_IN: self.next = pkt_in(raw=raw[ctrl_frm.MIN_LEN:length], prev=self) elif self.type == ctrl_frm.IPGW_RULE_ADD or self.type == ctrl_frm.IPGW_RULE_RM: self.next = rule(raw=raw[ctrl_frm.MIN_LEN:length], prev=self) elif self.type == ctrl_frm.IPGW_SERVICE: self.next = service(raw=raw[ctrl_frm.MIN_LEN:length], prev=self) elif dlen - ctrl_frm.MIN_LEN < self.len: self.msg('(ctrl_frm parse) warning packet data shorter than len: %u < %u' % (dlen-ctrl_frm.MIN_LEN, self.len)) else: self.next = raw[ctrl_frm.MIN_LEN:length] if isinstance(self.next, packet_base) and not self.next.parsed: self.next = raw[ctrl_frm.MIN_LEN:length]
def evaluator(self, rule, data): cond_data = rule(data) score = self.err_func( cond_data )
def apply_rules(self): for rule in self.rules: self.df = rule(self.df)
def set_rule(data): temp = data[0] humid = data[1] gas = data[2] rule(temp,humid,gas)
from rule import * import random import card r = rule() r.setTrumpRank('5') r.setTrumpSuit('Spade') ''' test rule.getCardPnt(cd) test passed ''' ''' r = rule() r.setTrumpRank('5') r.setTrumpSuit('Heart') for i in xrange(0,54): cd = card.Card(i) print str(cd) + ' ' + str(r.getCardPnt(cd)) ''' ''' r = rule() r.setTrumpRank('A') r.setTrumpSuit('Heart') for i in xrange(0,54): cd = card.Card(i) print str(cd) + ' ' + str(r.getCardPnt(cd))
else: flag = 0 wrong.append(player_card_rule) print "player wrong", wrong if len(tuple1) > 0: list1.append(player_card_rule) hypothesis = prune(hypothesis, correct) print "adv", hypothesis else: print "OUR RULE:", "if(", hypothesis, ",True)" print "WITH ALTERNATE", checkAlternate.CheckAlternate( Main.wrong, hypothesis) print "these are wrong", Main.wrong print "these are CORRECT", Main.correct print boardState() if rule() == player_card_rule: score_list[0] = -25 dealer = 0 raise Exception('') #Adversary 1 plays ad1_card_rule = adversary1.play() if is_card(ad1_card_rule): del cards[0] cards.append(ad1_card_rule) test = correct[(len(correct) - 2):len(correct)] test.append(ad1_card_rule) p = parse(rule).evaluate(test) print "ad1", ad1_card_rule print "evaluate", p if p == True or p == 'True':