Created
August 5, 2015 18:10
-
-
Save captbaritone/851ee3a0896ad90d242f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from numpy.linalg import svd | |
from numpy import array | |
CLUSTERS = 2 | |
character_index_lookup = { | |
0: "Papageno", | |
1: "Figaro", | |
2: "Mimi", | |
3: "Rudolfo", | |
4: "Susanna" | |
} | |
# Singer resumes | |
# Rows represent signers, columns represent characters | |
singer_matrix = array([ | |
(1, 1, 0, 0, 0), | |
(1, 1, 0, 0, 0), | |
(0, 0, 1, 0, 1), | |
(0, 0, 0, 1, 0), | |
]) | |
# Do magic with maths | |
U, s, V = svd(singer_matrix) | |
clusters = V[:CLUSTERS] | |
# Each column represents a character | |
input_singer_vector = array([1, 0, 0, 0, 0]) | |
singer_fach = input_singer_vector.dot(clusters.transpose()).dot(clusters) | |
for index, score in enumerate(singer_fach): | |
if score > 0: | |
print character_index_lookup[index] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment