Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
djrandom-py
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ale
djrandom-py
Commits
4618e1c4
Commit
4618e1c4
authored
13 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
remove last_song from the total for normalization too
parent
0c15ef55
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/djrandom/model/markov.py
+12
-8
12 additions, 8 deletions
server/djrandom/model/markov.py
with
12 additions
and
8 deletions
server/djrandom/model/markov.py
+
12
−
8
View file @
4618e1c4
...
...
@@ -53,17 +53,21 @@ class MarkovModel(object):
def
normalize
(
self
):
norm_map
=
{}
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
=
[]
tot
=
sum
(
target_map
.
itervalues
())
cur
=
0
tot
=
cur
=
0
for
target
,
count
in
target_map
.
iteritems
():
# We explicitly drop this target to avoid repeati
ng
# the same song more than once.
i
f
target
==
key
[
-
1
]
:
continue
if
target
!=
last_so
ng
:
tot
+=
count
for
target
,
count
i
n
target
_map
.
iteritems
()
:
if
target
!=
last_song
:
cur
+=
float
(
count
)
/
tot
norm_vec
.
append
((
cur
,
target
))
norm_map
[
key
]
=
norm_vec
self
.
_map
=
norm_map
def
suggest
(
self
,
prev
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment