/// <summary> /// Creates an Infer.NET inference algorithm for making predictions from a multi-class Bayes point machine classifier /// with <see cref="Gaussian"/> prior distributions over factorized weights and features in a dense representation. /// </summary> /// <param name="generatedSourceFolder">The folder to drop the generated prediction algorithm to.</param> public static void CreateDenseMulticlassPredictionAlgorithm(string generatedSourceFolder) { // Create the model var model = new DenseMulticlassModel( computeModelEvidence: false, useCompoundWeightPriorDistributions: false, breakSymmetries: false); // Add the inferred variables model.Labels.AddAttribute(QueryTypes.Marginal); // Apply the query to the model and compile the inference algorithm GetCompiledInferenceAlgorithm("GaussianDenseMulticlassBpmPrediction", generatedSourceFolder, model.Labels); }
/// <summary> /// Creates an Infer.NET inference algorithm which trains a multi-class Bayes point machine classifier /// with factorized weight distributions on features in a dense representation. /// </summary> /// <param name="generatedSourceFolder">The folder to drop the generated training algorithm to.</param> /// <param name="computeModelEvidence">If true, the generated training algorithm computes evidence.</param> /// <param name="useCompoundWeightPriorDistributions"> /// If true, the generated training algorithm uses compound prior distributions over weights. Otherwise /// <see cref="Gaussian"/> prior distributions are used. /// </param> public static void CreateDenseMulticlassTrainingAlgorithm( string generatedSourceFolder, bool computeModelEvidence, bool useCompoundWeightPriorDistributions) { // Create the model var model = new DenseMulticlassModel(computeModelEvidence, useCompoundWeightPriorDistributions, breakSymmetries: true); // Add the observed variables model.Labels.ObservedValue = default(int[]); // Add the inferred variables var queryVariables = new List <IVariable> { model.Weights }; model.Weights.AddAttribute(QueryTypes.Marginal); model.Weights.AddAttribute(QueryTypes.MarginalDividedByPrior); if (useCompoundWeightPriorDistributions) { queryVariables.Add(model.WeightPrecisionRates); model.WeightPrecisionRates.AddAttribute(QueryTypes.MarginalDividedByPrior); if (computeModelEvidence) { // This is required to compute evidence corrections model.WeightPrecisionRates.AddAttribute(QueryTypes.Marginal); } } if (computeModelEvidence) { queryVariables.Add(model.ModelSelector); model.ModelSelector.AddAttribute(QueryTypes.Marginal); } // Apply the query to the model and compile the inference algorithm string queryName = (useCompoundWeightPriorDistributions ? "Compound" : "Gaussian") + "DenseMulticlassBpmTraining" + (computeModelEvidence ? "Evidence" : string.Empty); GetCompiledInferenceAlgorithm(queryName, generatedSourceFolder, queryVariables.ToArray()); }