class_docstr: Funk Matrix Factorization for recommender systems.
  
  The model equation is defined as:
  
  $$\hat{y}(x) = \langle \mathbf{v}_u, \mathbf{v}_i \rangle = \sum_{f=1}^{k} \mathbf{v}_{u, f} \cdot \mathbf{v}_{i, f}$$
  
  where $k$ is the number of latent factors.
  
  This model expects a dict input with a `user` and an `item` entries without any type
  constraint on their values (i.e. can be strings or numbers). Other entries are ignored.
  
  Parameters
  ----------
  n_factors
      Dimensionality of the factorization or number of latent factors.
  optimizer
      The sequential optimizer used for updating the latent factors.
  loss
      The loss function to optimize for.
  l2
      Amount of L2 regularization used to push weights towards 0.
  initializer
      Latent factors initialization scheme.
  clip_gradient
      Clips the absolute value of each gradient value.
  seed
      Random number generation seed. Set this for reproducibility.
  
  Attributes
  ----------
  u_latents : collections.defaultdict
      The user latent vectors randomly initialized.
  i_latents : collections.defaultdict
      The item latent vectors randomly initialized.
  u_optimizer : optim.base.Optimizer
      The sequential optimizer used for updating the user latent weights.
  i_optimizer : optim.base.Optimizer
      The sequential optimizer used for updating the item latent weights.
  
  Examples
  --------
  
  >>> from river import optim
  >>> from river import reco
  
  >>> dataset = (
  ...     ({'user': 'Alice', 'item': 'Superman'}, 8),
  ...     ({'user': 'Alice', 'item': 'Terminator'}, 9),
  ...     ({'user': 'Alice', 'item': 'Star Wars'}, 8),
  ...     ({'user': 'Alice', 'item': 'Notting Hill'}, 2),
  ...     ({'user': 'Alice', 'item': 'Harry Potter'}, 5),
  ...     ({'user': 'Bob', 'item': 'Superman'}, 8),
  ...     ({'user': 'Bob', 'item': 'Terminator'}, 9),
  ...     ({'user': 'Bob', 'item': 'Star Wars'}, 8),
  ...     ({'user': 'Bob', 'item': 'Notting Hill'}, 2)
  ... )
  
  >>> model = reco.FunkMF(
  ...     n_factors=10,
  ...     optimizer=optim.SGD(0.1),
  ...     initializer=optim.initializers.Normal(mu=0., sigma=0.1, seed=11),
  ... )
  
  >>> for x, y in dataset:
  ...     model.learn_one(**x, y=y)
  
  >>> model.predict_one(user='Bob', item='Harry Potter')
  1.866272
  
  References
  ----------
  [^1]: [Netflix update: Try this at home](https://sifter.org/simon/journal/20061211.html)
  [^2]: [Matrix factorization techniques for recommender systems](https://datajobs.com/data-science-repo/Recommender-Systems-[Netflix].pdf)
class_docstr_tok: ["Funk","Matrix","Factorization","for","recommender","systems",".","The","model","equation","is","defined","as",":","$","$","\\hat","{","y","}","(","x",")","=","\\langle","\\mathbf","{","v","}","_u",",","\\mathbf","{","v","}","_i","\\rangle","=","\\sum_","{","f=1","}","^","{","k","}","\\mathbf","{","v","}","_","{","u",",","f","}","\\cdot","\\mathbf","{","v","}","_","{","i",",","f","}","$","$","where","$","k","$","is","the","number","of","latent","factors",".","This","model","expects","a","dict","input","with","a","`","user","`","and","an","`","item","`","entries","without","any","type","constraint","on","their","values","(","i.e",".","can","be","strings","or","numbers",")",".","Other","entries","are","ignored",".","Parameters","--","--","--","--","--","n_factors","Dimensionality","of","the","factorization","or","number","of","latent","factors",".","optimizer","The","sequential","optimizer","used","for","updating","the","latent","factors",".","loss","The","loss","function","to","optimize","for",".","l2","Amount","of","L2","regularization","used","to","push","weights","towards","0.","initializer","Latent","factors","initialization","scheme",".","clip_gradient","Clips","the","absolute","value","of","each","gradient","value",".","seed","Random","number","generation","seed",".","Set","this","for","reproducibility",".","Attributes","--","--","--","--","--","u_latents",":","collections.defaultdict","The","user","latent","vectors","randomly","initialized",".","i_latents",":","collections.defaultdict","The","item","latent","vectors","randomly","initialized",".","u_optimizer",":","optim.base.Optimizer","The","sequential","optimizer","used","for","updating","the","user","latent","weights",".","i_optimizer",":","optim.base.Optimizer","The","sequential","optimizer","used","for","updating","the","item","latent","weights",".","Examples","--","--","--","--",">",">",">","from","river","import","optim",">",">",">","from","river","import","reco",">",">",">","dataset","=","(","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Superman","'","}",",","8",")",",","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Terminator","'","}",",","9",")",",","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Star","Wars","'","}",",","8",")",",","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Notting","Hill","'","}",",","2",")",",","...","(","{","'user","'",":","'Alice","'",",","'item","'",":","'Harry","Potter","'","}",",","5",")",",","...","(","{","'user","'",":","'Bob","'",",","'item","'",":","'Superman","'","}",",","8",")",",","...","(","{","'user","'",":","'Bob","'",",","'item","'",":","'Terminator","'","}",",","9",")",",","...","(","{","'user","'",":","'Bob","'",",","'item","'",":","'Star","Wars","'","}",",","8",")",",","...","(","{","'user","'",":","'Bob","'",",","'item","'",":","'Notting","Hill","'","}",",","2",")","...",")",">",">",">","model","=","reco.FunkMF","(","...","n_factors=10",",","...","optimizer=optim.SGD","(","0.1",")",",","...","initializer=optim.initializers.Normal","(","mu=0.",",","sigma=0.1",",","seed=11",")",",","...",")",">",">",">","for","x",",","y","in","dataset",":","...","model.learn_one","(","*","*","x",",","y=y",")",">",">",">","model.predict_one","(","user='Bob","'",",","item='Harry","Potter","'",")","1.866272","References","--","--","--","--","--","[","^1","]",":","[","Netflix","update",":","Try","this","at","home","]","(","https",":","\/\/sifter.org\/simon\/journal\/20061211.html",")","[","^2","]",":","[","Matrix","factorization","techniques","for","recommender","systems","]","(","https",":","\/\/datajobs.com\/data-science-repo\/Recommender-Systems-","[","Netflix","]",".pdf",")"]
code: def __init__(
      self,
      n_factors=10,
      optimizer: optim.base.Optimizer | None = None,
      loss: optim.losses.Loss | None = None,
      l2=0.0,
      initializer: optim.initializers.Initializer | None = None,
      clip_gradient=1e12,
      seed=None,
  ):
      super().__init__(seed=seed)
  
      self.optimizer = optimizer
  
      self.n_factors = n_factors
      self.u_optimizer = (
          optim.SGD(0.1)
          if optimizer is None
          else copy.deepcopy(optimizer)
      )
      self.i_optimizer = (
          optim.SGD(0.1)
          if optimizer is None
          else copy.deepcopy(optimizer)
      )
      self.loss = optim.losses.Squared() if loss is None else loss
      self.l2 = l2
  
      if initializer is None:
          initializer = optim.initializers.Normal(
              mu=0.0, sigma=0.1, seed=self.seed
          )
      self.initializer = initializer
  
      self.clip_gradient = clip_gradient
  
      random_latents = functools.partial(
          self.initializer, shape=self.n_factors
      )
      self.u_latents: collections.defaultdict[
          int, optim.initializers.Initializer
      ] = collections.defaultdict(random_latents)
      self.i_latents: collections.defaultdict[
          int, optim.initializers.Initializer
      ] = collections.defaultdict(random_latents)
  
file_path: river/river/reco/funk_mf.py
imports: from __future__ import annotations
  import collections
  import copy
  import functools
  import numpy
  from river import optim, reco, utils
label_desc: Use image node_id 1 to create a new FunkMF object from inherited base classes: reco.base with example: obj = FunkMF(n_factors, optimizer, loss, l2, initializer, clip_gradient, seed)