Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Value:
- """
- Dense object that holds parameters.
- """
- def __init__(self, n):
- self._params = np.ones(n)
- self._n = n
- def dot(self, update):
- score = 0
- for position, value in zip(update._positions, update._values):
- score += self._params[int(position % self._n)] * value
- return score
- def assign(self, other):
- """
- self = other
- other is Value.
- """
- self = np.copy(other)
- def assign_mul(self, coeff):
- """
- self = self * coeff
- coeff is float.
- """
- self._params = np.multiply(self._params, coeff)
- def assign_madd(self, x, coeff):
- """
- self = self + x * coeff
- x can be either Value or Update.
- coeff is float.
- """
- if isinstance(x, Value):
- self._params = np.add(self._params, np.multiply(x._params, coeff))
- if isinstance(x, Update):
- for position, value in zip(x._positions, x._values):
- self._params[int(position % self._n)] += value * coeff
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement