Class BNMF


  • public class BNMF
    extends Recommender
    Implements Hernando, A., Bobadilla, J., & Ortega, F. (2016). A non negative matrix factorization for collaborative filtering recommender systems on a Bayesian probabilistic model. Knowledge-Based Systems, 97, 188-202.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected double[][] a
      User factors
      protected double alpha
      This hyper-parameter is related to the possibility of obtaining overlapping groups of users sharing the same tastes.
      protected double[][] b
      Item factors
      protected double beta
      This hyper-parameter represents the amount of evidence that the algorithm requires to deduce that a group of users likes an item.
      protected static double DEFAULT_R  
      protected double[][] epsilonMinus
      Epsilon- parameters
      protected double[][] epsilonPlus
      Epsilon+ parameters
      protected double[][] gamma
      Gamma parameters
      protected int numFactors
      Number of factors
      protected int numIters
      Number of iterations
      protected double r
      Hyper-parameter of the binomial distribution.
    • Constructor Summary

      Constructors 
      Constructor Description
      BNMF​(DataModel datamodel, int numFactors, int numIters, double alpha, double beta)
      Model constructor
      BNMF​(DataModel datamodel, int numFactors, int numIters, double alpha, double beta, double r, long seed)
      Model constructor
      BNMF​(DataModel datamodel, int numFactors, int numIters, double alpha, double beta, long seed)
      Model constructor
      BNMF​(DataModel datamodel, Map<String,​Object> params)
      Model constructor from a Map containing the model's hyper-parameters values.
    • Field Detail

      • a

        protected double[][] a
        User factors
      • b

        protected double[][] b
        Item factors
      • gamma

        protected double[][] gamma
        Gamma parameters
      • epsilonPlus

        protected double[][] epsilonPlus
        Epsilon+ parameters
      • epsilonMinus

        protected double[][] epsilonMinus
        Epsilon- parameters
      • alpha

        protected final double alpha
        This hyper-parameter is related to the possibility of obtaining overlapping groups of users sharing the same tastes.
      • beta

        protected final double beta
        This hyper-parameter represents the amount of evidence that the algorithm requires to deduce that a group of users likes an item.
      • r

        protected final double r
        Hyper-parameter of the binomial distribution.
      • numFactors

        protected final int numFactors
        Number of factors
      • numIters

        protected final int numIters
        Number of iterations
    • Constructor Detail

      • BNMF

        public BNMF​(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.
        • alpha: double value with the alpha hyper-parameter. This value is related to the possibility of obtaining overlapping groups of users sharing the same tastes.
        • beta: double value with the beta hyper-parameter. This value represents the amount of evidences that the algorithm requires to deduce that a group of users likes an item.
        • seed (optional): random seed for generating random numbers. If missing, random value is used.
        Parameters:
        datamodel - DataModel instance
        params - Model's hyper-parameters values
      • BNMF

        public BNMF​(DataModel datamodel,
                    int numFactors,
                    int numIters,
                    double alpha,
                    double beta)
        Model constructor
        Parameters:
        datamodel - DataModel instance
        numFactors - Number of factors
        numIters - Number of iterations
        alpha - This parameter is related to the possibility of obtaining overlapping groups of users sharing the same tastes
        beta - Amount of evidences that the algorithm requires to deduce that a group of users likes an item
      • BNMF

        public BNMF​(DataModel datamodel,
                    int numFactors,
                    int numIters,
                    double alpha,
                    double beta,
                    long seed)
        Model constructor
        Parameters:
        datamodel - DataModel instance
        numFactors - Number of factors
        numIters - Number of iterations
        alpha - This parameter is related to the possibility of obtaining overlapping groups of users sharing the same tastes
        beta - Amount of evidences that the algorithm requires to deduce that a group of users likes an item
        seed - Seed for random numbers generation
      • BNMF

        public BNMF​(DataModel datamodel,
                    int numFactors,
                    int numIters,
                    double alpha,
                    double beta,
                    double r,
                    long seed)
        Model constructor
        Parameters:
        datamodel - DataModel instance
        numFactors - Number of factors
        numIters - Number of iterations
        alpha - This parameter is related to the possibility of obtaining overlapping groups of users sharing the same tastes
        beta - Amount of evidences that the algorithm requires to deduce that a group of users likes an item
        r - Parameter of the binomial distribution (fixed to 4)
        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
      • getAlpha

        public double getAlpha()
        Get the alpha value
        Returns:
        Alpha value
      • getBeta

        public double getBeta()
        Get the beta value
        Returns:
        Beta value
      • getR

        public double getR()
        Get the r value
        Returns:
        r value
      • getGamma

        public double[] getGamma​(int userIndex)
        Get the gamma vector of an user
        Parameters:
        userIndex - user index
        Returns:
        User's gamma vector
      • getEpsilonPlus

        public double[] getEpsilonPlus​(int itemIndex)
        Get the epsilon+ vector of an item
        Parameters:
        itemIndex - item index
        Returns:
        Item's epsilon+ vector
      • getEpsilonMinus

        public double[] getEpsilonMinus​(int itemIndex)
        Get the epsilon- vector of an item
        Parameters:
        itemIndex - item index
        Returns:
        Item's epsilon- vector
      • getUserFactors

        public double[] getUserFactors​(int userIndex)
        Get the latent factors vector of a user (au)
        Parameters:
        userIndex - User
        Returns:
        Latent factors vector
      • getItemFactors

        public double[] getItemFactors​(int itemIndex)
        Get the latent factors vector of an item (bi)
        Parameters:
        itemIndex - User
        Returns:
        Latent factors vector
      • 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