/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PlusTruncatedGaussianOp"]/message_doc[@name="AAverageConditional(double, TruncatedGaussian)"]/*'/> public static TruncatedGaussian AAverageConditional(double sum, [SkipIfUniform] TruncatedGaussian b) { Gaussian prior = b.ToGaussian(); Gaussian post = DoublePlusOp.AAverageConditional(sum, prior); return(new TruncatedGaussian(post, sum - b.UpperBound, sum - b.LowerBound)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IndexOfMaximumOp"]/message_doc[@name="LogAverageFactor{GaussianList}(IndexOfMaximumBuffer, GaussianList, int)"]/*'/> /// <typeparam name="GaussianList">The type of an incoming message from <c>list</c>.</typeparam> public static double LogAverageFactor <GaussianList>(IndexOfMaximumBuffer Buffer, GaussianList list, int IndexOfMaximumDouble) where GaussianList : IList <Gaussian> { double evidence = 0; var max_marginal = list[IndexOfMaximumDouble] * Buffer.to_list[IndexOfMaximumDouble]; for (int c = 0; c < list.Count; c++) { 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]); evidence += IsPositiveOp.LogEvidenceRatio(true, msg_to_positiveop); // sum operator does not contribute because no projection is involved // the x[index]-x[c] variable does not contribute because it only connects to two factors evidence -= msg_to_sum.GetLogAverageOf(Buffer.MessagesToMax[c]); if (max_marginal.IsPointMass) { evidence += Buffer.MessagesToMax[c].GetLogAverageOf(max_marginal); } else { evidence -= Buffer.MessagesToMax[c].GetLogNormalizer(); } } } //evidence += ReplicateOp.LogEvidenceRatio<Gaussian>(MessagesToMax, list[IndexOfMaximumDouble], MessagesToMax.Select(o => max_marginal / o).ToArray()); if (!max_marginal.IsPointMass) { evidence += max_marginal.GetLogNormalizer() - list[IndexOfMaximumDouble].GetLogNormalizer(); } //evidence -= Buffer.MessagesToMax.Sum(o => o.GetLogNormalizer()); //evidence -= Buffer.MessagesToMax.Sum(o => (max_marginal / o).GetLogAverageOf(o)); return(evidence); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IndexOfMaximumOp"]/message_doc[@name="Buffer{GaussianList}(IndexOfMaximumBuffer, GaussianList, int)"]/*'/> /// <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); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PlusWrappedGaussianOp"]/message_doc[@name="AAverageConditional(WrappedGaussian, double)"]/*'/> public static WrappedGaussian AAverageConditional([SkipIfUniform] WrappedGaussian sum, double b) { WrappedGaussian result = WrappedGaussian.Uniform(sum.Period); result.Gaussian = DoublePlusOp.AAverageConditional(sum.Gaussian, b); result.Normalize(); return(result); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PlusTruncatedGaussianOp"]/message_doc[@name="AAverageConditional(TruncatedGaussian, double)"]/*'/> public static TruncatedGaussian AAverageConditional([SkipIfUniform] TruncatedGaussian sum, double b) { Gaussian prior = sum.ToGaussian(); Gaussian post = DoublePlusOp.AAverageConditional(prior, b); TruncatedGaussian result = sum; result.Gaussian = post; result.LowerBound -= b; result.UpperBound -= b; return(result); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PlusTruncatedGaussianOp"]/message_doc[@name="SumAverageConditional(double, TruncatedGaussian)"]/*'/> public static TruncatedGaussian SumAverageConditional(double a, [SkipIfUniform] TruncatedGaussian b) { Gaussian prior = b.ToGaussian(); Gaussian post = DoublePlusOp.SumAverageConditional(a, prior); TruncatedGaussian result = b; result.Gaussian = post; result.LowerBound += a; result.UpperBound += a; return(result); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PlusWrappedGaussianOp"]/message_doc[@name="AAverageConditional(WrappedGaussian, WrappedGaussian)"]/*'/> public static WrappedGaussian AAverageConditional([SkipIfUniform] WrappedGaussian sum, [SkipIfUniform] WrappedGaussian b) { if (sum.Period != b.Period) { throw new ArgumentException("sum.Period (" + sum.Period + ") != b.Period (" + b.Period + ")"); } WrappedGaussian result = WrappedGaussian.Uniform(sum.Period); result.Gaussian = DoublePlusOp.AAverageConditional(sum.Gaussian, b.Gaussian); result.Normalize(); return(result); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoublePlusVmpOp"]/message_doc[@name="SumAverageLogarithm(Gaussian, double)"]/*'/> public static Gaussian SumAverageLogarithm([SkipIfUniform] Gaussian a, double b) { return(DoublePlusOp.SumAverageConditional(a, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoublePlusVmpOp"]/message_doc[@name="AverageLogFactor(double, double, double)"]/*'/> public static double AverageLogFactor(double sum, double a, double b) { return(DoublePlusOp.LogAverageFactor(sum, a, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoublePlusVmpOp"]/message_doc[@name="SumAverageLogarithm(double, WrappedGaussian)"]/*'/> public static WrappedGaussian SumAverageLogarithm(double a, [SkipIfUniform] WrappedGaussian b) { return(DoublePlusOp.SumAverageConditional(a, b)); }
public static Gaussian BAverageConditional([SkipIfUniform] Gaussian Sum, Gaussian a) { return(DoublePlusOp.BAverageConditional(Sum, a)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoublePlusOp"]/message_doc[@name="SumAverageConditional(Gaussian, Gaussian)"]/*'/> public static Gaussian SumAverageConditional([NoInit] Gaussian a, [NoInit] Gaussian b) { return(DoublePlusOp.SumAverageConditional(a, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoubleMinusVmpOp"]/message_doc[@name="DifferenceAverageLogarithm(Gaussian, Gaussian)"]/*'/> public static Gaussian DifferenceAverageLogarithm([SkipIfUniform] Gaussian a, [SkipIfUniform] Gaussian b) { return(DoublePlusOp.AAverageConditional(a, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PlusTruncatedGaussianOp"]/message_doc[@name="AAverageConditional(Gaussian, Gaussian)"]/*'/> public static Gaussian AAverageConditional([SkipIfUniform] Gaussian sum, [SkipIfUniform] TruncatedGaussian b) { return(DoublePlusOp.AAverageConditional(sum, b.ToGaussian())); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="PlusTruncatedGaussianOp"]/message_doc[@name="SumAverageConditional(Gaussian, TruncatedGaussian)"]/*'/> public static Gaussian SumAverageConditional([SkipIfUniform] Gaussian a, [SkipIfUniform] TruncatedGaussian b) { return(DoublePlusOp.SumAverageConditional(a, b.ToGaussian())); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoublePlusVmpOp"]/message_doc[@name="SumAverageLogarithm(double, double)"]/*'/> public static Gaussian SumAverageLogarithm(double a, double b) { return(DoublePlusOp.SumAverageConditional(a, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoublePlusVmpOp"]/message_doc[@name="AAverageLogarithm(double, double)"]/*'/> public static Gaussian AAverageLogarithm(double Sum, double b) { return(DoublePlusOp.AAverageConditional(Sum, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoublePlusEvidenceOp"]/message_doc[@name="LogEvidenceRatio(double, double, double)"]/*'/> public static double LogEvidenceRatio(double Sum, double a, double b) { return(DoublePlusOp.LogAverageFactor(Sum, a, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoubleMinusVmpOp"]/message_doc[@name="DifferenceAverageLogarithm(double, double)"]/*'/> public static Gaussian DifferenceAverageLogarithm(double a, double b) { return(DoublePlusOp.AAverageConditional(a, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoubleMinusEvidenceOp"]/message_doc[@name="LogEvidenceRatio(double, double, double)"]/*'/> public static double LogEvidenceRatio(double difference, double a, double b) { return(DoublePlusOp.LogAverageFactor(a, difference, b)); }
public static Gaussian AAverageConditional([SkipIfUniform] Gaussian Sum, Gaussian b) { return(DoublePlusOp.AAverageConditional(Sum, b)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoubleMinusEvidenceOp"]/message_doc[@name="LogEvidenceRatio(double, Gaussian, Gaussian)"]/*'/> public static double LogEvidenceRatio(double difference, Gaussian a, [Fresh] Gaussian to_a) { return(DoublePlusOp.LogAverageFactor(a, to_a)); }
/// <summary> /// Returns the probability that A>B /// </summary> /// <param name="A"></param> /// <param name="B"></param> /// <returns></returns> private static Bernoulli ProbGreater(Gaussian A, Gaussian B) { Gaussian diff = DoublePlusOp.AAverageConditional(Sum: A, b: B); return(IsPositiveOp.IsPositiveAverageConditional(diff)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="DoubleMinusEvidenceOp"]/message_doc[@name="LogEvidenceRatio(double, double, Gaussian, Gaussian)"]/*'/> public static double LogEvidenceRatio(double difference, double a, Gaussian b, [Fresh] Gaussian to_b) { return(DoublePlusOp.LogAverageFactor(b, to_b)); }