Skip to content

Commit

Permalink
similarity fix
Browse files Browse the repository at this point in the history
Signed-off-by: Facundo Guerrero <[email protected]>
  • Loading branch information
Facundo Guerrero committed Oct 4, 2019
1 parent 1924e83 commit 033baba
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/service/topics/UserTopicService.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from src.db.dao.CooccurrenceGraphDAO import CooccurrenceGraphDAO
from src.db.dao.HashtagsTopicsDAO import HashtagsTopicsDAO
from src.db.dao.RawFollowerDAO import RawFollowerDAO
from src.db.dao.SimilarityDAO import SimilarityDAO
from src.db.dao.UserHashtagDAO import UserHashtagDAO
from src.exception.NonExistentDataForMatrixError import NonExistentDataForMatrixError
from src.model.Similarities import Similarities
Expand Down Expand Up @@ -84,11 +83,11 @@ def calculate_users_similarity(cls, date):
totals.append(total)

similarities.add_similarity(f"{x}-{y}", mean)
# cls.get_logger().info(f'Similarity between {x} - {y}: {mean}')
cls.get_logger().info(f'Similarity between {x} - {y}: {mean}')

random_mean = cls.get_weighted_mean(means, totals)
similarities.add_similarity('random', random_mean)
# cls.get_logger().info(f'Random {random_mean}')
cls.get_logger().info(f'Random {random_mean}')

similarities_wor = {}
for groups, sim in similarities.similarities.items():
Expand All @@ -98,7 +97,7 @@ def calculate_users_similarity(cls, date):
similarities_wor[new_key] = sim - random_mean

similarities.set_similarities_wor(similarities_wor)
SimilarityDAO().insert_similarities(similarities)
# SimilarityDAO().insert_similarities(similarities)
cls.get_logger().info('All similarities are calculated correctly.')

@classmethod
Expand Down Expand Up @@ -128,8 +127,9 @@ def multiply_matrices_and_get_mean(cls, m1, m2, setdiag):
len_sliced_matrix = len(sliced_matrix.data)

partial_means.append(
sliced_matrix.mean(dtype='float16') * old_shape[1] * rows_quantity / len_sliced_matrix)
partial_totals.append(len_sliced_matrix)
sliced_matrix.mean(dtype='float16') * old_shape[1] * (rows_quantity - 1) / len_sliced_matrix)
lsma = len_sliced_matrix if setdiag else 2 * len_sliced_matrix
partial_totals.append(lsma)
del partial_matrix_result

return cls.get_weighted_mean(partial_means, partial_totals), sum(partial_totals)
Expand All @@ -142,7 +142,7 @@ def get_weighted_mean(cls, means, totals):
return mean / sum(totals)

@classmethod
def calculate_and_save_users_topics_matrix(cls, date, have_to_save=True):
def calculate_and_save_users_topics_matrix(cls, date, have_to_save=False):
""" This method calculate the user-topic matrix. """

# Retrieve necessaries data
Expand Down

0 comments on commit 033baba

Please sign in to comment.