public static IndexOfMaximumBuffer[] Buffers <GaussianList>(IndexOfMaximumBuffer[] Buffers, [SkipIfUniform] GaussianList list, [IgnoreDependency] Discrete IndexOfMaximumDouble) where GaussianList : IList <Gaussian> { for (int i = 0; i < list.Count; i++) { Buffers[i].to_list = new DistributionStructArray <Gaussian, double>(list.Select(o => Gaussian.Uniform()).ToArray()); Buffers[i].to_list[i] = Buffers[i].MessagesToMax.Aggregate((p, q) => p * q); Buffers[i] = IndexOfMaximumOp.Buffer(Buffers[i], list, i); } return(Buffers); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IndexOfMaximumStochasticOp"]/message_doc[@name="IndexOfMaximumDoubleAverageConditional{GaussianList}(GaussianList, IndexOfMaximumBuffer[])"]/*'/> /// <typeparam name="GaussianList">The type of an incoming message from <c>list</c>.</typeparam> public static Discrete IndexOfMaximumDoubleAverageConditional <GaussianList>(GaussianList list, IndexOfMaximumBuffer[] Buffers) where GaussianList : DistributionStructArray <Gaussian, double> { // var results = list.Select(o => list.Select(p => Gaussian.Uniform()).ToList()).ToArray(); // TODO: if IndexOfMaximumDouble is uniform we will never call this routine so buffers will not get set, so messages to IndexOfMaximumDouble will be incorrect var evidences = new double[list.Count]; for (int i = 0; i < list.Count; i++) { //var res = new DistributionStructArray<Gaussian, double>(list.Select(o => Gaussian.Uniform()).ToArray()); //res[i] = Buffer[i].MessagesToMax.Aggregate((p, q) => p * q); evidences[i] = IndexOfMaximumOp.LogAverageFactor(Buffers[i], list, i); } return(new Discrete(MMath.Softmax(evidences))); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IndexOfMaximumStochasticOp"]/message_doc[@name="LogAverageFactor{GaussianList}(GaussianList, GaussianList, IndexOfMaximumBuffer[], Discrete)"]/*'/> /// <typeparam name="GaussianList">The type of an incoming message from <c>list</c>.</typeparam> public static double LogAverageFactor <GaussianList>( [SkipIfUniform] GaussianList list, GaussianList to_list, IndexOfMaximumBuffer[] Buffers, Discrete IndexOfMaximumDouble) where GaussianList : DistributionStructArray <Gaussian, double> { var evidences = new double[list.Count]; var tempBuffer = new IndexOfMaximumBuffer(); for (int i = 0; i < list.Count; i++) { tempBuffer.to_list = new DistributionStructArray <Gaussian, double>(list.Select(o => Gaussian.Uniform()).ToArray()); tempBuffer.to_list[i] = Buffers[i].MessagesToMax.Aggregate((p, q) => p * q); tempBuffer.MessagesToMax = new DistributionStructArray <Gaussian, double>(Buffers[i].MessagesToMax.Select(o => (Gaussian)o.Clone()).ToArray()); evidences[i] = IndexOfMaximumOp.LogAverageFactor(tempBuffer, list, i) + IndexOfMaximumDouble.GetLogProb(i); ; } return(MMath.LogSumExp(evidences)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IndexOfMaximumStochasticOp"]/message_doc[@name="BuffersInit{GaussianList}(GaussianList, Discrete)"]/*'/> /// <typeparam name="GaussianList">The type of an incoming message from <c>list</c>.</typeparam> public static IndexOfMaximumBuffer[] BuffersInit <GaussianList>([IgnoreDependency] GaussianList list, [IgnoreDependency] Discrete IndexOfMaximumDouble) where GaussianList : IList <Gaussian> { return(list.Select(o => IndexOfMaximumOp.BufferInit(list)).ToArray()); }