Main() { Variable<bool> firstCoin = Variable.Bernoulli(0.5).Named("firstCoin"); Variable<bool> secondCoin = Variable.Bernoulli(0.5).Named("secondCoin"); Variable<bool> bothHeads = (firstCoin & secondCoin).Named("bothHeads"); InferenceEngine ie = new InferenceEngine(); if (!(ie.Algorithm is VariationalMessagePassing)) { Console.WriteLine("Probability both coins are heads: "+ie.Infer(bothHeads)); bothHeads.ObservedValue=false; Console.WriteLine("Probability distribution over firstCoin: " + ie.Infer(firstCoin)); } else Console.WriteLine("This example does not run with Variational Message Passing"); } } first example of Infer.NET from Microsoft Research
coins are heads: "+ie.Infer(bothHeads)); bothHeads.ObservedValue=false; Console.WriteLine("Probability distribution over firstCoin: " + ie.Infer(firstCoin)); } 基本的にはObservedValueをセットして、ie.Infer を呼ぶだけ first example of Infer.NET from Microsoft Research
new Range(SizeVocab).Named("W"); Range T = new Range(NumTopics).Named("T"); NumWordsInDoc = Variable.Array<int>(D).Named("NumWordsInDoc"); Range WInD = new Range(NumWordsInDoc[D]).Named("WInD"); // Surround model by a stochastic If block so that we can compute model evidence Evidence = Variable.Bernoulli(0.5).Named("Evidence"); IfBlock evidenceBlock = null; // We cannot calculate evidence in the power-plate version if (!UsePowerPlate) evidenceBlock = Variable.If(Evidence); Theta = Variable.Array<Vector>(D); Theta.SetSparsity(ThetaSparsity); Theta.SetValueRange(T); ThetaPrior = Variable.Array<Dirichlet>(D).Named("ThetaPrior"); Theta[D] = Variable<Vector>.Random(ThetaPrior[D]); Phi = Variable.Array<Vector>(T); Phi.SetSparsity(PhiSparsity); Phi.SetValueRange(W); PhiPrior = Variable.Array<Dirichlet>(T).Named("PhiPrior"); Phi[T] = Variable<Vector>.Random(PhiPrior[T]); Words = Variable.Array(Variable.Array<int>(WInD), D).Named("Words"); WordCounts = Variable.Array(Variable.Array<double>(WInD), D).Named("WordCounts" LDAModel.cs