/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="IsGreaterThanAverageConditional(int, Binomial)"]/*'/> public static Bernoulli IsGreaterThanAverageConditional(int a, [Proper] Binomial b) { if (b.IsPointMass) { return(Bernoulli.PointMass(a > b.Point)); } if (b.A == 1 && b.B == 1) { if (a <= 0) { return(Bernoulli.PointMass(false)); } else if (a > b.TrialCount) { return(Bernoulli.PointMass(true)); } else { return(new Bernoulli(MMath.Beta(1 - b.ProbSuccess, b.TrialCount - a + 1, a))); } } else { double sum = 0; for (int i = 0; i < a; i++) { sum += Math.Exp(b.GetLogProb(i)); } if (sum > 1) { sum = 1; // this can happen due to round-off errors } return(new Bernoulli(sum)); } }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="IsGreaterThanAverageConditional(int, Poisson)"]/*'/> public static Bernoulli IsGreaterThanAverageConditional(int a, [Proper] Poisson b) { if (b.IsPointMass) { return(Bernoulli.PointMass(a > b.Point)); } if (b.Precision == 1) { if (a <= 0) { return(Bernoulli.PointMass(false)); } else { return(new Bernoulli(MMath.GammaUpper(a, b.Rate))); } } else { double sum = 0; for (int i = 0; i < a; i++) { sum += Math.Exp(b.GetLogProb(i)); } if (sum > 1) { sum = 1; // this can happen due to round-off errors } return(new Bernoulli(sum)); } }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="IsGreaterThanAverageConditional(Poisson, int)"]/*'/> public static Bernoulli IsGreaterThanAverageConditional([Proper] Poisson a, int b) { if (a.IsPointMass) { return(Bernoulli.PointMass(a.Point > b)); } if (a.Precision == 1) { if (b < 0) { return(Bernoulli.PointMass(true)); } else { return(new Bernoulli(MMath.GammaLower(b + 1, a.Rate))); } } else { double sum = 0; for (int i = 0; i <= b; i++) { sum += Math.Exp(a.GetLogProb(i)); } if (sum > 1) { sum = 1; // this can happen due to round-off errors } return(new Bernoulli(1 - sum)); } }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="IsGreaterThanAverageConditional(Binomial, int)"]/*'/> public static Bernoulli IsGreaterThanAverageConditional([Proper] Binomial a, int b) { if (a.IsPointMass) { return(Bernoulli.PointMass(a.Point > b)); } if (a.A == 1 && a.B == 1) { if (b < 0) { return(Bernoulli.PointMass(true)); } else if (b >= a.TrialCount) { return(Bernoulli.PointMass(false)); } else { return(new Bernoulli(MMath.Beta(a.ProbSuccess, b + 1, a.TrialCount - b))); } } else { double sum = 0; for (int i = 0; i <= b; i++) { sum += Math.Exp(a.GetLogProb(i)); } if (sum > 1) { sum = 1; // this can happen due to round-off errors } return(new Bernoulli(1 - sum)); } }
public static Bernoulli IsGreaterThanAverageConditional(double a, [Proper] Beta b) { if (b.IsPointMass) { return(Bernoulli.PointMass(a > b.Point)); } return(new Bernoulli(b.GetProbLessThan(a))); }
// Gamma --------------------------------------------------------------------------------------- public static Bernoulli IsGreaterThanAverageConditional([Proper] Gamma a, double b) { if (a.IsPointMass) { return(Bernoulli.PointMass(a.Point > b)); } return(new Bernoulli(1 - a.GetProbLessThan(b))); }
/// <summary> /// EP message to 'a'. /// </summary> /// <param name="and">Constant value for 'and'.</param> /// <param name="B">Incoming message from 'b'.</param> /// <returns>The outgoing EP message to the 'a' argument.</returns> /// <remarks><para> /// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'a'. /// The formula is <c>int f(a,x) q(x) dx</c> where <c>x = (and,b)</c>. /// </para></remarks> public static Bernoulli AAverageConditional(bool and, Bernoulli B) { if (B.IsPointMass) { return(AAverageConditional(and, B.Point)); } return(AAverageConditional(Bernoulli.PointMass(and), B)); }
/// <summary> /// EP message to 'allTrue'. /// </summary> /// <param name="array">Constant value for 'array'.</param> /// <returns>The outgoing EP message to the 'allTrue' argument.</returns> /// <remarks><para> /// The outgoing message is the factor viewed as a function of 'allTrue' conditioned on the given values. /// </para></remarks> public static Bernoulli AllTrueAverageConditional(IList <bool> array) { foreach (bool b in array) { if (!b) { return(Bernoulli.PointMass(false)); } } return(Bernoulli.PointMass(true)); }
/// <summary> /// EP message to 'and'. /// </summary> /// <param name="A">Constant value for 'a'.</param> /// <param name="B">Incoming message from 'b'.</param> /// <returns>The outgoing EP message to the 'and' argument.</returns> /// <remarks><para> /// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'and'. /// The formula is <c>int f(and,x) q(x) dx</c> where <c>x = (a,b)</c>. /// </para></remarks> public static Bernoulli AndAverageConditional(bool A, Bernoulli B) { if (A) { return(B); } else { return(Bernoulli.PointMass(false)); } }
/// <summary> /// EP message to 'isGreaterThan' /// </summary> /// <param name="a">Incoming message from 'a'.</param> /// <param name="b">Constant value for 'b'.</param> /// <returns>The outgoing EP message to the 'isGreaterThan' argument</returns> /// <remarks><para> /// The outgoing message is a distribution matching the moments of 'isGreaterThan' as the random arguments are varied. /// The formula is <c>proj[p(isGreaterThan) sum_(a) p(a) factor(isGreaterThan,a,b)]/p(isGreaterThan)</c>. /// </para></remarks> public static Bernoulli IsGreaterThanAverageConditional(Discrete a, int b) { if (a.IsPointMass) { return(Bernoulli.PointMass(a.Point > b)); } double sum = 0.0; for (int i = b + 1; i < a.Dimension; i++) { sum += a[i]; } return(new Bernoulli(sum)); }
/// <summary> /// EP message to 'a'. /// </summary> /// <param name="and">Constant value for 'and'.</param> /// <param name="B">Constant value for 'b'.</param> /// <returns>The outgoing EP message to the 'a' argument.</returns> /// <remarks><para> /// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'a'. /// The formula is <c>int f(a,x) q(x) dx</c> where <c>x = (and,b)</c>. /// </para></remarks> public static Bernoulli AAverageConditional(bool and, bool B) { if (B) { return(Bernoulli.PointMass(and)); } else if (!and) { return(Bernoulli.Uniform()); } else { throw new AllZeroException(); } }
/// <summary> /// EP message to 'isGreaterThan' /// </summary> /// <param name="a">Constant value for 'a'.</param> /// <param name="b">Incoming message from 'b'.</param> /// <returns>The outgoing EP message to the 'isGreaterThan' argument</returns> /// <remarks><para> /// The outgoing message is a distribution matching the moments of 'isGreaterThan' as the random arguments are varied. /// The formula is <c>proj[p(isGreaterThan) sum_(b) p(b) factor(isGreaterThan,a,b)]/p(isGreaterThan)</c>. /// </para></remarks> public static Bernoulli IsGreaterThanAverageConditional(int a, Discrete b) { if (b.IsPointMass) { return(Bernoulli.PointMass(a > b.Point)); } double sum = 0.0; for (int i = 0; (i < a) && (i < b.Dimension); i++) { sum += b[i]; } if (sum > 1) { sum = 1; // this can happen due to round-off errors } return(new Bernoulli(sum)); }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IsGreaterThanOp"]/message_doc[@name="IsGreaterThanAverageConditional(Discrete, int)"]/*'/> public static Bernoulli IsGreaterThanAverageConditional(Discrete a, int b) { if (a.IsPointMass) { return(Bernoulli.PointMass(a.Point > b)); } double sum = 0.0; for (int i = b + 1; i < a.Dimension; i++) { sum += a[i]; } if (sum > 1) { sum = 1; // this can happen due to round-off errors } return(new Bernoulli(sum)); }
public void BernoulliFromBetaOpTest() { Assert.True(System.Math.Abs(BernoulliFromBetaOp.LogEvidenceRatio(new Bernoulli(3e-5), Beta.PointMass(1)) - 0) < 1e-10); using (TestUtils.TemporarilyAllowBetaImproperSums) { Beta probTrueDist = new Beta(3, 2); Bernoulli sampleDist = new Bernoulli(); Assert.True(new Beta(1, 1).MaxDiff(BernoulliFromBetaOp.ProbTrueAverageConditional(sampleDist, probTrueDist)) < 1e-4); sampleDist = Bernoulli.PointMass(true); Assert.True(new Beta(2, 1).MaxDiff(BernoulliFromBetaOp.ProbTrueAverageConditional(sampleDist, probTrueDist)) < 1e-4); sampleDist = Bernoulli.PointMass(false); Assert.True(new Beta(1, 2).MaxDiff(BernoulliFromBetaOp.ProbTrueAverageConditional(sampleDist, probTrueDist)) < 1e-4); sampleDist = new Bernoulli(0.9); Assert.True(new Beta(1.724, 0.9598).MaxDiff(BernoulliFromBetaOp.ProbTrueAverageConditional(sampleDist, probTrueDist)) < 1e-3); Assert.Throws <ImproperMessageException>(() => { BernoulliFromBetaOp.ProbTrueAverageConditional(sampleDist, new Beta(1, -2)); }); } }
public void ConstantPropagationTest() { var a = Variable.Bernoulli(0.5).Named("a"); var b = Variable.Bernoulli(0.5).Named("b"); var c = Variable.Bernoulli(0.5).Named("c"); var d = Variable.Bernoulli(0.5).Named("d"); using (Variable.If(c)) { Variable.ConstrainTrue(d); } Variable.ConstrainEqual(b, c); using (Variable.If(a)) { Variable.ConstrainTrue(b); } Variable.ConstrainTrue(a); InferenceEngine engine = new InferenceEngine(); Bernoulli dActual = engine.Infer <Bernoulli>(d); Bernoulli dExpected = Bernoulli.PointMass(true); Assert.Equal(dActual, dExpected); }
/// <summary>Computations that depend on the observed value of FeatureCount and FeatureValues and InstanceCount and Labels and numberOfIterations and WeightConstraints and WeightPriors</summary> /// <param name="numberOfIterations">The number of times to iterate each loop</param> private void Changed_FeatureCount_FeatureValues_InstanceCount_Labels_numberOfIterations_WeightConstraints_WeightP8(int numberOfIterations) { if (this.Changed_FeatureCount_FeatureValues_InstanceCount_Labels_numberOfIterations_WeightConstraints_WeightP8_isDone) { return; } for (int iteration = this.numberOfIterationsDone; iteration < numberOfIterations; iteration++) { for (int FeatureRange = 0; FeatureRange < this.featureCount; FeatureRange++) { this.Weights_depth1_rep_F_marginal[FeatureRange] = ReplicateOp_Divide.Marginal <Gaussian>(this.Weights_depth1_rep_B_toDef[FeatureRange], this.Weights_uses_F[1][FeatureRange], this.Weights_depth1_rep_F_marginal[FeatureRange]); } for (int InstanceRange = 0; InstanceRange < this.instanceCount; InstanceRange++) { for (int FeatureRange = 0; FeatureRange < this.featureCount; FeatureRange++) { this.Weights_depth1_rep_F[FeatureRange][InstanceRange] = ReplicateOp_Divide.UsesAverageConditional <Gaussian>(this.Weights_depth1_rep_B[FeatureRange][InstanceRange], this.Weights_depth1_rep_F_marginal[FeatureRange], InstanceRange, this.Weights_depth1_rep_F[FeatureRange][InstanceRange]); this.FeatureScores_F[InstanceRange][FeatureRange] = GaussianProductOpBase.ProductAverageConditional(this.featureValues[InstanceRange][FeatureRange], this.Weights_depth1_rep_F[FeatureRange][InstanceRange]); } this.Score_F[InstanceRange] = FastSumOp.SumAverageConditional(this.FeatureScores_F[InstanceRange]); this.NoisyScore_F[InstanceRange] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(this.Score_F[InstanceRange], 1.0); this.NoisyScore_use_B[InstanceRange] = IsPositiveOp_Proper.XAverageConditional(Bernoulli.PointMass(this.labels[InstanceRange]), this.NoisyScore_F[InstanceRange]); this.Score_B[InstanceRange] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(this.NoisyScore_use_B[InstanceRange], 1.0); this.FeatureScores_B[InstanceRange] = FastSumOp.ArrayAverageConditional <DistributionStructArray <Gaussian, double> >(this.Score_B[InstanceRange], this.Score_F[InstanceRange], this.FeatureScores_F[InstanceRange], this.FeatureScores_B[InstanceRange]); for (int FeatureRange = 0; FeatureRange < this.featureCount; FeatureRange++) { this.Weights_depth1_rep_B[FeatureRange][InstanceRange] = GaussianProductOpBase.BAverageConditional(this.FeatureScores_B[InstanceRange][FeatureRange], this.featureValues[InstanceRange][FeatureRange]); this.Weights_depth1_rep_F_marginal[FeatureRange] = ReplicateOp_Divide.MarginalIncrement <Gaussian>(this.Weights_depth1_rep_F_marginal[FeatureRange], this.Weights_depth1_rep_F[FeatureRange][InstanceRange], this.Weights_depth1_rep_B[FeatureRange][InstanceRange]); } } for (int FeatureRange = 0; FeatureRange < this.featureCount; FeatureRange++) { this.Weights_depth1_rep_B_toDef[FeatureRange] = ReplicateOp_Divide.ToDef <Gaussian>(this.Weights_depth1_rep_B[FeatureRange], this.Weights_depth1_rep_B_toDef[FeatureRange]); } this.OnProgressChanged(new ProgressChangedEventArgs(iteration)); } for (int _iv = 0; _iv < this.featureCount; _iv++) { this.Weights_uses_B[1][_iv] = ArrayHelper.SetTo <Gaussian>(this.Weights_uses_B[1][_iv], this.Weights_depth1_rep_B_toDef[_iv]); } this.Weights_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.weightPriors, 0, this.Weights_uses_F[0]); this.ModelSelector_selector_cases_0_uses_B[6] = Bernoulli.FromLogOdds(ReplicateOp.LogEvidenceRatio <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.weightPriors, this.Weights_uses_F)); this.ModelSelector_selector_cases_0_uses_B[7] = Bernoulli.FromLogOdds(ConstrainEqualRandomOp <double[]> .LogEvidenceRatio <DistributionStructArray <Gaussian, double> >(this.Weights_uses_F[0], this.weightConstraints)); for (int FeatureRange = 0; FeatureRange < this.featureCount; FeatureRange++) { this.ModelSelector_selector_cases_0_rep3_uses_B[FeatureRange][1] = Bernoulli.FromLogOdds(ReplicateOp.LogEvidenceRatio <Gaussian>(this.Weights_depth1_rep_B[FeatureRange], this.Weights_uses_F[1][FeatureRange], this.Weights_depth1_rep_F[FeatureRange])); this.ModelSelector_selector_cases_0_rep3_B[FeatureRange] = ReplicateOp_NoDivide.DefAverageConditional <Bernoulli>(this.ModelSelector_selector_cases_0_rep3_uses_B[FeatureRange], this.ModelSelector_selector_cases_0_rep3_B[FeatureRange]); } this.ModelSelector_selector_cases_0_uses_B[12] = ReplicateOp_NoDivide.DefAverageConditional <Bernoulli>(this.ModelSelector_selector_cases_0_rep3_B, this.ModelSelector_selector_cases_0_uses_B[12]); for (int InstanceRange = 0; InstanceRange < this.instanceCount; InstanceRange++) { this.ModelSelector_selector_cases_0_rep8_B[InstanceRange] = Bernoulli.FromLogOdds(IsPositiveOp.LogEvidenceRatio(this.labels[InstanceRange], this.NoisyScore_F[InstanceRange])); } this.ModelSelector_selector_cases_0_uses_B[17] = ReplicateOp_NoDivide.DefAverageConditional <Bernoulli>(this.ModelSelector_selector_cases_0_rep8_B, this.ModelSelector_selector_cases_0_uses_B[17]); this.ModelSelector_selector_cases_0_B = ReplicateOp_NoDivide.DefAverageConditional <Bernoulli>(this.ModelSelector_selector_cases_0_uses_B, this.ModelSelector_selector_cases_0_B); this.ModelSelector_selector_cases_B[0] = ArrayHelper.SetTo <Bernoulli>(this.ModelSelector_selector_cases_B[0], this.ModelSelector_selector_cases_0_B); this.ModelSelector_selector_B = CasesOp.BAverageConditional(this.ModelSelector_selector_cases_B); this.ModelSelector_marginal_F = VariableOp.MarginalAverageConditional <Bernoulli>(this.ModelSelector_selector_B, this.vBernoulli0, this.ModelSelector_marginal_F); this.Weights_use_B = ReplicateOp_NoDivide.DefAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.Weights_use_B); this.Weights_marginal_F = VariableOp.MarginalAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_use_B, this.weightPriors, this.Weights_marginal_F); this.Changed_FeatureCount_FeatureValues_InstanceCount_Labels_numberOfIterations_WeightConstraints_WeightP8_isDone = true; }
/// <summary>Evidence message for EP.</summary> /// <param name="isPositive">Constant value for <c>isPositive</c>.</param> /// <param name="x">Incoming message from <c>x</c>.</param> /// <returns>Logarithm of the factor's average value across the given argument distributions.</returns> /// <remarks> /// <para>The formula for the result is <c>log(sum_(x) p(x) factor(isPositive,x))</c>.</para> /// </remarks> public static double LogAverageFactor(bool isPositive, Gaussian x) { return(LogAverageFactor(Bernoulli.PointMass(isPositive), x)); }
/// <summary>VMP message to <c>set</c>.</summary> /// <param name="i">Constant value for <c>i</c>.</param> /// <param name="result">Modified to contain the outgoing message.</param> /// <returns> /// <paramref name="result" /> /// </returns> /// <remarks> /// <para>The outgoing message is the factor viewed as a function of <c>set</c> conditioned on the given values.</para> /// </remarks> public static BernoulliIntegerSubset SetAverageLogarithm(int i, BernoulliIntegerSubset result) { result.SetToUniform(); result.SparseBernoulliList[i] = Bernoulli.PointMass(true); return(result); }
/// <summary> /// EP message to 'b' /// </summary> /// <param name="isGreaterThan">Constant value for 'isGreaterThan'.</param> /// <param name="a">Constant value for 'a'.</param> /// <param name="result">Modified to contain the outgoing message</param> /// <returns><paramref name="result"/></returns> /// <remarks><para> /// The outgoing message is the factor viewed as a function of 'b' conditioned on the given values. /// </para></remarks> public static Discrete BAverageConditional(bool isGreaterThan, int a, Discrete result) { return(BAverageConditional(Bernoulli.PointMass(isGreaterThan), a, result)); }
/// <summary>Computations that depend on the observed value of numberOfIterations and vint__0 and vint__1</summary> /// <param name="numberOfIterations">The number of times to iterate each loop</param> private void Changed_numberOfIterations_vint__0_vint__1(int numberOfIterations) { if (this.Changed_numberOfIterations_vint__0_vint__1_isDone) { return; } DistributionStructArray <Gaussian, double> vdouble__0_F; Gaussian vdouble__0_F_reduced; // Create array for 'vdouble__0' Forwards messages. vdouble__0_F = new DistributionStructArray <Gaussian, double>(5); // Message to 'vdouble__0' from GaussianFromMeanAndVariance factor vdouble__0_F_reduced = GaussianFromMeanAndVarianceOp.SampleAverageConditional(6.0, 9.0); for (int index1 = 0; index1 < 5; index1++) { vdouble__0_F[index1] = vdouble__0_F_reduced; vdouble__0_F[index1] = vdouble__0_F_reduced; } // Create array for 'vdouble__0_marginal' Forwards messages. this.vdouble__0_marginal_F = new DistributionStructArray <Gaussian, double>(5); DistributionStructArray <Gaussian, double> vdouble__0_use_B; // Create array for 'vdouble__0_use' Backwards messages. vdouble__0_use_B = new DistributionStructArray <Gaussian, double>(5); for (int index1 = 0; index1 < 5; index1++) { vdouble__0_use_B[index1] = Gaussian.Uniform(); } DistributionStructArray <Gaussian, double>[] vdouble__0_uses_F; // Create array for 'vdouble__0_uses' Forwards messages. vdouble__0_uses_F = new DistributionStructArray <Gaussian, double> [2]; // Create array for 'vdouble__0_uses' Forwards messages. vdouble__0_uses_F[1] = new DistributionStructArray <Gaussian, double>(5); for (int index1 = 0; index1 < 5; index1++) { vdouble__0_uses_F[1][index1] = Gaussian.Uniform(); } DistributionStructArray <Gaussian, double> vdouble__0_uses_F_1__marginal; // Message to 'vdouble__0_itemvint__1_index0_' from GetItems factor vdouble__0_uses_F_1__marginal = GetItemsOp <double> .MarginalInit <DistributionStructArray <Gaussian, double> >(vdouble__0_uses_F[1]); DistributionStructArray <Gaussian, double> vdouble__0_itemvint__1_index0__F; // Create array for 'vdouble__0_itemvint__1_index0_' Forwards messages. vdouble__0_itemvint__1_index0__F = new DistributionStructArray <Gaussian, double>(6); for (int index0 = 0; index0 < 6; index0++) { vdouble__0_itemvint__1_index0__F[index0] = Gaussian.Uniform(); } // Create array for replicates of 'vdouble11_F' DistributionStructArray <Gaussian, double> vdouble11_F = new DistributionStructArray <Gaussian, double>(6); for (int index0 = 0; index0 < 6; index0++) { vdouble11_F[index0] = Gaussian.Uniform(); } // Create array for 'vdouble__0_uses' Forwards messages. vdouble__0_uses_F[0] = new DistributionStructArray <Gaussian, double>(5); for (int index1 = 0; index1 < 5; index1++) { vdouble__0_uses_F[0][index1] = Gaussian.Uniform(); } DistributionStructArray <Gaussian, double> vdouble__0_uses_F_0__marginal; // Message to 'vdouble__0_itemvint__0_index0_' from GetItems factor vdouble__0_uses_F_0__marginal = GetItemsOp <double> .MarginalInit <DistributionStructArray <Gaussian, double> >(vdouble__0_uses_F[0]); DistributionStructArray <Gaussian, double> vdouble__0_itemvint__0_index0__F; // Create array for 'vdouble__0_itemvint__0_index0_' Forwards messages. vdouble__0_itemvint__0_index0__F = new DistributionStructArray <Gaussian, double>(6); for (int index0 = 0; index0 < 6; index0++) { vdouble__0_itemvint__0_index0__F[index0] = Gaussian.Uniform(); } // Create array for replicates of 'vdouble8_F' DistributionStructArray <Gaussian, double> vdouble8_F = new DistributionStructArray <Gaussian, double>(6); for (int index0 = 0; index0 < 6; index0++) { vdouble8_F[index0] = Gaussian.Uniform(); } // Create array for replicates of 'vdouble12_F' DistributionStructArray <Gaussian, double> vdouble12_F = new DistributionStructArray <Gaussian, double>(6); for (int index0 = 0; index0 < 6; index0++) { vdouble12_F[index0] = Gaussian.Uniform(); } // Create array for replicates of 'vdouble12_B' DistributionStructArray <Gaussian, double> vdouble12_B = new DistributionStructArray <Gaussian, double>(6); for (int index0 = 0; index0 < 6; index0++) { vdouble12_B[index0] = Gaussian.Uniform(); } // Create array for replicates of 'vdouble8_use_B' DistributionStructArray <Gaussian, double> vdouble8_use_B = new DistributionStructArray <Gaussian, double>(6); for (int index0 = 0; index0 < 6; index0++) { vdouble8_use_B[index0] = Gaussian.Uniform(); } // Create array for replicates of 'vdouble11_use_B' DistributionStructArray <Gaussian, double> vdouble11_use_B = new DistributionStructArray <Gaussian, double>(6); for (int index0 = 0; index0 < 6; index0++) { vdouble11_use_B[index0] = Gaussian.Uniform(); } for (int iteration = this.numberOfIterationsDone; iteration < numberOfIterations; iteration++) { // Message to 'vdouble__0_uses' from Replicate factor vdouble__0_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.vdouble__0_uses_B, vdouble__0_F, 1, vdouble__0_uses_F[1]); // Message to 'vdouble__0_itemvint__1_index0_' from GetItems factor vdouble__0_uses_F_1__marginal = GetItemsOp <double> .Marginal <DistributionStructArray <Gaussian, double>, Gaussian>(vdouble__0_uses_F[1], this.vdouble__0_uses_B[1], vdouble__0_uses_F_1__marginal); // Message to 'vdouble__0_uses' from Replicate factor vdouble__0_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.vdouble__0_uses_B, vdouble__0_F, 0, vdouble__0_uses_F[0]); // Message to 'vdouble__0_itemvint__0_index0_' from GetItems factor vdouble__0_uses_F_0__marginal = GetItemsOp <double> .Marginal <DistributionStructArray <Gaussian, double>, Gaussian>(vdouble__0_uses_F[0], this.vdouble__0_uses_B[0], vdouble__0_uses_F_0__marginal); for (int index0 = 0; index0 < 6; index0++) { // Message to 'vdouble__0_itemvint__1_index0_' from GetItems factor vdouble__0_itemvint__1_index0__F[index0] = GetItemsOp <double> .ItemsAverageConditional <DistributionStructArray <Gaussian, double>, Gaussian>(this.vdouble__0_itemvint__1_index0__B[index0], vdouble__0_uses_F[1], vdouble__0_uses_F_1__marginal, this.Vint__1, index0, vdouble__0_itemvint__1_index0__F[index0]); // Message to 'vdouble11' from GaussianFromMeanAndVariance factor vdouble11_F[index0] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(vdouble__0_itemvint__1_index0__F[index0], 1.0); // Message to 'vdouble__0_itemvint__0_index0_' from GetItems factor vdouble__0_itemvint__0_index0__F[index0] = GetItemsOp <double> .ItemsAverageConditional <DistributionStructArray <Gaussian, double>, Gaussian>(this.vdouble__0_itemvint__0_index0__B[index0], vdouble__0_uses_F[0], vdouble__0_uses_F_0__marginal, this.Vint__0, index0, vdouble__0_itemvint__0_index0__F[index0]); // Message to 'vdouble8' from GaussianFromMeanAndVariance factor vdouble8_F[index0] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(vdouble__0_itemvint__0_index0__F[index0], 1.0); // Message to 'vdouble12' from Difference factor vdouble12_F[index0] = DoublePlusOp.AAverageConditional(vdouble8_F[index0], vdouble11_F[index0]); // Message to 'vdouble12' from IsPositive factor vdouble12_B[index0] = IsPositiveOp_Proper.XAverageConditional(Bernoulli.PointMass(true), vdouble12_F[index0]); // Message to 'vdouble8_use' from Difference factor vdouble8_use_B[index0] = DoublePlusOp.SumAverageConditional(vdouble12_B[index0], vdouble11_F[index0]); // Message to 'vdouble__0_itemvint__0_index0_' from GaussianFromMeanAndVariance factor this.vdouble__0_itemvint__0_index0__B[index0] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(vdouble8_use_B[index0], 1.0); // Message to 'vdouble11_use' from Difference factor vdouble11_use_B[index0] = DoublePlusOp.BAverageConditional(vdouble8_F[index0], vdouble12_B[index0]); // Message to 'vdouble__0_itemvint__1_index0_' from GaussianFromMeanAndVariance factor this.vdouble__0_itemvint__1_index0__B[index0] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(vdouble11_use_B[index0], 1.0); } // Message to 'vdouble__0_uses' from GetItems factor this.vdouble__0_uses_B[0] = GetItemsOp <double> .ArrayAverageConditional <Gaussian, DistributionStructArray <Gaussian, double> >(this.vdouble__0_itemvint__0_index0__B, this.Vint__0, this.vdouble__0_uses_B[0]); // Message to 'vdouble__0_uses' from GetItems factor this.vdouble__0_uses_B[1] = GetItemsOp <double> .ArrayAverageConditional <Gaussian, DistributionStructArray <Gaussian, double> >(this.vdouble__0_itemvint__1_index0__B, this.Vint__1, this.vdouble__0_uses_B[1]); this.OnProgressChanged(new ProgressChangedEventArgs(iteration)); } // Message to 'vdouble__0_use' from Replicate factor vdouble__0_use_B = ReplicateOp_NoDivide.DefAverageConditional <DistributionStructArray <Gaussian, double> >(this.vdouble__0_uses_B, vdouble__0_use_B); for (int index1 = 0; index1 < 5; index1++) { this.vdouble__0_marginal_F[index1] = Gaussian.Uniform(); // Message to 'vdouble__0_marginal' from Variable factor this.vdouble__0_marginal_F[index1] = VariableOp.MarginalAverageConditional <Gaussian>(vdouble__0_use_B[index1], vdouble__0_F_reduced, this.vdouble__0_marginal_F[index1]); } this.Changed_numberOfIterations_vint__0_vint__1_isDone = true; }
/// <summary>Computations that depend on the observed value of numberOfIterationsDecreased and WeightPriors and FeatureIndexes and InstanceCount and InstanceFeatureCounts and FeatureValues and Labels and WeightConstraints</summary> /// <param name="numberOfIterations">The number of times to iterate each loop</param> private void Changed_numberOfIterationsDecreased_WeightPriors_FeatureIndexes_InstanceCount_InstanceFeatureCounts_7(int numberOfIterations) { if (this.Changed_numberOfIterationsDecreased_WeightPriors_FeatureIndexes_InstanceCount_InstanceFeatureCounts_7_iterationsDone == numberOfIterations) { return; } for (int iteration = this.Changed_numberOfIterationsDecreased_WeightPriors_FeatureIndexes_InstanceCount_InstanceFeatureCounts_7_iterationsDone; iteration < numberOfIterations; iteration++) { // Message to 'Weights_uses' from Replicate factor this.Weights_uses_B_toDef = ReplicateOp_Divide.ToDef <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.Weights_uses_B_toDef); // Message to 'Weights_uses' from Replicate factor this.Weights_uses_F_marginal = ReplicateOp_Divide.Marginal <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B_toDef, this.weightPriors, this.Weights_uses_F_marginal); // Message to 'Weights_uses' from Replicate factor this.Weights_uses_F[1] = ReplicateOp_Divide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B[1], this.Weights_uses_F_marginal, 1, this.Weights_uses_F[1]); // Message to 'Weights_FeatureIndexes' from JaggedSubarray factor this.Weights_uses_F_1__marginal = JaggedSubarrayOp <double> .Marginal <DistributionStructArray <Gaussian, double>, Gaussian, object, DistributionStructArray <Gaussian, double> >(this.Weights_uses_F[1], this.IndexedWeights_B, this.featureIndexes, this.Weights_uses_F_1__marginal); for (int InstanceRange = 0; InstanceRange < this.instanceCount; InstanceRange++) { // Message to 'Weights_FeatureIndexes' from JaggedSubarray factor this.Weights_FeatureIndexes_F[InstanceRange] = JaggedSubarrayOp <double> .ItemsAverageConditional <DistributionStructArray <Gaussian, double>, Gaussian, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B[InstanceRange], this.Weights_uses_F[1], this.Weights_uses_F_1__marginal, this.featureIndexes, InstanceRange, this.Weights_FeatureIndexes_F[InstanceRange]); for (int InstanceFeatureRanges = 0; InstanceFeatureRanges < this.instanceFeatureCounts[InstanceRange]; InstanceFeatureRanges++) { // Message to 'FeatureScores' from Product factor this.FeatureScores_F[InstanceRange][InstanceFeatureRanges] = GaussianProductOp.ProductAverageConditional(this.featureValues[InstanceRange][InstanceFeatureRanges], this.Weights_FeatureIndexes_F[InstanceRange][InstanceFeatureRanges]); } // Message to 'Score' from Sum factor this.Score_F[InstanceRange] = FastSumOp.SumAverageConditional(this.FeatureScores_F[InstanceRange]); // Message to 'NoisyScore' from GaussianFromMeanAndVariance factor this.NoisyScore_F[InstanceRange] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(this.Score_F[InstanceRange], 1.0); // Message to 'NoisyScore_use' from IsPositive factor this.NoisyScore_use_B[InstanceRange] = IsPositiveOp_Proper.XAverageConditional(Bernoulli.PointMass(this.labels[InstanceRange]), this.NoisyScore_F[InstanceRange]); // Message to 'Score' from GaussianFromMeanAndVariance factor this.Score_B[InstanceRange] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(this.NoisyScore_use_B[InstanceRange], 1.0); // Message to 'FeatureScores' from Sum factor this.FeatureScores_B[InstanceRange] = FastSumOp.ArrayAverageConditional <DistributionStructArray <Gaussian, double> >(this.Score_B[InstanceRange], this.Score_F[InstanceRange], this.FeatureScores_F[InstanceRange], this.FeatureScores_B[InstanceRange]); for (int InstanceFeatureRanges = 0; InstanceFeatureRanges < this.instanceFeatureCounts[InstanceRange]; InstanceFeatureRanges++) { // Message to 'IndexedWeights' from Product factor this.IndexedWeights_B[InstanceRange][InstanceFeatureRanges] = GaussianProductOp.BAverageConditional(this.FeatureScores_B[InstanceRange][InstanceFeatureRanges], this.featureValues[InstanceRange][InstanceFeatureRanges]); } this.Weights_uses_F_1__marginal = JaggedSubarrayOp <double> .MarginalIncrement <DistributionStructArray <Gaussian, double>, Gaussian, DistributionStructArray <Gaussian, double> >(this.Weights_uses_F_1__marginal, this.Weights_FeatureIndexes_F[InstanceRange], this.IndexedWeights_B[InstanceRange], this.featureIndexes, InstanceRange); } // Message to 'Weights_uses' from JaggedSubarray factor this.Weights_uses_B[1] = JaggedSubarrayOp <double> .ArrayAverageConditional <Gaussian, DistributionStructArray <Gaussian, double>, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B, this.featureIndexes, this.Weights_uses_B[1]); this.OnProgressChanged(new ProgressChangedEventArgs(iteration)); } // Message to 'Weights_uses' from Replicate factor this.Weights_uses_B_toDef = ReplicateOp_Divide.ToDef <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.Weights_uses_B_toDef); // Message to 'Weights_marginal' from Variable factor this.Weights_marginal_F = VariableOp.MarginalAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B_toDef, this.weightPriors, this.Weights_marginal_F); this.Changed_numberOfIterationsDecreased_WeightPriors_FeatureIndexes_InstanceCount_InstanceFeatureCounts_7_iterationsDone = numberOfIterations; }
/// <summary> /// EP message to 'a' /// </summary> /// <param name="isGreaterThan">Constant value for 'isGreaterThan'.</param> /// <param name="b">Constant value for 'b'.</param> /// <param name="result">Modified to contain the outgoing message</param> /// <returns><paramref name="result"/></returns> /// <remarks><para> /// The outgoing message is the factor viewed as a function of 'a' conditioned on the given values. /// </para></remarks> static public Discrete AAverageConditional(bool isGreaterThan, int b, Discrete result) { return(AAverageConditional(Bernoulli.PointMass(isGreaterThan), b, result)); }
/// <summary>Computations that depend on the observed value of FeatureIndexes and FeatureValues and InstanceCount and InstanceFeatureCounts and Labels and numberOfIterations and WeightConstraints and WeightPriors</summary> /// <param name="numberOfIterations">The number of times to iterate each loop</param> private void Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7(int numberOfIterations) { if (this.Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7_isDone) { return; } for (int iteration = this.numberOfIterationsDone; iteration < numberOfIterations; iteration++) { for (int InstanceRange = 0; InstanceRange < this.instanceCount; InstanceRange++) { this.Weights_FeatureIndexes_F[InstanceRange] = JaggedSubarrayWithMarginalOp <double> .ItemsAverageConditional <DistributionStructArray <Gaussian, double>, Gaussian, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B[InstanceRange], this.Weights_uses_F[1], this.Weights_marginal_F, this.featureIndexes, InstanceRange, this.Weights_FeatureIndexes_F[InstanceRange]); for (int InstanceFeatureRanges = 0; InstanceFeatureRanges < this.instanceFeatureCounts[InstanceRange]; InstanceFeatureRanges++) { this.FeatureScores_F[InstanceRange][InstanceFeatureRanges] = GaussianProductOpBase.ProductAverageConditional(this.featureValues[InstanceRange][InstanceFeatureRanges], this.Weights_FeatureIndexes_F[InstanceRange][InstanceFeatureRanges]); } this.Score_F[InstanceRange] = FastSumOp.SumAverageConditional(this.FeatureScores_F[InstanceRange]); this.NoisyScore_F[InstanceRange] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(this.Score_F[InstanceRange], 1.0); this.NoisyScore_use_B[InstanceRange] = IsPositiveOp_Proper.XAverageConditional(Bernoulli.PointMass(this.labels[InstanceRange]), this.NoisyScore_F[InstanceRange]); this.Score_B[InstanceRange] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(this.NoisyScore_use_B[InstanceRange], 1.0); this.FeatureScores_B[InstanceRange] = FastSumOp.ArrayAverageConditional <DistributionStructArray <Gaussian, double> >(this.Score_B[InstanceRange], this.Score_F[InstanceRange], this.FeatureScores_F[InstanceRange], this.FeatureScores_B[InstanceRange]); for (int InstanceFeatureRanges = 0; InstanceFeatureRanges < this.instanceFeatureCounts[InstanceRange]; InstanceFeatureRanges++) { this.IndexedWeights_B[InstanceRange][InstanceFeatureRanges] = GaussianProductOpBase.BAverageConditional(this.FeatureScores_B[InstanceRange][InstanceFeatureRanges], this.featureValues[InstanceRange][InstanceFeatureRanges]); } this.Weights_marginal_F = JaggedSubarrayWithMarginalOp <double> .MarginalIncrementItems <DistributionStructArray <Gaussian, double>, Gaussian, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B[InstanceRange], this.Weights_FeatureIndexes_F[InstanceRange], this.featureIndexes, InstanceRange, this.Weights_marginal_F); } this.OnProgressChanged(new ProgressChangedEventArgs(iteration)); } this.Weights_uses_B[1] = JaggedSubarrayWithMarginalOp <double> .ArrayAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_F[1], this.Weights_marginal_F, this.Weights_uses_B[1]); this.Weights_B = ReplicateOp_NoDivide.DefAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.Weights_B); this.Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7_isDone = true; }
/// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="BooleanAreEqualOp"]/message_doc[@name="AreEqualAverageConditional(bool, bool)"]/*'/> public static Bernoulli AreEqualAverageConditional(bool A, bool B) { return(Bernoulli.PointMass(Factor.AreEqual(A, B))); }
/// <summary>Computations that depend on the observed value of FeatureIndexes and FeatureValues and InstanceCount and InstanceFeatureCounts and Labels and numberOfIterations and WeightConstraints and WeightPriors</summary> /// <param name="numberOfIterations">The number of times to iterate each loop</param> private void Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7(int numberOfIterations) { if (this.Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7_isDone) { return; } for (int iteration = this.numberOfIterationsDone; iteration < numberOfIterations; iteration++) { for (int InstanceRange = 0; InstanceRange < this.instanceCount; InstanceRange++) { this.Weights_FeatureIndexes_F[InstanceRange] = JaggedSubarrayWithMarginalOp <double> .ItemsAverageConditional <DistributionStructArray <Gaussian, double>, Gaussian, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B[InstanceRange], this.Weights_uses_F[1], this.Weights_marginal_F, this.featureIndexes, InstanceRange, this.Weights_FeatureIndexes_F[InstanceRange]); for (int InstanceFeatureRanges = 0; InstanceFeatureRanges < this.instanceFeatureCounts[InstanceRange]; InstanceFeatureRanges++) { this.FeatureScores_F[InstanceRange][InstanceFeatureRanges] = GaussianProductOpBase.ProductAverageConditional(this.featureValues[InstanceRange][InstanceFeatureRanges], this.Weights_FeatureIndexes_F[InstanceRange][InstanceFeatureRanges]); } this.Score_F[InstanceRange] = FastSumOp.SumAverageConditional(this.FeatureScores_F[InstanceRange]); this.NoisyScore_F[InstanceRange] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(this.Score_F[InstanceRange], 1.0); this.NoisyScore_use_B[InstanceRange] = IsPositiveOp_Proper.XAverageConditional(Bernoulli.PointMass(this.labels[InstanceRange]), this.NoisyScore_F[InstanceRange]); this.Score_B[InstanceRange] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(this.NoisyScore_use_B[InstanceRange], 1.0); this.FeatureScores_B[InstanceRange] = FastSumOp.ArrayAverageConditional <DistributionStructArray <Gaussian, double> >(this.Score_B[InstanceRange], this.Score_F[InstanceRange], this.FeatureScores_F[InstanceRange], this.FeatureScores_B[InstanceRange]); for (int InstanceFeatureRanges = 0; InstanceFeatureRanges < this.instanceFeatureCounts[InstanceRange]; InstanceFeatureRanges++) { this.IndexedWeights_B[InstanceRange][InstanceFeatureRanges] = GaussianProductOpBase.BAverageConditional(this.FeatureScores_B[InstanceRange][InstanceFeatureRanges], this.featureValues[InstanceRange][InstanceFeatureRanges]); } this.Weights_marginal_F = JaggedSubarrayWithMarginalOp <double> .MarginalIncrementItems <DistributionStructArray <Gaussian, double>, Gaussian, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B[InstanceRange], this.Weights_FeatureIndexes_F[InstanceRange], this.featureIndexes, InstanceRange, this.Weights_marginal_F); } this.OnProgressChanged(new ProgressChangedEventArgs(iteration)); } this.Weights_uses_B[1] = JaggedSubarrayWithMarginalOp <double> .ArrayAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_F[1], this.Weights_marginal_F, this.Weights_uses_B[1]); this.Weights_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.weightPriors, 0, this.Weights_uses_F[0]); this.ModelSelector_selector_cases_0_uses_B[3] = Bernoulli.FromLogOdds(ReplicateOp.LogEvidenceRatio <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.weightPriors, this.Weights_uses_F)); this.ModelSelector_selector_cases_0_uses_B[4] = Bernoulli.FromLogOdds(ConstrainEqualRandomOp <double[]> .LogEvidenceRatio <DistributionStructArray <Gaussian, double> >(this.Weights_uses_F[0], this.weightConstraints)); this.ModelSelector_selector_cases_0_uses_B[8] = Bernoulli.FromLogOdds(JaggedSubarrayWithMarginalOp <double> .LogEvidenceRatio <Gaussian, DistributionRefArray <DistributionStructArray <Gaussian, double>, double[]>, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B, this.Weights_uses_F[1], this.featureIndexes, this.Weights_FeatureIndexes_F)); for (int InstanceRange = 0; InstanceRange < this.instanceCount; InstanceRange++) { this.ModelSelector_selector_cases_0_rep9_B[InstanceRange] = Bernoulli.FromLogOdds(IsPositiveOp.LogEvidenceRatio(this.labels[InstanceRange], this.NoisyScore_F[InstanceRange])); } this.ModelSelector_selector_cases_0_uses_B[16] = ReplicateOp_NoDivide.DefAverageConditional <Bernoulli>(this.ModelSelector_selector_cases_0_rep9_B, this.ModelSelector_selector_cases_0_uses_B[16]); this.ModelSelector_selector_cases_0_B = ReplicateOp_NoDivide.DefAverageConditional <Bernoulli>(this.ModelSelector_selector_cases_0_uses_B, this.ModelSelector_selector_cases_0_B); this.ModelSelector_selector_cases_B[0] = ArrayHelper.SetTo <Bernoulli>(this.ModelSelector_selector_cases_B[0], this.ModelSelector_selector_cases_0_B); this.ModelSelector_selector_B = CasesOp.BAverageConditional(this.ModelSelector_selector_cases_B); this.ModelSelector_marginal_F = VariableOp.MarginalAverageConditional <Bernoulli>(this.ModelSelector_selector_B, this.vBernoulli1, this.ModelSelector_marginal_F); this.Weights_B = ReplicateOp_NoDivide.DefAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.Weights_B); this.Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7_isDone = true; }
/// <summary> /// EP message to 'b'. /// </summary> /// <param name="not">Constant value for 'not'.</param> /// <returns>The outgoing EP message to the 'b' argument.</returns> /// <remarks><para> /// The outgoing message is the integral of the factor times incoming messages, over all arguments except 'b'. /// The formula is <c>int f(b,x) q(x) dx</c> where <c>x = (not)</c>. /// </para></remarks> public static Bernoulli BAverageConditional(bool not) { return(Bernoulli.PointMass(!not)); }
/// <summary>EP message to <c>sample</c>.</summary> /// <param name="choice">Constant value for <c>choice</c>.</param> /// <param name="probTrue">Constant value for <c>probTrue</c>.</param> /// <returns>The outgoing EP message to the <c>sample</c> argument.</returns> /// <remarks> /// <para>The outgoing message is the factor viewed as a function of <c>sample</c> conditioned on the given values.</para> /// </remarks> public static Bernoulli SampleAverageConditional(bool choice, double[] probTrue) { return(SampleAverageConditional(Bernoulli.PointMass(choice), probTrue)); }
/// <summary> /// EP message to 'array'. /// </summary> /// <param name="allTrue">Constant value for 'allTrue'.</param> /// <param name="array">Incoming message from 'array'.</param> /// <param name="result">Modified to contain the outgoing message.</param> /// <returns><paramref name="result"/></returns> /// <remarks><para> /// The outgoing message is the factor viewed as a function of 'array' conditioned on the given values. /// </para></remarks> public static BernoulliList ArrayAverageConditional <BernoulliList>(bool allTrue, IList <Bernoulli> array, BernoulliList result) where BernoulliList : IList <Bernoulli> { return(ArrayAverageConditional(Bernoulli.PointMass(allTrue), array, result)); }
/// <summary>EP message to <c>x</c>.</summary> /// <param name="isPositive">Constant value for <c>isPositive</c>.</param> /// <param name="x">Incoming message from <c>x</c>. Must be a proper distribution. If uniform, the result will be uniform.</param> /// <returns>The outgoing EP message to the <c>x</c> argument.</returns> /// <remarks> /// <para>The outgoing message is the factor viewed as a function of <c>x</c> conditioned on the given values.</para> /// </remarks> /// <exception cref="ImproperMessageException"> /// <paramref name="x" /> is not a proper distribution.</exception> public static Gaussian XAverageConditional(bool isPositive, [SkipIfUniform] Gaussian x) { return(XAverageConditional(Bernoulli.PointMass(isPositive), x)); }