/// <summary>Update the buffer <c>Buffer</c>.</summary> /// <param name="Buffer">Buffer <c>Buffer</c>.</param> /// <param name="list">Incoming message from <c>list</c>.</param> /// <param name="IndexOfMaximumDouble">Constant value for <c>indexOfMaximumDouble</c>.</param> /// <returns>New value of buffer <c>Buffer</c>.</returns> /// <remarks> /// <para /> /// </remarks> /// <typeparam name="GaussianList">The type of an incoming message from <c>list</c>.</typeparam> public static IndexOfMaximumBuffer Buffer <GaussianList>( IndexOfMaximumBuffer Buffer, GaussianList list, int IndexOfMaximumDouble) // redundant parameters required for correct dependency graph where GaussianList : IList <Gaussian> { var max_marginal = Buffer.to_list[IndexOfMaximumDouble] * list[IndexOfMaximumDouble]; Gaussian product = Gaussian.Uniform(); //var order = Rand.Perm(list.Count); for (int i = 0; i < list.Count; i++) { //int c = order[i]; int c = i; if (c != IndexOfMaximumDouble) { var msg_to_sum = max_marginal / Buffer.MessagesToMax[c]; var msg_to_positiveop = DoublePlusOp.AAverageConditional(Sum: msg_to_sum, b: list[c]); var msgFromPositiveOp = IsPositiveOp.XAverageConditional(true, msg_to_positiveop); Buffer.MessagesToMax[c] = DoublePlusOp.SumAverageConditional(list[c], msgFromPositiveOp); Buffer.to_list[c] = DoublePlusOp.AAverageConditional(Sum: msg_to_sum, b: msgFromPositiveOp); max_marginal = msg_to_sum * Buffer.MessagesToMax[c]; product.SetToProduct(product, Buffer.MessagesToMax[c]); } } //Buffer.to_list[IndexOfMaximumDouble] = max_marginal / list[IndexOfMaximumDouble]; Buffer.to_list[IndexOfMaximumDouble] = product; return(Buffer); }
// redundant parameters required for correct dependency graph public static IndexOfMaximumBuffer Buffer <GaussianList>(IndexOfMaximumBuffer Buffer, GaussianList list, int IndexOfMaximumDouble) where GaussianList : IList <Gaussian> { var max_marginal = Buffer.to_list[IndexOfMaximumDouble] * list[IndexOfMaximumDouble]; //var order = Rand.Perm(list.Count); for (int i = 0; i < list.Count; i++) { //int c = order[i]; int c = i; if (c != IndexOfMaximumDouble) { var msg_to_sum = max_marginal / Buffer.MessagesToMax[c]; var msg_to_positiveop = DoublePlusOp.AAverageConditional(Sum: msg_to_sum, b: list[c]); var msgFromPositiveOp = IsPositiveOp.XAverageConditional(true, msg_to_positiveop); Buffer.MessagesToMax[c] = DoublePlusOp.SumAverageConditional(list[c], msgFromPositiveOp); Buffer.to_list[c] = DoublePlusOp.AAverageConditional(Sum: msg_to_sum, b: msgFromPositiveOp); max_marginal = msg_to_sum * Buffer.MessagesToMax[c]; } } Buffer.to_list[IndexOfMaximumDouble] = max_marginal / list[IndexOfMaximumDouble]; return(Buffer); }