/// <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));
            }
            for (int InstanceRange = 0; InstanceRange < this.instanceCount; InstanceRange++)
            {
                this.Weights_FeatureIndexes_B[InstanceRange] = ArrayHelper.SetTo <DistributionStructArray <Gaussian, double> >(this.Weights_FeatureIndexes_B[InstanceRange], this.IndexedWeights_B[InstanceRange]);
            }
            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.Weights_FeatureIndexes_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>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;
 }
Example #3
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;
        }
Example #4
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;
        }
Example #5
0
        /// <summary>Computations that depend on the observed value of Cloudy and WetGrass and Sprinkler</summary>
        public void Changed_Cloudy_WetGrass_Sprinkler()
        {
            if (this.Changed_Cloudy_WetGrass_Sprinkler_iterationsDone == 1)
            {
                return;
            }
            // The constant 'vBernoulli0'
            Bernoulli vBernoulli0 = Bernoulli.FromLogOdds(0);

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

            this.WetGrass_marginal = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli5);
            this.WetGrass_marginal = Distribution.SetPoint <Bernoulli, bool>(this.WetGrass_marginal, this.wetGrass);
            // The constant 'vBernoulli1'
            Bernoulli vBernoulli1 = Bernoulli.FromLogOdds(-2.1972245773362191);

            this.Sprinkler_marginal = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli1);
            this.Sprinkler_marginal = Distribution.SetPoint <Bernoulli, bool>(this.Sprinkler_marginal, this.sprinkler);
            // The constant 'vBernoulli3'
            Bernoulli vBernoulli3 = Bernoulli.FromLogOdds(1.3862943611198908);
            Bernoulli Rain_F      = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli3);

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

            if (this.cloudy)
            {
                // Message to 'Rain' from Copy factor
                Rain_F = Factor.Copy <Bernoulli>(vBernoulli3);
            }
            // The constant 'vBernoulli4'
            Bernoulli vBernoulli4 = Bernoulli.FromLogOdds(-1.3862943611198906);

            if (!this.cloudy)
            {
                // Message to 'Rain' from Copy factor
                Rain_F = Factor.Copy <Bernoulli>(vBernoulli4);
            }
            // Rain_F is now updated in all contexts
            if (this.sprinkler)
            {
                this.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
                this.Rain_cond_Sprinkler_0_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli5));
                // Create array for 'Rain_cond_Sprinkler_0_selector_cases' Backwards messages.
                this.Rain_cond_Sprinkler_0_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
                for (int _ind0 = 0; _ind0 < 2; _ind0++)
                {
                    this.Rain_cond_Sprinkler_0_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
                }
                // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor
                this.Rain_cond_Sprinkler_0_selector_cases_B[0] = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_0_selector_cases_0_B);
            }
            // The constant 'vBernoulli6'
            Bernoulli vBernoulli6 = Bernoulli.FromLogOdds(2.1972245773362196);

            if (this.sprinkler)
            {
                this.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
                this.Rain_cond_Sprinkler_0_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli6));
                // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor
                this.Rain_cond_Sprinkler_0_selector_cases_B[1] = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_0_selector_cases_1_B);
                this.Rain_cond_Sprinkler_0_selector_B          = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli3);
                // Message to 'Rain_cond_Sprinkler_0_selector' from Cases factor
                this.Rain_cond_Sprinkler_0_selector_B = CasesOp.BAverageConditional(this.Rain_cond_Sprinkler_0_selector_cases_B);
                // Message to 'Rain_use' from Copy factor
                Rain_use_B = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_0_selector_B);
            }
            if (!this.sprinkler)
            {
                this.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
                this.Rain_cond_Sprinkler_1_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli6));
                // Create array for 'Rain_cond_Sprinkler_1_selector_cases' Backwards messages.
                this.Rain_cond_Sprinkler_1_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
                for (int _ind0 = 0; _ind0 < 2; _ind0++)
                {
                    this.Rain_cond_Sprinkler_1_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
                }
                // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor
                this.Rain_cond_Sprinkler_1_selector_cases_B[0] = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_1_selector_cases_0_B);
            }
            // The constant 'vBernoulli8'
            Bernoulli vBernoulli8 = Bernoulli.FromLogOdds(Double.NegativeInfinity);

            if (!this.sprinkler)
            {
                this.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
                this.Rain_cond_Sprinkler_1_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli8));
                // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor
                this.Rain_cond_Sprinkler_1_selector_cases_B[1] = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_1_selector_cases_1_B);
                this.Rain_cond_Sprinkler_1_selector_B          = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli3);
                // Message to 'Rain_cond_Sprinkler_1_selector' from Cases factor
                this.Rain_cond_Sprinkler_1_selector_B = CasesOp.BAverageConditional(this.Rain_cond_Sprinkler_1_selector_cases_B);
                // Message to 'Rain_use' from Copy factor
                Rain_use_B = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_1_selector_B);
            }
            // Rain_use_B is now updated in all contexts
            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, vBernoulli4, this.Rain_marginal_F);
            }
            // Rain_marginal_F is now updated in all contexts
            this.Changed_Cloudy_WetGrass_Sprinkler_iterationsDone = 1;
        }
Example #6
0
        /// <summary>Computations that depend on the observed value of Sprinkler and WetGrass</summary>
        public void Changed_Sprinkler_WetGrass()
        {
            if (this.Changed_Sprinkler_WetGrass_iterationsDone == 1)
            {
                return;
            }
            // The constant 'vBernoulli1'
            Bernoulli vBernoulli1 = Bernoulli.FromLogOdds(-2.1972245773362191);

            this.Sprinkler_marginal = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli1);
            this.Sprinkler_marginal = Distribution.SetPoint <Bernoulli, bool>(this.Sprinkler_marginal, this.sprinkler);
            // The constant 'vBernoulli5'
            Bernoulli vBernoulli5 = Bernoulli.FromLogOdds(4.5951198501345889);

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

            this.Cloudy_marginal_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli0);
            Bernoulli[] Cloudy_selector_cases_0_uses_B = default(Bernoulli[]);
            // Create array for 'Cloudy_selector_cases_0_uses' Backwards messages.
            Cloudy_selector_cases_0_uses_B = new Bernoulli[7];
            for (int _ind = 0; _ind < 7; _ind++)
            {
                Cloudy_selector_cases_0_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Cloudy_selector_cases_0_uses' from Random factor
            Cloudy_selector_cases_0_uses_B[6] = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.sprinkler, vBernoulli1));
            Bernoulli Cloudy_selector_cases_0_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Cloudy_selector_cases_0' from Replicate factor
            Cloudy_selector_cases_0_B = ReplicateOp.DefAverageConditional <Bernoulli>(Cloudy_selector_cases_0_uses_B, Cloudy_selector_cases_0_B);
            DistributionStructArray <Bernoulli, bool>[] Cloudy_selector_cases_uses_B = default(DistributionStructArray <Bernoulli, bool>[]);
            // Create array for 'Cloudy_selector_cases_uses' Backwards messages.
            Cloudy_selector_cases_uses_B = new DistributionStructArray <Bernoulli, bool> [3];
            for (int _ind = 0; _ind < 3; _ind++)
            {
                // Create array for 'Cloudy_selector_cases_uses' Backwards messages.
                Cloudy_selector_cases_uses_B[_ind] = new DistributionStructArray <Bernoulli, bool>(2);
                for (int _iv0 = 0; _iv0 < 2; _iv0++)
                {
                    Cloudy_selector_cases_uses_B[_ind][_iv0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
                }
            }
            // Message to 'Cloudy_selector_cases_uses' from Copy factor
            Cloudy_selector_cases_uses_B[0][0] = Factor.Copy <Bernoulli>(Cloudy_selector_cases_0_B);
            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>(vBernoulli3);
            }
            // Message to 'Rain_cond_Cloudy' from Copy factor
            Rain_cond_Cloudy_F[0] = Factor.Copy <Bernoulli>(vBernoulli3);
            // The constant 'vBernoulli4'
            Bernoulli vBernoulli4 = Bernoulli.FromLogOdds(-1.3862943611198906);

            // Message to 'Rain_cond_Cloudy' from Copy factor
            Rain_cond_Cloudy_F[1] = Factor.Copy <Bernoulli>(vBernoulli4);
            if (this.sprinkler)
            {
                this.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
                this.Rain_cond_Sprinkler_0_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli5));
                // Create array for 'Rain_cond_Sprinkler_0_selector_cases' Backwards messages.
                this.Rain_cond_Sprinkler_0_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
                for (int _ind0 = 0; _ind0 < 2; _ind0++)
                {
                    this.Rain_cond_Sprinkler_0_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
                }
                // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor
                this.Rain_cond_Sprinkler_0_selector_cases_B[0] = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_0_selector_cases_0_B);
            }
            // The constant 'vBernoulli6'
            Bernoulli vBernoulli6 = Bernoulli.FromLogOdds(2.1972245773362196);

            if (this.sprinkler)
            {
                this.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
                this.Rain_cond_Sprinkler_0_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli6));
                // Message to 'Rain_cond_Sprinkler_0_selector_cases' from Copy factor
                this.Rain_cond_Sprinkler_0_selector_cases_B[1] = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_0_selector_cases_1_B);
                this.Rain_cond_Sprinkler_0_selector_B          = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli3);
                // Message to 'Rain_cond_Sprinkler_0_selector' from Cases factor
                this.Rain_cond_Sprinkler_0_selector_B = CasesOp.BAverageConditional(this.Rain_cond_Sprinkler_0_selector_cases_B);
            }
            // Message from use of 'Rain'
            Bernoulli Rain_use_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli3);

            if (this.sprinkler)
            {
                // Message to 'Rain_use' from Copy factor
                Rain_use_B = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_0_selector_B);
            }
            if (!this.sprinkler)
            {
                this.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
                this.Rain_cond_Sprinkler_1_selector_cases_0_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli6));
                // Create array for 'Rain_cond_Sprinkler_1_selector_cases' Backwards messages.
                this.Rain_cond_Sprinkler_1_selector_cases_B = new DistributionStructArray <Bernoulli, bool>(2);
                for (int _ind0 = 0; _ind0 < 2; _ind0++)
                {
                    this.Rain_cond_Sprinkler_1_selector_cases_B[_ind0] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
                }
                // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor
                this.Rain_cond_Sprinkler_1_selector_cases_B[0] = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_1_selector_cases_0_B);
            }
            // The constant 'vBernoulli8'
            Bernoulli vBernoulli8 = Bernoulli.FromLogOdds(Double.NegativeInfinity);

            if (!this.sprinkler)
            {
                this.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
                this.Rain_cond_Sprinkler_1_selector_cases_1_B = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.wetGrass, vBernoulli8));
                // Message to 'Rain_cond_Sprinkler_1_selector_cases' from Copy factor
                this.Rain_cond_Sprinkler_1_selector_cases_B[1] = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_1_selector_cases_1_B);
                this.Rain_cond_Sprinkler_1_selector_B          = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli3);
                // Message to 'Rain_cond_Sprinkler_1_selector' from Cases factor
                this.Rain_cond_Sprinkler_1_selector_B = CasesOp.BAverageConditional(this.Rain_cond_Sprinkler_1_selector_cases_B);
                // Message to 'Rain_use' from Copy factor
                Rain_use_B = Factor.Copy <Bernoulli>(this.Rain_cond_Sprinkler_1_selector_B);
            }
            // Rain_use_B is now updated in all contexts
            // Message to 'Cloudy_selector_cases_uses' from Exit factor
            Cloudy_selector_cases_uses_B[1] = GateExitOp <bool> .CasesAverageConditional <Bernoulli, DistributionStructArray <Bernoulli, bool> >(Rain_use_B, Rain_cond_Cloudy_F, Cloudy_selector_cases_uses_B[1]);

            Bernoulli[] Cloudy_selector_cases_1_uses_B = default(Bernoulli[]);
            // Create array for 'Cloudy_selector_cases_1_uses' Backwards messages.
            Cloudy_selector_cases_1_uses_B = new Bernoulli[7];
            for (int _ind = 0; _ind < 7; _ind++)
            {
                Cloudy_selector_cases_1_uses_B[_ind] = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());
            }
            // Message to 'Cloudy_selector_cases_1_uses' from Random factor
            Cloudy_selector_cases_1_uses_B[6] = Bernoulli.FromLogOdds(UnaryOp <bool> .LogEvidenceRatio <Bernoulli>(this.sprinkler, vBernoulli0));
            Bernoulli Cloudy_selector_cases_1_B = ArrayHelper.MakeUniform <Bernoulli>(new Bernoulli());

            // Message to 'Cloudy_selector_cases_1' from Replicate factor
            Cloudy_selector_cases_1_B = ReplicateOp.DefAverageConditional <Bernoulli>(Cloudy_selector_cases_1_uses_B, Cloudy_selector_cases_1_B);
            // Message to 'Cloudy_selector_cases_uses' from Copy factor
            Cloudy_selector_cases_uses_B[2][1] = Factor.Copy <Bernoulli>(Cloudy_selector_cases_1_B);
            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> >(Cloudy_selector_cases_uses_B, Cloudy_selector_cases_B);
            Bernoulli Cloudy_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli0);

            // 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, vBernoulli0, this.Cloudy_marginal_F);
            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());
            }
            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> [3];
            for (int _ind = 0; _ind < 3; _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());
                }
            }
            // Message to 'Cloudy_selector_cases' from Cases factor
            Cloudy_selector_cases_F = CasesOp.CasesAverageConditional <DistributionStructArray <Bernoulli, bool> >(vBernoulli0, Cloudy_selector_cases_F);
            // 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);
            // Message to 'Cloudy_selector_cases_uses' from Replicate factor
            Cloudy_selector_cases_uses_B_marginal = Replicate2BufferOp.Marginal <DistributionStructArray <Bernoulli, bool> >(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> >(Cloudy_selector_cases_uses_B, Cloudy_selector_cases_F, Cloudy_selector_cases_uses_B_marginal, 1, Cloudy_selector_cases_uses_F[1]);
            this.Rain_marginal_F            = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli3);
            // Message to 'Rain' from Exit factor
            Rain_F = GateExitOp <bool> .ExitAverageConditional <Bernoulli>(Rain_use_B, Cloudy_selector_cases_uses_F[1], Rain_cond_Cloudy_F, Rain_F);

            // Message to 'Rain_marginal' from DerivedVariable factor
            this.Rain_marginal_F = DerivedVariableOp.MarginalAverageConditional <Bernoulli>(Rain_use_B, Rain_F, this.Rain_marginal_F);
            this.Changed_Sprinkler_WetGrass_iterationsDone = 1;
        }