# Path: recommender/ratings.py
# POSITIVE = 1
# NEGATIVE = -1
# NEUTRAL = 0
# def NumberToRating(value):


from abc import ABCMeta
from abc import abstractmethod
from recommender import ratings
import math
          # delta = power * rating * r.rating
          # If user B recommended this 50 recommendations ago then we should not
          # connect user A to them as strongly as to user C who recommended this
          # only 2 recommendations ago.
          #
          # Otherwise a user (user T) can game the system and gain more
          # attention than they deserve:
          # 1) User T upvotes 1000 most popular items at once.
          # 2) When user A just happens to upvote 10 of those items in a row
          #    they get connected to user T as if the user T only upvoted those
          #    10 items and nothing else (ie, user T is a perfect predictor for
          #    user A).
          #
          # So the amount by how much we connect user A to user T should be
          # similar to when user A upvotes each item right after user T upvotes
          # it. So all the following non shared items cause the connection to be
          # decay.
          # We assume that the delta will be contributing to the linear part of
          # the sigmoid function so we apply the ignore directly to the delta in
          # the log odds space.
          delta *= (1 - self.ignore_learning_rate)**r.num_ratings_ago
          self.connection_store.SetWeight(
              user,
              r.user,
              POSITIVE if r.rating > 0 else NEGATIVE,
              r.weight + delta,
              shared_item=shared_item)

    # Decay the connection weights slightly where this user is a publisher.
    # We don't penalize negative ratings.

# Path: recommender/ratings.py
# POSITIVE = 1
# NEGATIVE = -1
# NEUTRAL = 0
# def NumberToRating(value):


# Path: recommender/connection_trainer.py
from abc import ABCMeta
from abc import abstractmethod
from recommender import ratings
import math

          # delta = power * rating * r.rating
          # If user B recommended this 50 recommendations ago then we should not
          # connect user A to them as strongly as to user C who recommended this
          # only 2 recommendations ago.
          #
          # Otherwise a user (user T) can game the system and gain more
          # attention than they deserve:
          # 1) User T upvotes 1000 most popular items at once.
          # 2) When user A just happens to upvote 10 of those items in a row
          #    they get connected to user T as if the user T only upvoted those
          #    10 items and nothing else (ie, user T is a perfect predictor for
          #    user A).
          #
          # So the amount by how much we connect user A to user T should be
          # similar to when user A upvotes each item right after user T upvotes
          # it. So all the following non shared items cause the connection to be
          # decay.
          # We assume that the delta will be contributing to the linear part of
          # the sigmoid function so we apply the ignore directly to the delta in
          # the log odds space.
          delta *= (1 - self.ignore_learning_rate)**r.num_ratings_ago
          self.connection_store.SetWeight(
              user,
              r.user,
              POSITIVE if r.rating > 0 else NEGATIVE,
              r.weight + delta,
              shared_item=shared_item)

    # Decay the connection weights slightly where this user is a publisher.
    # We don't penalize negative ratings.

    if rating == ratings.POSITIVE: