/// <summary> /// Sets the traits, biases and thresholds to the product of two parameter distributions. /// </summary> /// <param name="firstFactor">The first factor.</param> /// <param name="secondFactor">The second factor.</param> /// <remarks>This method does not affect the user and item features.</remarks> public void SetEntityParametersToProduct(ParameterDistributions firstFactor, ParameterDistributions secondFactor) { this.UserTraitDistribution.SetToProduct(firstFactor.UserTraitDistribution, secondFactor.UserTraitDistribution); this.UserBiasDistribution.SetToProduct(firstFactor.UserBiasDistribution, secondFactor.UserBiasDistribution); this.UserThresholdDistribution.SetToProduct(firstFactor.UserThresholdDistribution, secondFactor.UserThresholdDistribution); this.ItemTraitDistribution.SetToProduct(firstFactor.ItemTraitDistribution, secondFactor.ItemTraitDistribution); this.ItemBiasDistribution.SetToProduct(firstFactor.ItemBiasDistribution, secondFactor.ItemBiasDistribution); }
/// <summary> /// Sets the traits, biases and thresholds to the power of a parameter distributions. /// </summary> /// <param name="value">The base.</param> /// <param name="exponent">The exponent.</param> /// <remarks>This method does not affect the user and item features.</remarks> public void SetEntityParametersToPower(ParameterDistributions value, double exponent) { this.UserTraitDistribution.SetToPower(value.UserTraitDistribution, exponent); this.UserBiasDistribution.SetToPower(value.UserBiasDistribution, exponent); this.UserThresholdDistribution.SetToPower(value.UserThresholdDistribution, exponent); this.ItemTraitDistribution.SetToPower(value.ItemTraitDistribution, exponent); this.ItemBiasDistribution.SetToPower(value.ItemBiasDistribution, exponent); }
/// <summary> /// Sets the traits, biases and thresholds to represent the ratio of two parameter distributions. /// </summary> /// <param name="numerator">The numerator parameter distribution.</param> /// <param name="denominator">The denominator parameter distribution.</param> /// <param name="forceProper">A flag indicating whether or not to force proper messages.</param> /// <remarks>This method does not affect the user and item features.</remarks> public void SetEntityParametersToRatio(ParameterDistributions numerator, ParameterDistributions denominator, bool forceProper = true) { this.UserTraitDistribution.SetToRatio(numerator.UserTraitDistribution, denominator.UserTraitDistribution, forceProper); this.UserBiasDistribution.SetToRatio(numerator.UserBiasDistribution, denominator.UserBiasDistribution, forceProper); this.UserThresholdDistribution.SetToRatio(numerator.UserThresholdDistribution, denominator.UserThresholdDistribution, forceProper); this.ItemTraitDistribution.SetToRatio(numerator.ItemTraitDistribution, denominator.ItemTraitDistribution, forceProper); this.ItemBiasDistribution.SetToRatio(numerator.ItemBiasDistribution, denominator.ItemBiasDistribution, forceProper); }
/// <summary> /// Initializes the per-user and per-item model parameters. /// </summary> /// <param name="initializers">The parameters to initialize to.</param> /// <remarks> /// The per-entity parameter initialization is required for correct reconstruction of the /// intermediate messages by the special first iteration. The initializers have to contain /// the corresponding posteriors from the last iteration. Note that feature-related parameters /// do not need to be initialized, because messages to the features are not reconstructed by /// the special first iteration. /// </remarks> public void InitializeEntityParameters(ParameterDistributions initializers) { this.inferenceAlgorithm.UserTraitsInitializer = initializers.UserTraitDistribution; this.inferenceAlgorithm.UserBiasInitializer = initializers.UserBiasDistribution; this.inferenceAlgorithm.UserThresholdsInitializer = initializers.UserThresholdDistribution; this.inferenceAlgorithm.ItemTraitsInitializer = initializers.ItemTraitDistribution; this.inferenceAlgorithm.ItemBiasInitializer = initializers.ItemBiasDistribution; }
/// <summary> /// Constrains the per-user and per-item model parameters. /// </summary> /// <param name="constraints">The parameters to constrain to.</param> /// <remarks> /// The per-entity parameters are constrained to their corresponding output messages /// (or more concretely, to the marginal divided by the prior). This is required in /// order to carry message information over several batches of the data. /// </remarks> public void ConstrainEntityParameters(ParameterDistributions constraints) { this.inferenceAlgorithm.UserTraitsMessage = constraints.UserTraitDistribution; this.inferenceAlgorithm.UserBiasMessage = constraints.UserBiasDistribution; this.inferenceAlgorithm.UserThresholdsMessage = constraints.UserThresholdDistribution; this.inferenceAlgorithm.ItemTraitsMessage = constraints.ItemTraitDistribution; this.inferenceAlgorithm.ItemBiasMessage = constraints.ItemBiasDistribution; }
/// <summary> /// Gets the parameter distributions of the average item. /// </summary> /// <param name="parameterDistributions">The learned posterior parameter distributions.</param> /// <param name="itemFeatures">The item features.</param> /// <returns>The average item parameter distributions.</returns> public static ItemParameterDistribution GetAverageItemParameters( ParameterDistributions parameterDistributions, SparseFeatureMatrix itemFeatures) { GaussianArray traitDistribution; Gaussian biasDistribution; GetAverageTraitsAndBiases( parameterDistributions.ItemTraitDistribution, parameterDistributions.ItemBiasDistribution, parameterDistributions.ItemFeature.TraitWeights, parameterDistributions.ItemFeature.BiasWeights, itemFeatures, out traitDistribution, out biasDistribution); return(new ItemParameterDistribution(traitDistribution, biasDistribution)); }
/// <summary> /// Gets the parameter distributions of the average user. /// </summary> /// <param name="parameterDistributions">The learned posterior parameter distributions.</param> /// <param name="userFeatures">The user features.</param> /// <returns>The average user parameter distributions.</returns> public static UserParameterDistribution GetAverageUserParameters( ParameterDistributions parameterDistributions, SparseFeatureMatrix userFeatures) { GaussianArray traitDistribution; Gaussian biasDistribution; GaussianArray thresholdDistribution = GetAverageParameterVector(parameterDistributions.UserThresholdDistribution); GetAverageTraitsAndBiases( parameterDistributions.UserTraitDistribution, parameterDistributions.UserBiasDistribution, parameterDistributions.UserFeature.TraitWeights, parameterDistributions.UserFeature.BiasWeights, userFeatures, out traitDistribution, out biasDistribution); return(new UserParameterDistribution(traitDistribution, biasDistribution, thresholdDistribution)); }