/// <summary>
        /// Initializes a new instance of the <see cref="NegativeDataGeneratorMapping{TInstanceSource,TInstance,TUser,TItem,TFeatureSource,TFeatureValues}"/>
        /// class from a reader of a binary stream.
        /// </summary>
        /// <param name="reader">The binary reader to read the state of the negative data generation mapping from.</param>
        /// <param name="mapping">The top level mapping.</param>
        public NegativeDataGeneratorMapping(
            IReader reader,
            IRecommenderMapping <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues> mapping)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }

            this.mapping = mapping;

            reader.VerifySerializationGuid(
                this.customSerializationGuid, "The binary stream does not contain the negative data generation mapping of an Infer.NET Matchbox recommender.");

            int deserializedVersion = reader.ReadSerializationVersion(CustomSerializationVersion);

            if (deserializedVersion == CustomSerializationVersion)
            {
                this.itemHistogramAdjustment = reader.ReadDouble();
            }
        }
 WithGeneratedNegativeData <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues>(
     this IRecommenderMapping <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues> mapping,
     double itemHistogramAdjustment = 1.2)
 {
     return(new NegativeDataGeneratorMapping <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues>(
                mapping, itemHistogramAdjustment));
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="NegativeDataGeneratorMapping{TInstanceSource,TInstance,TUser,TItem,TFeatureSource,TFeatureValues}"/> class.
        /// </summary>
        /// <param name="mapping">The top level mapping.</param>
        /// <param name="itemHistogramAdjustment">
        /// The degree to which each element of the item histogram is raised before sampling.
        /// Should be different from 1.0 if it is believed that there is some quality
        /// bar which drives popular items to be more generally liked.
        /// </param>
        public NegativeDataGeneratorMapping(
            IRecommenderMapping <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues> mapping,
            double itemHistogramAdjustment = DefaultItemHistogramAdjustment)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException(nameof(mapping));
            }

            this.mapping = mapping;
            this.itemHistogramAdjustment = itemHistogramAdjustment;
        }
Beispiel #4
0
 SplitToTrainTest <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues>(
     this IRecommenderMapping <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues> mapping,
     double trainingOnlyUserFraction,
     double testUserRatingTrainingFraction,
     double coldUserFraction        = 0,
     double coldItemFraction        = 0,
     double ignoredUserFraction     = 0,
     double ignoredItemFraction     = 0,
     bool removeOccasionalColdItems = false)
 {
     return(new TrainTestSplittingRecommenderMapping <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues>(
                mapping, trainingOnlyUserFraction, testUserRatingTrainingFraction, coldUserFraction, coldItemFraction, ignoredUserFraction, ignoredItemFraction, removeOccasionalColdItems));
 }
Beispiel #5
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="TrainTestSplittingRecommenderMapping{TInstanceSource,TInstance,TUser,TItem,TFeatureSource,TFeatureValues}"/> class.
        /// </summary>
        /// <param name="mapping">The wrapped recommender mapping.</param>
        /// <param name="trainingOnlyUserFraction">The fraction of users included in the training set only.</param>
        /// <param name="testUserRatingTrainingFraction">The fraction of ratings in the training set for each user who is presented in both sets.</param>
        /// <param name="coldUserFraction">The fraction of users included in the test set only.</param>
        /// <param name="coldItemFraction">The fraction of items included in the test set only.</param>
        /// <param name="ignoredUserFraction">The fraction of users not included in either the training or the test set.</param>
        /// <param name="ignoredItemFraction">The fraction of items not included in either the training or the test set.</param>
        /// <param name="removeOccasionalColdItems">Whether the occasionally produced cold items should be removed from the test set.</param>
        public TrainTestSplittingRecommenderMapping(
            IRecommenderMapping <TInstanceSource, TInstance, TUser, TItem, TFeatureSource, TFeatureValues> mapping,
            double trainingOnlyUserFraction,
            double testUserRatingTrainingFraction,
            double coldUserFraction        = 0,
            double coldItemFraction        = 0,
            double ignoredUserFraction     = 0,
            double ignoredItemFraction     = 0,
            bool removeOccasionalColdItems = false)
        {
            if (mapping == null)
            {
                throw new ArgumentNullException("mapping");
            }

            CheckFraction(trainingOnlyUserFraction, "trainingOnlyUserFraction");
            CheckFraction(testUserRatingTrainingFraction, "testUserRatingTrainingFraction");
            CheckFraction(coldUserFraction, "coldUserFraction");
            CheckFraction(coldItemFraction, "coldItemFraction");
            CheckFraction(ignoredUserFraction, "ignoredUserFraction");
            CheckFraction(ignoredItemFraction, "ignoredItemFraction");

            if (ignoredUserFraction + coldUserFraction + trainingOnlyUserFraction > 1)
            {
                throw new ArgumentException("The total fraction of cold users, training-only users and ignored users can not be greater than 1.");
            }

            if (ignoredItemFraction + coldItemFraction > 1)
            {
                throw new ArgumentException("The total fraction of cold items and ignored items can not be greater than 1.");
            }

            this.mapping                        = mapping;
            this.ignoredUserFraction            = ignoredUserFraction;
            this.ignoredItemFraction            = ignoredItemFraction;
            this.trainingOnlyUserFraction       = trainingOnlyUserFraction;
            this.testUserRatingTrainingFraction = testUserRatingTrainingFraction;
            this.coldUserFraction               = coldUserFraction;
            this.coldItemFraction               = coldItemFraction;
            this.removeUndesiredColdItems       = removeOccasionalColdItems;
        }