Class for (shrunk) adjusted cosine similarity
Badrul Sarwar, George Karypis, Joseph Konstan, John Riedl: Item-based collaborative filtering recommendation algorithms. WWW 2001
Inheritance: RatingCorrelationMatrix
Esempio n. 1
0
        /// <summary>Create a AdjustedCosine matrix from given data</summary>
        /// <param name="ratings">the ratings data</param>
        /// <param name="entity_type">the entity type, either USER or ITEM</param>
        /// <param name="shrinkage">a shrinkage parameter</param>
        /// <returns>the complete AdjustedCosine matrix</returns>
        static public CorrelationMatrix Create(IRatings ratings, EntityType entity_type, float shrinkage)
        {
            AdjustedCosine cm;
            int            num_entities = 0;

            if (entity_type.Equals(EntityType.USER))
            {
                num_entities = ratings.MaxUserID + 1;
            }
            else if (entity_type.Equals(EntityType.ITEM))
            {
                num_entities = ratings.MaxItemID + 1;
            }
            else
            {
                throw new ArgumentException("Unknown entity type: " + entity_type);
            }

            try
            {
                cm = new AdjustedCosine(num_entities);
            }
            catch (OverflowException)
            {
                Console.Error.WriteLine("Too many entities: " + num_entities);
                throw;
            }
            cm.shrinkage = shrinkage;
            cm.ComputeCorrelations(ratings, entity_type);
            return(cm);
        }
Esempio n. 2
0
        /// <summary>Create a AdjustedCosine matrix from given data</summary>
        /// <param name="ratings">the ratings data</param>
        /// <param name="entity_type">the entity type, either USER or ITEM</param>
        /// <param name="shrinkage">a shrinkage parameter</param>
        /// <returns>the complete AdjustedCosine matrix</returns>
        public static CorrelationMatrix Create(IRatings ratings, EntityType entity_type, float shrinkage)
        {
            AdjustedCosine cm;
            int num_entities = 0;
            if (entity_type.Equals(EntityType.USER))
                num_entities = ratings.MaxUserID + 1;
            else if (entity_type.Equals(EntityType.ITEM))
                num_entities = ratings.MaxItemID + 1;
            else
                throw new ArgumentException("Unknown entity type: " + entity_type);

            try
            {
                cm = new AdjustedCosine(num_entities);
            }
            catch (OverflowException)
            {
                Console.Error.WriteLine("Too many entities: " + num_entities);
                throw;
            }
            cm.shrinkage = shrinkage;
            cm.ComputeCorrelations(ratings, entity_type);
            return cm;
        }