Class NMF


  • public class NMF
    extends Recommender
    Implements Lee, D. D., & Seung, H. S. (2001). Algorithms for non-negative matrix factorization. In Advances in neural information processing systems (pp. 556-562).
    • Field Detail

      • w

        protected final double[][] w
        User factors
      • h

        protected final double[][] h
        Item factors
      • numFactors

        protected final int numFactors
        Number of factors
      • numIters

        protected final int numIters
        Number of iterations
    • Constructor Detail

      • NMF

        public NMF​(DataModel datamodel,
                   Map<String,​Object> params)
        Model constructor from a Map containing the model's hyper-parameters values. Map object must contains the following keys:
        • numFactors: int value with the number of latent factors.
        • numIters:: int value with the number of iterations.
        • seed (optional): random seed for random numbers generation. If missing, random value is used.
        Parameters:
        datamodel - DataModel instance
        params - Model's hyper-parameters values
      • NMF

        public NMF​(DataModel datamodel,
                   int numFactors,
                   int numIters)
        Model constructor
        Parameters:
        datamodel - DataModel instance
        numFactors - Number of factors
        numIters - Number of iterations
      • NMF

        public NMF​(DataModel datamodel,
                   int numFactors,
                   int numIters,
                   long seed)
        Model constructor
        Parameters:
        datamodel - DataModel instance
        numFactors - Number of factors
        numIters - Number of iterations
        seed - Seed for random numbers generation
    • Method Detail

      • getNumFactors

        public int getNumFactors()
        Get the number of factors of the model
        Returns:
        Number of factors
      • getNumIters

        public int getNumIters()
        Get the number of iterations
        Returns:
        Number of iterations
      • fit

        public void fit()
        Description copied from class: Recommender
        Estimates model parameters given the hyper-parameters
        Specified by:
        fit in class Recommender
      • predict

        public double predict​(int userIndex,
                              int itemIndex)
        Description copied from class: Recommender
        Computes a rating prediction
        Specified by:
        predict in class Recommender
        Parameters:
        userIndex - Index of the user in the array of Users of the DataModel instance
        itemIndex - Index of the item in the array of Items of the DataModel instance
        Returns:
        Prediction