Skip to content
Snippets Groups Projects
Commit 4618e1c4 authored by ale's avatar ale
Browse files

remove last_song from the total for normalization too

parent 0c15ef55
No related branches found
No related tags found
No related merge requests found
...@@ -53,17 +53,21 @@ class MarkovModel(object): ...@@ -53,17 +53,21 @@ class MarkovModel(object):
def normalize(self): def normalize(self):
norm_map = {} norm_map = {}
for key, target_map in self._map.iteritems(): for key, target_map in self._map.iteritems():
# We will explicitly drop this target to avoid repeating
# the same song more than once.
last_song = key[-1]
norm_vec = [] norm_vec = []
tot = sum(target_map.itervalues()) tot = cur = 0
cur = 0
for target, count in target_map.iteritems(): for target, count in target_map.iteritems():
# We explicitly drop this target to avoid repeating if target != last_song:
# the same song more than once. tot += count
if target == key[-1]: for target, count in target_map.iteritems():
continue if target != last_song:
cur += float(count) / tot cur += float(count) / tot
norm_vec.append((cur, target)) norm_vec.append((cur, target))
norm_map[key] = norm_vec norm_map[key] = norm_vec
self._map = norm_map self._map = norm_map
def suggest(self, prev): def suggest(self, prev):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment