Esempio n. 1
0
        /// <include file='FactorDocs.xml' path='factor_docs/message_op_class[@name="IndexOfMaximumStochasticOp"]/message_doc[@name="ListAverageConditional{GaussianList}(IndexOfMaximumBuffer[], GaussianList, Discrete, GaussianList)"]/*'/>
        /// <typeparam name="GaussianList">The type of an incoming message from <c>list</c>.</typeparam>
        public static GaussianList ListAverageConditional <GaussianList>(
            [SkipIfUniform] IndexOfMaximumBuffer[] Buffers, GaussianList list, [SkipIfUniform] Discrete IndexOfMaximumDouble, GaussianList result)
            where GaussianList : DistributionStructArray <Gaussian, double> // IList<Gaussian>
        {
            int count = list.Count;

            int[] indices = Util.ArrayInit(count, i => i);
            // TODO: check if Index is a point mass
            var enterPartial = Util.ArrayInit(count, i => Util.ArrayInit(count, j => Buffers[j].to_list[i]));

            for (int i = 0; i < count; i++)
            {
                result[i] = GateEnterPartialOp <double> .ValueAverageConditional(enterPartial[i], IndexOfMaximumDouble, list[i], indices, result[i]);
            }
            return(result);
        }
        public static GaussianList listAverageConditional <GaussianList>([Fresh, SkipIfUniform] IndexOfMaximumBuffer[] Buffers, GaussianList list, [SkipIfUniform] Discrete IndexOfMaximumDouble, GaussianList result)
            where GaussianList : DistributionStructArray <Gaussian, double> // IList<Gaussian>
        {
            // TODO: check if Index is a point mass
            var results = list.Select(o => list.Select(p => Gaussian.Uniform()).ToList()).ToArray();

            //var evidences = new Bernoulli[list.Count];
            for (int i = 0; i < list.Count; i++)
            {
                for (int j = 0; j < list.Count; j++)
                {
                    results[j][i] = Buffers[i].to_list[j];
                }
            }
            for (int i = 0; i < list.Count; i++)
            {
                result[i] = GateEnterPartialOp <double> .ValueAverageConditional <Gaussian>(results[i], IndexOfMaximumDouble, list[i], System.Linq.Enumerable.Range(0, list.Count).ToArray(), result[i]);
            }
            return(result);
        }
Esempio n. 3
0
        /// <summary>
        /// Tests EP and BP gate enter ops for Bernoulli random variable for correctness given message parameters.
        /// </summary>
        /// <param name="valueProbTrue">Probability of being true for the variable entering the gate.</param>
        /// <param name="enterOneProbTrue">Probability of being true for the variable approximation inside the gate when the selector is true.</param>
        /// <param name="selectorProbTrue">Probability of being true for the selector variable.</param>
        private void DoBernoulliEnterTest(double valueProbTrue, double enterOneProbTrue, double selectorProbTrue)
        {
            var value                   = new Bernoulli(valueProbTrue);
            var enterOne                = new Bernoulli(enterOneProbTrue);
            var selector                = new Bernoulli(selectorProbTrue);
            var selectorInverse         = new Bernoulli(selector.GetProbFalse());
            var discreteSelector        = new Discrete(selector.GetProbTrue(), selector.GetProbFalse());
            var discreteSelectorInverse = new Discrete(selector.GetProbFalse(), selector.GetProbTrue());
            var cases                   = new[] { Bernoulli.FromLogOdds(selector.GetLogProbTrue()), Bernoulli.FromLogOdds(selector.GetLogProbFalse()) };

            // Compute expected message
            double logShift           = enterOne.GetLogNormalizer() + value.GetLogNormalizer() - (value * enterOne).GetLogNormalizer();
            double expectedProbTrue   = selector.GetProbFalse() + (selector.GetProbTrue() * enterOne.GetProbTrue() * Math.Exp(logShift));
            double expectedProbFalse  = selector.GetProbFalse() + (selector.GetProbTrue() * enterOne.GetProbFalse() * Math.Exp(logShift));
            double expectedNormalizer = expectedProbTrue + expectedProbFalse;

            expectedProbTrue /= expectedNormalizer;

            Bernoulli value1, value2;

            // Enter partial (bernoulli selector, first case)
            value1 = GateEnterPartialOp <bool> .ValueAverageConditional(
                new[] { enterOne }, selector, value, new[] { 0 }, new Bernoulli());

            value2 = BeliefPropagationGateEnterPartialOp.ValueAverageConditional(
                new[] { enterOne }, selector, value, new[] { 0 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter partial (bernoulli selector, second case)
            value1 = GateEnterPartialOp <bool> .ValueAverageConditional(
                new[] { enterOne }, selectorInverse, value, new[] { 1 }, new Bernoulli());

            value2 = BeliefPropagationGateEnterPartialOp.ValueAverageConditional(
                new[] { enterOne }, selectorInverse, value, new[] { 1 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter partial (bernoulli selector, both cases)
            value1 = GateEnterPartialOp <bool> .ValueAverageConditional(
                new[] { enterOne, Bernoulli.Uniform() }, selector, value, new[] { 0, 1 }, new Bernoulli());

            value2 = BeliefPropagationGateEnterPartialOp.ValueAverageConditional(
                new[] { enterOne, Bernoulli.Uniform() }, selector, value, new[] { 0, 1 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter partial (discrete selector, first case)
            value1 = GateEnterPartialOp <bool> .ValueAverageConditional(
                new[] { enterOne }, discreteSelector, value, new[] { 0 }, new Bernoulli());

            value2 = BeliefPropagationGateEnterPartialOp.ValueAverageConditional(
                new[] { enterOne }, discreteSelector, value, new[] { 0 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter partial (discrete selector, second case)
            value1 = GateEnterPartialOp <bool> .ValueAverageConditional(
                new[] { enterOne }, discreteSelectorInverse, value, new[] { 1 }, new Bernoulli());

            value2 = BeliefPropagationGateEnterPartialOp.ValueAverageConditional(
                new[] { enterOne }, discreteSelectorInverse, value, new[] { 1 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter partial (discrete selector, both cases)
            value1 = GateEnterPartialOp <bool> .ValueAverageConditional(
                new[] { enterOne, Bernoulli.Uniform() }, discreteSelector, value, new[] { 0, 1 }, new Bernoulli());

            value2 = BeliefPropagationGateEnterPartialOp.ValueAverageConditional(
                new[] { enterOne, Bernoulli.Uniform() }, discreteSelector, value, new[] { 0, 1 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter one (discrete selector, first case)
            value1 = GateEnterOneOp <bool> .ValueAverageConditional(
                enterOne, discreteSelector, value, 0, new Bernoulli());

            value2 = BeliefPropagationGateEnterOneOp.ValueAverageConditional(
                enterOne, discreteSelector, value, 0, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter one (discrete selector, second case)
            value1 = GateEnterOneOp <bool> .ValueAverageConditional(
                enterOne, discreteSelectorInverse, value, 1, new Bernoulli());

            value2 = BeliefPropagationGateEnterOneOp.ValueAverageConditional(
                enterOne, discreteSelectorInverse, value, 1, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter partial two  (first case)
            value1 = GateEnterPartialTwoOp.ValueAverageConditional(
                new[] { enterOne }, cases[0], cases[1], value, new[] { 0 }, new Bernoulli());
            value2 = BeliefPropagationGateEnterPartialTwoOp.ValueAverageConditional(
                new[] { enterOne }, cases[0], cases[1], value, new[] { 0 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter partial two  (second case)
            value1 = GateEnterPartialTwoOp.ValueAverageConditional(
                new[] { enterOne }, cases[1], cases[0], value, new[] { 1 }, new Bernoulli());
            value2 = BeliefPropagationGateEnterPartialTwoOp.ValueAverageConditional(
                new[] { enterOne }, cases[1], cases[0], value, new[] { 1 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter partial two (both cases)
            value1 = GateEnterPartialTwoOp.ValueAverageConditional(
                new[] { enterOne, Bernoulli.Uniform() }, cases[0], cases[1], value, new[] { 0, 1 }, new Bernoulli());
            value2 = BeliefPropagationGateEnterPartialTwoOp.ValueAverageConditional(
                new[] { enterOne, Bernoulli.Uniform() }, cases[0], cases[1], value, new[] { 0, 1 }, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);

            // Enter (discrete selector)
            value1 = GateEnterOp <bool> .ValueAverageConditional(
                new[] { enterOne, Bernoulli.Uniform() }, discreteSelector, value, new Bernoulli());

            value2 = BeliefPropagationGateEnterOp.ValueAverageConditional(
                new[] { enterOne, Bernoulli.Uniform() }, discreteSelector, value, new Bernoulli());
            Assert.Equal(expectedProbTrue, value1.GetProbTrue(), 1e-4);
            Assert.Equal(expectedProbTrue, value2.GetProbTrue(), 1e-4);
        }
Esempio n. 4
0
        /// <summary>Computations that depend on the observed value of Cloudy and WetGrass</summary>
        public void Changed_Cloudy_WetGrass()
        {
            if (this.Changed_Cloudy_WetGrass_iterationsDone == 1)
            {
                return;
            }
            // The constant 'vBernoulli18'
            Bernoulli vBernoulli18 = Bernoulli.FromLogOdds(0);

            this.Cloudy_marginal = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli18);
            this.Cloudy_marginal = Distribution.SetPoint <Bernoulli, bool>(this.Cloudy_marginal, this.cloudy);
            // The constant 'vBernoulli23'
            Bernoulli vBernoulli23 = Bernoulli.FromLogOdds(4.5951198501345889);

            this.WetGrass_marginal = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli23);
            this.WetGrass_marginal = Distribution.SetPoint <Bernoulli, bool>(this.WetGrass_marginal, this.wetGrass);
            // The constant 'vBernoulli21'
            Bernoulli vBernoulli21 = Bernoulli.FromLogOdds(1.3862943611198908);
            Bernoulli Rain_F       = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli21);

            this.Rain_marginal_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli21);
            // Message to use of 'Rain'
            Bernoulli Rain_use_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli21);
            // Message from use of 'Rain'
            Bernoulli Rain_use_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli21);

            if (this.cloudy)
            {
                // Message to 'Rain' from Copy factor
                Rain_F = Factor.Copy <Bernoulli>(vBernoulli21);
            }
            // The constant 'vBernoulli22'
            Bernoulli vBernoulli22 = Bernoulli.FromLogOdds(0.28185115214098749);

            if (!this.cloudy)
            {
                // Message to 'Rain' from Copy factor
                Rain_F = Factor.Copy <Bernoulli>(vBernoulli22);
            }
            // Rain_F is now updated in all contexts
            if (this.cloudy)
            {
                // Message to 'Rain_use' from DerivedVariable factor
                Rain_use_F = Factor.Copy <Bernoulli>(Rain_F);
            }
            Bernoulli Rain_cond_Sprinkler_0_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Rain_cond_Sprinkler_0_selector_cases_0' from Random factor
            Rain_cond_Sprinkler_0_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli23));
            DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_0_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Rain_cond_Sprinkler_0_selector_cases' Backwards messages.
            Rain_cond_Sprinkler_0_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _ind0 = 0; _ind0 < 2; _ind0++)
            {
                Rain_cond_Sprinkler_0_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor
            Rain_cond_Sprinkler_0_selector_cases_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_cases_0_B);
            // The constant 'vBernoulli24'
            Bernoulli vBernoulli24 = Bernoulli.FromLogOdds(2.1972245773362196);
            Bernoulli Rain_cond_Sprinkler_0_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Rain_cond_Sprinkler_0_selector_cases_1' from Random factor
            Rain_cond_Sprinkler_0_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli24));
            // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor
            Rain_cond_Sprinkler_0_selector_cases_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_cases_1_B);
            if (!this.cloudy)
            {
                // Message to 'Rain_use' from DerivedVariable factor
                Rain_use_F = Factor.Copy <Bernoulli>(vBernoulli22);
            }
            // Rain_use_F is now updated in all contexts
            Bernoulli[] Sprinkler_selector_cases_0_uses_B = default(Bernoulli[]);
            // Create array for 'Sprinkler_selector_cases_0_uses' Backwards messages.
            Sprinkler_selector_cases_0_uses_B = new Bernoulli[5];
            for (int _ind = 0; _ind < 5; _ind++)
            {
                Sprinkler_selector_cases_0_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Sprinkler_selector_cases_0_uses' from Cases factor
            Sprinkler_selector_cases_0_uses_B[4] = Bernoulli.FromLogOdds(CasesOp.LogEvidenceRatio(Rain_cond_Sprinkler_0_selector_cases_B, Rain_use_F));
            Bernoulli Sprinkler_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Sprinkler_selector_cases_0' from Replicate factor
            Sprinkler_selector_cases_0_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_cases_0_uses_B, Sprinkler_selector_cases_0_B);
            DistributionStructArray <Bernoulli, bool> Sprinkler_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Sprinkler_selector_cases' Backwards messages.
            Sprinkler_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _ind0 = 0; _ind0 < 2; _ind0++)
            {
                Sprinkler_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Sprinkler_selector_cases' from Copy factor
            Sprinkler_selector_cases_B[0] = Factor.Copy <Bernoulli>(Sprinkler_selector_cases_0_B);
            Bernoulli Rain_cond_Sprinkler_1_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Rain_cond_Sprinkler_1_selector_cases_0' from Random factor
            Rain_cond_Sprinkler_1_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli24));
            DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_1_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Rain_cond_Sprinkler_1_selector_cases' Backwards messages.
            Rain_cond_Sprinkler_1_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _ind0 = 0; _ind0 < 2; _ind0++)
            {
                Rain_cond_Sprinkler_1_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor
            Rain_cond_Sprinkler_1_selector_cases_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_cases_0_B);
            // The constant 'vBernoulli26'
            Bernoulli vBernoulli26 = Bernoulli.FromLogOdds(-2.4423470353692043);
            Bernoulli Rain_cond_Sprinkler_1_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Rain_cond_Sprinkler_1_selector_cases_1' from Random factor
            Rain_cond_Sprinkler_1_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli26));
            // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor
            Rain_cond_Sprinkler_1_selector_cases_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_cases_1_B);
            Bernoulli[] Sprinkler_selector_cases_1_uses_B = default(Bernoulli[]);
            // Create array for 'Sprinkler_selector_cases_1_uses' Backwards messages.
            Sprinkler_selector_cases_1_uses_B = new Bernoulli[5];
            for (int _ind = 0; _ind < 5; _ind++)
            {
                Sprinkler_selector_cases_1_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Sprinkler_selector_cases_1_uses' from Cases factor
            Sprinkler_selector_cases_1_uses_B[4] = Bernoulli.FromLogOdds(CasesOp.LogEvidenceRatio(Rain_cond_Sprinkler_1_selector_cases_B, Rain_use_F));
            Bernoulli Sprinkler_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Sprinkler_selector_cases_1' from Replicate factor
            Sprinkler_selector_cases_1_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_cases_1_uses_B, Sprinkler_selector_cases_1_B);
            // Message to 'Sprinkler_selector_cases' from Copy factor
            Sprinkler_selector_cases_B[1] = Factor.Copy <Bernoulli>(Sprinkler_selector_cases_1_B);
            Bernoulli[] Sprinkler_selector_uses_B = default(Bernoulli[]);
            // Create array for 'Sprinkler_selector_uses' Backwards messages.
            Sprinkler_selector_uses_B = new Bernoulli[2];
            // The constant 'vBernoulli19'
            Bernoulli vBernoulli19 = Bernoulli.FromLogOdds(-2.1972245773362191);

            for (int _ind = 0; _ind < 2; _ind++)
            {
                Sprinkler_selector_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli19);
            }
            // Message to 'Sprinkler_selector_uses' from Cases factor
            Sprinkler_selector_uses_B[0] = CasesOp.BAverageConditional(Sprinkler_selector_cases_B);
            Bernoulli Sprinkler_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli19);

            if (this.cloudy)
            {
                // Message to 'Sprinkler' from Copy factor
                Sprinkler_F = Factor.Copy <Bernoulli>(vBernoulli19);
            }
            if (!this.cloudy)
            {
                // Message to 'Sprinkler' from Copy factor
                Sprinkler_F = Factor.Copy <Bernoulli>(vBernoulli18);
            }
            // Sprinkler_F is now updated in all contexts
            // Message to use of 'Sprinkler'
            Bernoulli Sprinkler_use_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli19);

            if (this.cloudy)
            {
                // Message to 'Sprinkler_use' from DerivedVariable factor
                Sprinkler_use_F = Factor.Copy <Bernoulli>(Sprinkler_F);
            }
            if (!this.cloudy)
            {
                // Message to 'Sprinkler_use' from DerivedVariable factor
                Sprinkler_use_F = Factor.Copy <Bernoulli>(vBernoulli18);
            }
            // Sprinkler_use_F is now updated in all contexts
            // Buffer for Replicate2BufferOp.UsesAverageConditional<Bernoulli>
            Bernoulli Sprinkler_selector_uses_B_marginal = default(Bernoulli);

            // Message to 'Sprinkler_selector_uses' from Replicate factor
            Sprinkler_selector_uses_B_marginal = Replicate2BufferOp.MarginalInit <Bernoulli>(Sprinkler_use_F);
            // Message to 'Sprinkler_selector_uses' from Replicate factor
            Sprinkler_selector_uses_B_marginal = Replicate2BufferOp.Marginal <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_use_F, Sprinkler_selector_uses_B_marginal);
            Bernoulli[] Sprinkler_selector_uses_F = default(Bernoulli[]);
            // Create array for 'Sprinkler_selector_uses' Forwards messages.
            Sprinkler_selector_uses_F = new Bernoulli[2];
            for (int _ind = 0; _ind < 2; _ind++)
            {
                Sprinkler_selector_uses_F[_ind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli19);
            }
            // Message to 'Sprinkler_selector_uses' from Replicate factor
            Sprinkler_selector_uses_F[1] = Replicate2BufferOp.UsesAverageConditional <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_use_F, Sprinkler_selector_uses_B_marginal, 1, Sprinkler_selector_uses_F[1]);
            Bernoulli Rain_cond_Sprinkler_0_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli21);

            // Message to 'Rain_cond_Sprinkler_0_selector' from Cases factor
            Rain_cond_Sprinkler_0_selector_B = CasesOp.BAverageConditional(Rain_cond_Sprinkler_0_selector_cases_B);
            DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Rain_cond_Sprinkler' Backwards messages.
            Rain_cond_Sprinkler_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _gateind = 0; _gateind < 2; _gateind++)
            {
                Rain_cond_Sprinkler_B[_gateind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli21);
            }
            // Message to 'Rain_cond_Sprinkler' from Copy factor
            Rain_cond_Sprinkler_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_B);
            Bernoulli Rain_cond_Sprinkler_1_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli21);

            // Message to 'Rain_cond_Sprinkler_1_selector' from Cases factor
            Rain_cond_Sprinkler_1_selector_B = CasesOp.BAverageConditional(Rain_cond_Sprinkler_1_selector_cases_B);
            // Message to 'Rain_cond_Sprinkler' from Copy factor
            Rain_cond_Sprinkler_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_B);
            // Message to 'Rain_use' from EnterPartial factor
            Rain_use_B = GateEnterPartialOp <bool> .ValueAverageConditional <Bernoulli>(Rain_cond_Sprinkler_B, Sprinkler_selector_uses_F[1], Rain_use_F, new int[2] {
                0, 1
            }, Rain_use_B);

            if (this.cloudy)
            {
                // Message to 'Rain_marginal' from DerivedVariable factor
                this.Rain_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Rain_use_B, Rain_F, this.Rain_marginal_F);
            }
            if (!this.cloudy)
            {
                // Message to 'Rain_marginal' from DerivedVariable factor
                this.Rain_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Rain_use_B, vBernoulli22, this.Rain_marginal_F);
            }
            // Rain_marginal_F is now updated in all contexts
            this.Sprinkler_marginal_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli19);
            Bernoulli Sprinkler_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli19);

            // Message to 'Sprinkler_selector' from Replicate factor
            Sprinkler_selector_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_selector_B);
            if (this.cloudy)
            {
                // Message to 'Sprinkler_marginal' from DerivedVariable factor
                this.Sprinkler_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Sprinkler_selector_B, Sprinkler_F, this.Sprinkler_marginal_F);
            }
            if (!this.cloudy)
            {
                // Message to 'Sprinkler_marginal' from DerivedVariable factor
                this.Sprinkler_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Sprinkler_selector_B, vBernoulli18, this.Sprinkler_marginal_F);
            }
            // Sprinkler_marginal_F is now updated in all contexts
            this.Changed_Cloudy_WetGrass_iterationsDone = 1;
        }
Esempio n. 5
0
        /// <summary>Computations that depend on the observed value of numberOfIterationsDecreased and WetGrass</summary>
        /// <param name="numberOfIterations">The number of times to iterate each loop</param>
        public void Changed_numberOfIterationsDecreased_WetGrass(int numberOfIterations)
        {
            if (this.Changed_numberOfIterationsDecreased_WetGrass_iterationsDone == numberOfIterations)
            {
                return;
            }
            // The constant 'vBernoulli32'
            Bernoulli vBernoulli32 = Bernoulli.FromLogOdds(4.5951198501345889);

            this.WetGrass_marginal = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli32);
            this.WetGrass_marginal = Distribution.SetPoint <Bernoulli, bool>(this.WetGrass_marginal, this.wetGrass);
            Bernoulli Rain_F = ArrayHelper.MakeUniform <Bernoulli>(this.vBernoulli30);
            // The constant 'vBernoulli27'
            Bernoulli vBernoulli27 = Bernoulli.FromLogOdds(0);

            this.Cloudy_marginal_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli27);
            DistributionStructArray <Bernoulli, bool> Rain_cond_Cloudy_F = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Rain_cond_Cloudy' Forwards messages.
            Rain_cond_Cloudy_F = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _gateind = 0; _gateind < 2; _gateind++)
            {
                Rain_cond_Cloudy_F[_gateind] = ArrayHelper.MakeUniform <Bernoulli>(this.vBernoulli30);
            }
            // Message to 'Rain_cond_Cloudy' from Copy factor
            Rain_cond_Cloudy_F[0] = Factor.Copy <Bernoulli>(this.vBernoulli30);
            // The constant 'vBernoulli31'
            Bernoulli vBernoulli31 = Bernoulli.FromLogOdds(-1.3862943611198906);

            // Message to 'Rain_cond_Cloudy' from Copy factor
            Rain_cond_Cloudy_F[1] = Factor.Copy <Bernoulli>(vBernoulli31);
            DistributionStructArray <Bernoulli, bool> Cloudy_selector_cases_F = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Cloudy_selector_cases' Forwards messages.
            Cloudy_selector_cases_F = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _iv0 = 0; _iv0 < 2; _iv0++)
            {
                Cloudy_selector_cases_F[_iv0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Cloudy_selector_cases' from Cases factor
            Cloudy_selector_cases_F = CasesOp.CasesAverageConditional <DistributionStructArray <Bernoulli, bool> >(vBernoulli27, Cloudy_selector_cases_F);
            // The constant 'vBernoulli28'
            Bernoulli vBernoulli28 = Bernoulli.FromLogOdds(-2.1972245773362191);
            DistributionStructArray <Bernoulli, bool> Sprinkler_cond_Cloudy_F = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Sprinkler_cond_Cloudy' Forwards messages.
            Sprinkler_cond_Cloudy_F = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _gateind = 0; _gateind < 2; _gateind++)
            {
                Sprinkler_cond_Cloudy_F[_gateind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli28);
            }
            // Message to 'Sprinkler_cond_Cloudy' from Copy factor
            Sprinkler_cond_Cloudy_F[0] = Factor.Copy <Bernoulli>(vBernoulli28);
            // Message to 'Sprinkler_cond_Cloudy' from Copy factor
            Sprinkler_cond_Cloudy_F[1] = Factor.Copy <Bernoulli>(vBernoulli27);
            Bernoulli Rain_cond_Sprinkler_0_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Rain_cond_Sprinkler_0_selector_cases_0' from Random factor
            Rain_cond_Sprinkler_0_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli32));
            DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_0_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Rain_cond_Sprinkler_0_selector_cases' Backwards messages.
            Rain_cond_Sprinkler_0_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _ind0 = 0; _ind0 < 2; _ind0++)
            {
                Rain_cond_Sprinkler_0_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor
            Rain_cond_Sprinkler_0_selector_cases_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_cases_0_B);
            // The constant 'vBernoulli33'
            Bernoulli vBernoulli33 = Bernoulli.FromLogOdds(2.1972245773362196);
            Bernoulli Rain_cond_Sprinkler_0_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Rain_cond_Sprinkler_0_selector_cases_1' from Random factor
            Rain_cond_Sprinkler_0_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli33));
            // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor
            Rain_cond_Sprinkler_0_selector_cases_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_cases_1_B);
            Bernoulli[] Sprinkler_selector_cases_0_uses_B = default(Bernoulli[]);
            // Create array for 'Sprinkler_selector_cases_0_uses' Backwards messages.
            Sprinkler_selector_cases_0_uses_B = new Bernoulli[5];
            for (int _ind = 0; _ind < 5; _ind++)
            {
                Sprinkler_selector_cases_0_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            Bernoulli Sprinkler_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            DistributionStructArray <Bernoulli, bool> Sprinkler_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Sprinkler_selector_cases' Backwards messages.
            Sprinkler_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _ind0 = 0; _ind0 < 2; _ind0++)
            {
                Sprinkler_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            Bernoulli Rain_cond_Sprinkler_1_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Rain_cond_Sprinkler_1_selector_cases_0' from Random factor
            Rain_cond_Sprinkler_1_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli33));
            DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_1_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Rain_cond_Sprinkler_1_selector_cases' Backwards messages.
            Rain_cond_Sprinkler_1_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _ind0 = 0; _ind0 < 2; _ind0++)
            {
                Rain_cond_Sprinkler_1_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor
            Rain_cond_Sprinkler_1_selector_cases_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_cases_0_B);
            // The constant 'vBernoulli35'
            Bernoulli vBernoulli35 = Bernoulli.FromLogOdds(Double.NegativeInfinity);
            Bernoulli Rain_cond_Sprinkler_1_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Rain_cond_Sprinkler_1_selector_cases_1' from Random factor
            Rain_cond_Sprinkler_1_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli35));
            // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor
            Rain_cond_Sprinkler_1_selector_cases_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_cases_1_B);
            Bernoulli[] Sprinkler_selector_cases_1_uses_B = default(Bernoulli[]);
            // Create array for 'Sprinkler_selector_cases_1_uses' Backwards messages.
            Sprinkler_selector_cases_1_uses_B = new Bernoulli[5];
            for (int _ind = 0; _ind < 5; _ind++)
            {
                Sprinkler_selector_cases_1_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            Bernoulli Sprinkler_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            Bernoulli[] Sprinkler_selector_uses_B = default(Bernoulli[]);
            // Create array for 'Sprinkler_selector_uses' Backwards messages.
            Sprinkler_selector_uses_B = new Bernoulli[2];
            for (int _ind = 0; _ind < 2; _ind++)
            {
                Sprinkler_selector_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli28);
            }
            Bernoulli Sprinkler_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli28);
            // Buffer for Replicate2BufferOp.UsesAverageConditional<DistributionStructArray<Bernoulli,bool>>
            DistributionStructArray <Bernoulli, bool> Cloudy_selector_cases_uses_B_marginal = default(DistributionStructArray <Bernoulli, bool>);

            // Message to 'Cloudy_selector_cases_uses' from Replicate factor
            Cloudy_selector_cases_uses_B_marginal = Replicate2BufferOp.MarginalInit <DistributionStructArray <Bernoulli, bool> >(Cloudy_selector_cases_F);
            DistributionStructArray <Bernoulli, bool>[] Cloudy_selector_cases_uses_F = default(DistributionStructArray <Bernoulli, bool>[]);
            // Create array for 'Cloudy_selector_cases_uses' Forwards messages.
            Cloudy_selector_cases_uses_F = new DistributionStructArray <Bernoulli, bool> [4];
            for (int _ind = 0; _ind < 4; _ind++)
            {
                // Create array for 'Cloudy_selector_cases_uses' Forwards messages.
                Cloudy_selector_cases_uses_F[_ind] = new DistributionStructArray <Bernoulli, bool>(2);
                for (int _iv0 = 0; _iv0 < 2; _iv0++)
                {
                    Cloudy_selector_cases_uses_F[_ind][_iv0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
                }
            }
            Bernoulli Sprinkler_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli28);
            // Buffer for Replicate2BufferOp.UsesAverageConditional<Bernoulli>
            Bernoulli Sprinkler_selector_uses_B_marginal = default(Bernoulli);

            // Message to 'Sprinkler_selector_uses' from Replicate factor
            Sprinkler_selector_uses_B_marginal = Replicate2BufferOp.MarginalInit <Bernoulli>(Sprinkler_F);
            Bernoulli[] Sprinkler_selector_uses_F = default(Bernoulli[]);
            // Create array for 'Sprinkler_selector_uses' Forwards messages.
            Sprinkler_selector_uses_F = new Bernoulli[2];
            for (int _ind = 0; _ind < 2; _ind++)
            {
                Sprinkler_selector_uses_F[_ind] = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli28);
            }
            Bernoulli Rain_cond_Sprinkler_0_selector_B = ArrayHelper.MakeUniform <Bernoulli>(this.vBernoulli30);

            // Message to 'Rain_cond_Sprinkler_0_selector' from Cases factor
            Rain_cond_Sprinkler_0_selector_B = CasesOp.BAverageConditional(Rain_cond_Sprinkler_0_selector_cases_B);
            DistributionStructArray <Bernoulli, bool> Rain_cond_Sprinkler_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Rain_cond_Sprinkler' Backwards messages.
            Rain_cond_Sprinkler_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _gateind = 0; _gateind < 2; _gateind++)
            {
                Rain_cond_Sprinkler_B[_gateind] = ArrayHelper.MakeUniform <Bernoulli>(this.vBernoulli30);
            }
            // Message to 'Rain_cond_Sprinkler' from Copy factor
            Rain_cond_Sprinkler_B[0] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_0_selector_B);
            Bernoulli Rain_cond_Sprinkler_1_selector_B = ArrayHelper.MakeUniform <Bernoulli>(this.vBernoulli30);

            // Message to 'Rain_cond_Sprinkler_1_selector' from Cases factor
            Rain_cond_Sprinkler_1_selector_B = CasesOp.BAverageConditional(Rain_cond_Sprinkler_1_selector_cases_B);
            // Message to 'Rain_cond_Sprinkler' from Copy factor
            Rain_cond_Sprinkler_B[1] = Factor.Copy <Bernoulli>(Rain_cond_Sprinkler_1_selector_B);
            for (int iteration = this.Changed_numberOfIterationsDecreased_WetGrass_iterationsDone; iteration < numberOfIterations; iteration++)
            {
                // Message to 'Cloudy_selector_cases_uses' from Replicate factor
                Cloudy_selector_cases_uses_B_marginal = Replicate2BufferOp.Marginal <DistributionStructArray <Bernoulli, bool> >(this.Cloudy_selector_cases_uses_B, Cloudy_selector_cases_F, Cloudy_selector_cases_uses_B_marginal);
                // Message to 'Cloudy_selector_cases_uses' from Replicate factor
                Cloudy_selector_cases_uses_F[1] = Replicate2BufferOp.UsesAverageConditional <DistributionStructArray <Bernoulli, bool> >(this.Cloudy_selector_cases_uses_B, Cloudy_selector_cases_F, Cloudy_selector_cases_uses_B_marginal, 1, Cloudy_selector_cases_uses_F[1]);
                // Message to 'Rain' from Exit factor
                Rain_F = GateExitOp <bool> .ExitAverageConditional <Bernoulli>(this.Rain_use_B, Cloudy_selector_cases_uses_F[1], Rain_cond_Cloudy_F, Rain_F);

                // Message to 'Sprinkler_selector_cases_1_uses' from Cases factor
                Sprinkler_selector_cases_1_uses_B[4] = Bernoulli.FromLogOdds(CasesOp.LogEvidenceRatio(Rain_cond_Sprinkler_1_selector_cases_B, Rain_F));
                // Message to 'Sprinkler_selector_cases_1' from Replicate factor
                Sprinkler_selector_cases_1_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_cases_1_uses_B, Sprinkler_selector_cases_1_B);
                // Message to 'Sprinkler_selector_cases' from Copy factor
                Sprinkler_selector_cases_B[1] = Factor.Copy <Bernoulli>(Sprinkler_selector_cases_1_B);
                // Message to 'Sprinkler_selector_cases_0_uses' from Cases factor
                Sprinkler_selector_cases_0_uses_B[4] = Bernoulli.FromLogOdds(CasesOp.LogEvidenceRatio(Rain_cond_Sprinkler_0_selector_cases_B, Rain_F));
                // Message to 'Sprinkler_selector_cases_0' from Replicate factor
                Sprinkler_selector_cases_0_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_cases_0_uses_B, Sprinkler_selector_cases_0_B);
                // Message to 'Sprinkler_selector_cases' from Copy factor
                Sprinkler_selector_cases_B[0] = Factor.Copy <Bernoulli>(Sprinkler_selector_cases_0_B);
                // Message to 'Sprinkler_selector_uses' from Cases factor
                Sprinkler_selector_uses_B[0] = CasesOp.BAverageConditional(Sprinkler_selector_cases_B);
                // Message to 'Sprinkler_selector' from Replicate factor
                Sprinkler_selector_B = ReplicateOp.DefAverageConditional <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_selector_B);
                // Message to 'Cloudy_selector_cases_uses' from Exit factor
                this.Cloudy_selector_cases_uses_B[3] = GateExitOp <bool> .CasesAverageConditional <Bernoulli, DistributionStructArray <Bernoulli, bool> >(Sprinkler_selector_B, Sprinkler_cond_Cloudy_F, this.Cloudy_selector_cases_uses_B[3]);

                // Message to 'Cloudy_selector_cases_uses' from Replicate factor
                Cloudy_selector_cases_uses_B_marginal = Replicate2BufferOp.Marginal <DistributionStructArray <Bernoulli, bool> >(this.Cloudy_selector_cases_uses_B, Cloudy_selector_cases_F, Cloudy_selector_cases_uses_B_marginal);
                // Message to 'Cloudy_selector_cases_uses' from Replicate factor
                Cloudy_selector_cases_uses_F[3] = Replicate2BufferOp.UsesAverageConditional <DistributionStructArray <Bernoulli, bool> >(this.Cloudy_selector_cases_uses_B, Cloudy_selector_cases_F, Cloudy_selector_cases_uses_B_marginal, 3, Cloudy_selector_cases_uses_F[3]);
                // Message to 'Sprinkler' from Exit factor
                Sprinkler_F = GateExitOp <bool> .ExitAverageConditional <Bernoulli>(Sprinkler_selector_B, Cloudy_selector_cases_uses_F[3], Sprinkler_cond_Cloudy_F, Sprinkler_F);

                // Message to 'Sprinkler_selector_uses' from Replicate factor
                Sprinkler_selector_uses_B_marginal = Replicate2BufferOp.Marginal <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_F, Sprinkler_selector_uses_B_marginal);
                // Message to 'Sprinkler_selector_uses' from Replicate factor
                Sprinkler_selector_uses_F[1] = Replicate2BufferOp.UsesAverageConditional <Bernoulli>(Sprinkler_selector_uses_B, Sprinkler_F, Sprinkler_selector_uses_B_marginal, 1, Sprinkler_selector_uses_F[1]);
                // Message to 'Rain_use' from EnterPartial factor
                this.Rain_use_B = GateEnterPartialOp <bool> .ValueAverageConditional <Bernoulli>(Rain_cond_Sprinkler_B, Sprinkler_selector_uses_F[1], Rain_F, new int[2] {
                    0, 1
                }, this.Rain_use_B);

                // Message to 'Cloudy_selector_cases_uses' from Exit factor
                this.Cloudy_selector_cases_uses_B[1] = GateExitOp <bool> .CasesAverageConditional <Bernoulli, DistributionStructArray <Bernoulli, bool> >(this.Rain_use_B, Rain_cond_Cloudy_F, this.Cloudy_selector_cases_uses_B[1]);

                this.OnProgressChanged(new ProgressChangedEventArgs(iteration));
            }
            DistributionStructArray <Bernoulli, bool> Cloudy_selector_cases_B = default(DistributionStructArray <Bernoulli, bool>);

            // Create array for 'Cloudy_selector_cases' Backwards messages.
            Cloudy_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
            for (int _iv0 = 0; _iv0 < 2; _iv0++)
            {
                Cloudy_selector_cases_B[_iv0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Cloudy_selector_cases' from Replicate factor
            Cloudy_selector_cases_B = ReplicateOp.DefAverageConditional <DistributionStructArray <Bernoulli, bool> >(this.Cloudy_selector_cases_uses_B, Cloudy_selector_cases_B);
            Bernoulli Cloudy_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli27);

            // Message to 'Cloudy_selector' from Cases factor
            Cloudy_selector_B = CasesOp.BAverageConditional(Cloudy_selector_cases_B);
            // Message to 'Cloudy_marginal' from Variable factor
            this.Cloudy_marginal_F = VariableOp.MarginalAverageConditional <Bernoulli>(Cloudy_selector_B, vBernoulli27, this.Cloudy_marginal_F);
            this.Rain_marginal_F   = ArrayHelper.MakeUniform <Bernoulli>(this.vBernoulli30);
            // Message to 'Rain_marginal' from DerivedVariable factor
            this.Rain_marginal_F      = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(this.Rain_use_B, Rain_F, this.Rain_marginal_F);
            this.Sprinkler_marginal_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli28);
            // Message to 'Sprinkler_marginal' from DerivedVariable factor
            this.Sprinkler_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Sprinkler_selector_B, Sprinkler_F, this.Sprinkler_marginal_F);
            this.Changed_numberOfIterationsDecreased_WetGrass_iterationsDone = numberOfIterations;
        }