예제 #1
0
        /// <summary>
        /// Infers parameters for a given cold user.
        /// </summary>
        /// <param name="userFeatures">The user features.</param>
        /// <returns>A distribution over the user parameters.</returns>
        public UserParameterDistribution InferUserParameters(SparseFeatureVector userFeatures)
        {
            UserParameterDistribution result;

            if (this.userFeatureParameterPosteriors.FeatureCount == 0)
            {
                Debug.Assert(
                    userFeatures.FeatureCount == 0,
                    "The number of user features passed must be equal to the number of user features learned.");

                result = this.userParameterDistributionAverage;
            }
            else
            {
                GaussianArray traits;
                Gaussian      bias;

                AlgorithmUtils.AddFeatureContribution(
                    this.userParameterDistributionAverage,
                    this.userFeatureParameterPosteriors,
                    userFeatures,
                    out traits,
                    out bias);

                result = new UserParameterDistribution(traits, bias, this.userParameterDistributionAverage.Thresholds);
            }

            return(result);
        }
        /// <summary>
        /// Sets up the inference algorithm to operate on a single user given the posteriors over the parameters of the user.
        /// </summary>
        /// <param name="userParameterPosteriors">The posteriors over the parameters of the user.</param>
        private void SetupUserFromPosteriors(UserParameterDistribution userParameterPosteriors)
        {
            Debug.Assert(userParameterPosteriors != null, "Valid user parameter posteriors must be provided.");

            this.inferenceAlgorithm.UserCount           = 1;
            this.inferenceAlgorithm.UserThresholdCount  = userParameterPosteriors.Thresholds.Count;
            this.inferenceAlgorithm.UserTraitsPrior     = new GaussianMatrix(new[] { userParameterPosteriors.Traits });
            this.inferenceAlgorithm.UserBiasPrior       = new GaussianArray(new[] { userParameterPosteriors.Bias });
            this.inferenceAlgorithm.UserThresholdsPrior = new GaussianMatrix(new[] { userParameterPosteriors.Thresholds });
        }
예제 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ColdUserItemParameterAlgorithm"/> class.
 /// </summary>
 /// <param name="userFeatureParameterPosteriors">The posteriors over the user feature related parameters learned during community training.</param>
 /// <param name="itemFeatureParameterPosteriors">The posteriors over the item feature related parameters learned during community training.</param>
 /// <param name="userParameterDistributionAverage">The average trait, bias, and threshold posterior over all users in training.</param>
 /// <param name="itemParameterDistributionAverage">The average trait and bias posterior over all items in training.</param>
 public ColdUserItemParameterAlgorithm(
     FeatureParameterDistribution userFeatureParameterPosteriors,
     FeatureParameterDistribution itemFeatureParameterPosteriors,
     UserParameterDistribution userParameterDistributionAverage,
     ItemParameterDistribution itemParameterDistributionAverage)
 {
     this.userFeatureParameterPosteriors   = userFeatureParameterPosteriors;
     this.itemFeatureParameterPosteriors   = itemFeatureParameterPosteriors;
     this.userParameterDistributionAverage = userParameterDistributionAverage;
     this.itemParameterDistributionAverage = itemParameterDistributionAverage;
 }
        /// <summary>
        /// Infers the distribution over the rating which a given user will give to an item.
        /// </summary>
        /// <param name="userParameterPosteriors">The posteriors over user parameters.</param>
        /// <param name="itemParameterPosteriors">The posteriors over item parameters.</param>
        /// <returns>The distribution over the rating.</returns>
        public Discrete InferRatingDistribution(
            UserParameterDistribution userParameterPosteriors, ItemParameterDistribution itemParameterPosteriors)
        {
            Debug.Assert(userParameterPosteriors != null && itemParameterPosteriors != null, "A valid posteriors must be provided.");
            Debug.Assert(
                userParameterPosteriors.Traits.Count == itemParameterPosteriors.Traits.Count,
                "Given posteriors should have the same associated number of traits.");

            this.inferenceAlgorithm.TraitCount = userParameterPosteriors.Traits.Count;

            this.SetupUserFromPosteriors(userParameterPosteriors);
            this.SetupItemFromPosteriors(itemParameterPosteriors);

            this.inferenceAlgorithm.ObservationCount = 1;
            this.inferenceAlgorithm.UserIds          = new[] { 0 };
            this.inferenceAlgorithm.ItemIds          = new[] { 0 };

            this.inferenceAlgorithm.Execute(1);

            return(this.inferenceAlgorithm.RatingsMarginal()[0]);
        }