def adjust_for_register(self, weights): new_map = {} for k in weights.keys(): distance = abs(self.register_center-k)+1 new_map[k] = pow(distance, - self.register) weights = w.apply(new_map, weights) return w.ensure_safe(weights)
def adjust_for_uniformity(self, weights): new_map = {} for k in weights.keys(): occurrences = self.prev_picks.count(k) new_map[k] = pow(2, - self.uniformity * occurrences) weights = w.apply(new_map, weights) return w.ensure_safe(weights)
def adjust_for_directionality(self, weights): _PAST_NOTES_TO_COUNT = 6 new_map = {} direction_count = {'down':0, 'same':0, 'up':0} lpp = len(self.prev_picks) if lpp == 0: return weights for i in range(0,min(_PAST_NOTES_TO_COUNT, lpp-1)): picks = self.prev_picks[lpp-i-2:lpp-i] if picks[1] < picks[0]: direction_count['down'] += 1 elif picks[1] > picks[0]: direction_count['up'] += 1 else: direction_count['same'] += 1 direction_difference = direction_count['up'] - direction_count['down'] score = _PAST_NOTES_TO_COUNT - abs(direction_difference) + 1 sign = lambda x,y: x < y if direction_difference < 0: sign = lambda x,y: x > y for k in weights.keys(): prev_pick = self.prev_picks[-1:][0] if sign(prev_pick, k): new_map[k] = pow(score, self.directionality) weights = w.apply(new_map, weights) return w.ensure_safe(weights)
def adjust_for_directionality(self, weights): _PAST_NOTES_TO_COUNT = 6 new_map = {} direction_count = {'down': 0, 'same': 0, 'up': 0} lpp = len(self.prev_picks) if lpp == 0: return weights for i in range(0, min(_PAST_NOTES_TO_COUNT, lpp - 1)): picks = self.prev_picks[lpp - i - 2:lpp - i] if picks[1] < picks[0]: direction_count['down'] += 1 elif picks[1] > picks[0]: direction_count['up'] += 1 else: direction_count['same'] += 1 direction_difference = direction_count['up'] - direction_count['down'] score = _PAST_NOTES_TO_COUNT - abs(direction_difference) + 1 sign = lambda x, y: x < y if direction_difference < 0: sign = lambda x, y: x > y for k in weights.keys(): prev_pick = self.prev_picks[-1:][0] if sign(prev_pick, k): new_map[k] = pow(score, self.directionality) weights = w.apply(new_map, weights) return w.ensure_safe(weights)
def adjust_for_variance(self, weights): map = {} prev_picks = self.prev_picks[-self.max_length:] prev_picks_length = len(self.prev_picks) for k in weights.keys(): occurrence_score = sum([1/pow(prev_picks_length - index, 0.5) for index,val in enumerate(self.prev_picks) if self.identity(k, val)]) map[k] = pow(2, (- self.variance * occurrence_score)) return w.ensure_safe(w.apply(map, weights))
def adjust_for_linearity(self, weights): new_map = {} for k in weights.keys(): if len(self.prev_picks) == 0: distance = 0 else: distance = abs(k - self.prev_picks[-1]) new_map[k] = pow(2, (- self.linearity * distance)) weights = w.apply(new_map, weights) return w.ensure_safe(weights)
def adjust_for_linearity(self, weights): new_map = {} for k in weights.keys(): if len(self.prev_picks) == 0: distance = 0 else: distance = abs(k - self.prev_picks[-1]) new_map[k] = pow(2, (-self.linearity * distance)) weights = w.apply(new_map, weights) return w.ensure_safe(weights)
def adjust_for_leads(self, weights): map = {} if len(self.prev_picks) == 0: return weights prev = self.prev_picks[-1] if (prev not in self.leads.keys()): return weights leadChoices = self.leads[prev] if len(set(leadChoices.keys()).union(weights.keys())) == 0: return weights # lead choices and weights have no options in common for k,v in weights.items(): if k in leadChoices: map[k] = v else: map[k] = 0 return w.ensure_safe(w.apply(map, weights))
def adjust_for_spacing(self, weights): new_map = {k:1 for k in weights.keys()} for prev in self.prev_picks: octave = max(0, prev - 36) / 12 too_close = 0 if octave == 0: too_close = 11 elif octave == 1: too_close = 4 elif octave == 2: too_close = 2 for k in weights.keys(): if abs(prev - k) <= too_close: new_map[k] *= pow(0.5, self.spacing) weights = w.apply(new_map, weights) return w.ensure_safe(weights)
def adjust_for_balance(self,weights): location = 0. ons = 0 offs = 0 new_map = {} for pick in self.prev_picks: location += pick if int(location) == location: ons += 1 else: offs += 1 #print "offs",offs,"ons",ons for k in weights: if int(k) != k and int(location) != location or int(k) == k and int(location) == location: new_map[k] = pow(2, offs-ons) else: new_map[k] = pow(2, ons-offs) weights = w.apply(new_map, weights) #print weights return w.ensure_safe(weights)
def adjust_for_uniqueness(self, weights): for k, v in weights.items(): if k in self.prev_picks: weights[k] = v * pow(2., - self.uniqueness) return w.ensure_safe(weights)