Exemplo n.º 1
0
        /// <summary>Computations that depend on the observed value of vVector__41</summary>
        private void Changed_vVector__41()
        {
            if (this.Changed_vVector__41_iterationsDone == 1)
            {
                return;
            }
            this.vVector__41_marginal = new PointMass <Vector[]>(this.VVector__41);
            // The constant 'vVectorGaussian41'
            VectorGaussian vVectorGaussian41 = VectorGaussian.FromNatural(DenseVector.FromArray(new double[3] {
                1547829870.0, 525077980.0, 200270.0
            }), new PositiveDefiniteMatrix(new double[3, 3] {
                { 4254590363351.0, 1127383488860.0, 433199230.0 }, { 1127383488860.0, 482723521821.0, 146764360.0 }, { 433199230.0, 146764360.0, 56221.0 }
            }));

            this.vVector123_marginal_F = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian41);
            // Buffer for ReplicateOp_Divide.Marginal<VectorGaussian>
            VectorGaussian vVector123_rep_B_toDef = default(VectorGaussian);

            // Message to 'vVector123_rep' from Replicate factor
            vVector123_rep_B_toDef = ReplicateOp_Divide.ToDefInit <VectorGaussian>(vVectorGaussian41);
            // Message to 'vVector123_marginal' from Variable factor
            this.vVector123_marginal_F = VariableOp.MarginalAverageConditional <VectorGaussian>(vVector123_rep_B_toDef, vVectorGaussian41, this.vVector123_marginal_F);
            DistributionStructArray <Gaussian, double> vdouble__123_F = default(DistributionStructArray <Gaussian, double>);

            // Create array for 'vdouble__123' Forwards messages.
            vdouble__123_F = new DistributionStructArray <Gaussian, double>(1);
            for (int index41 = 0; index41 < 1; index41++)
            {
                vdouble__123_F[index41] = Gaussian.Uniform();
            }
            DistributionStructArray <Gaussian, double> vdouble__124_F = default(DistributionStructArray <Gaussian, double>);

            // Create array for 'vdouble__124' Forwards messages.
            vdouble__124_F = new DistributionStructArray <Gaussian, double>(1);
            for (int index41 = 0; index41 < 1; index41++)
            {
                vdouble__124_F[index41] = Gaussian.Uniform();
            }
            DistributionRefArray <VectorGaussian, Vector> vVector123_rep_F = default(DistributionRefArray <VectorGaussian, Vector>);
            DistributionRefArray <VectorGaussian, Vector> vVector123_rep_B = default(DistributionRefArray <VectorGaussian, Vector>);

            // Create array for 'vVector123_rep' Forwards messages.
            vVector123_rep_F = new DistributionRefArray <VectorGaussian, Vector>(1);
            // Create array for 'vVector123_rep' Backwards messages.
            vVector123_rep_B = new DistributionRefArray <VectorGaussian, Vector>(1);
            for (int index41 = 0; index41 < 1; index41++)
            {
                vVector123_rep_B[index41] = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian41);
                vVector123_rep_F[index41] = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian41);
            }
            // Buffer for ReplicateOp_Divide.UsesAverageConditional<VectorGaussian>
            VectorGaussian vVector123_rep_F_marginal = default(VectorGaussian);

            // Message to 'vVector123_rep' from Replicate factor
            vVector123_rep_F_marginal = ReplicateOp_Divide.MarginalInit <VectorGaussian>(vVectorGaussian41);
            // Message to 'vVector123_rep' from Replicate factor
            vVector123_rep_F_marginal = ReplicateOp_Divide.Marginal <VectorGaussian>(vVector123_rep_B_toDef, vVectorGaussian41, vVector123_rep_F_marginal);
            // Buffer for InnerProductOp.InnerProductAverageConditional
            // Create array for replicates of 'vVector123_rep_F_index41__AMean'
            Vector[] vVector123_rep_F_index41__AMean = new Vector[1];
            for (int index41 = 0; index41 < 1; index41++)
            {
                // Message to 'vdouble__124' from InnerProduct factor
                vVector123_rep_F_index41__AMean[index41] = InnerProductOp.AMeanInit(vVector123_rep_F[index41]);
            }
            // Buffer for InnerProductOp.AMean
            // Create array for replicates of 'vVector123_rep_F_index41__AVariance'
            PositiveDefiniteMatrix[] vVector123_rep_F_index41__AVariance = new PositiveDefiniteMatrix[1];
            for (int index41 = 0; index41 < 1; index41++)
            {
                // Message to 'vdouble__124' from InnerProduct factor
                vVector123_rep_F_index41__AVariance[index41] = InnerProductOp.AVarianceInit(vVector123_rep_F[index41]);
                // Message to 'vVector123_rep' from Replicate factor
                vVector123_rep_F[index41] = ReplicateOp_Divide.UsesAverageConditional <VectorGaussian>(vVector123_rep_B[index41], vVector123_rep_F_marginal, index41, vVector123_rep_F[index41]);
            }
            // Create array for 'vdouble__124_marginal' Forwards messages.
            this.vdouble__124_marginal_F = new DistributionStructArray <Gaussian, double>(1);
            for (int index41 = 0; index41 < 1; index41++)
            {
                this.vdouble__124_marginal_F[index41] = Gaussian.Uniform();
            }
            // Message from use of 'vdouble__124'
            DistributionStructArray <Gaussian, double> vdouble__124_use_B = default(DistributionStructArray <Gaussian, double>);

            // Create array for 'vdouble__124_use' Backwards messages.
            vdouble__124_use_B = new DistributionStructArray <Gaussian, double>(1);
            for (int index41 = 0; index41 < 1; index41++)
            {
                vdouble__124_use_B[index41] = Gaussian.Uniform();
                // Message to 'vdouble__124' from InnerProduct factor
                vVector123_rep_F_index41__AVariance[index41] = InnerProductOp.AVariance(vVector123_rep_F[index41], vVector123_rep_F_index41__AVariance[index41]);
                // Message to 'vdouble__124' from InnerProduct factor
                vVector123_rep_F_index41__AMean[index41] = InnerProductOp.AMean(vVector123_rep_F[index41], vVector123_rep_F_index41__AVariance[index41], vVector123_rep_F_index41__AMean[index41]);
                // Message to 'vdouble__124' from InnerProduct factor
                vdouble__124_F[index41] = InnerProductOp.InnerProductAverageConditional(vVector123_rep_F_index41__AMean[index41], vVector123_rep_F_index41__AVariance[index41], this.VVector__41[index41]);
                // Message to 'vdouble__124_marginal' from DerivedVariable factor
                this.vdouble__124_marginal_F[index41] = DerivedVariableOp.MarginalAverageConditional <Gaussian>(vdouble__124_use_B[index41], vdouble__124_F[index41], this.vdouble__124_marginal_F[index41]);
            }
            // Create array for 'vdouble__123_marginal' Forwards messages.
            this.vdouble__123_marginal_F = new DistributionStructArray <Gaussian, double>(1);
            for (int index41 = 0; index41 < 1; index41++)
            {
                this.vdouble__123_marginal_F[index41] = Gaussian.Uniform();
            }
            // Message from use of 'vdouble__123'
            DistributionStructArray <Gaussian, double> vdouble__123_use_B = default(DistributionStructArray <Gaussian, double>);

            // Create array for 'vdouble__123_use' Backwards messages.
            vdouble__123_use_B = new DistributionStructArray <Gaussian, double>(1);
            for (int index41 = 0; index41 < 1; index41++)
            {
                vdouble__123_use_B[index41] = Gaussian.Uniform();
                // Message to 'vdouble__123' from GaussianFromMeanAndVariance factor
                vdouble__123_F[index41] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(vdouble__124_F[index41], 0.1);
                // Message to 'vdouble__123_marginal' from Variable factor
                this.vdouble__123_marginal_F[index41] = VariableOp.MarginalAverageConditional <Gaussian>(vdouble__123_use_B[index41], vdouble__123_F[index41], this.vdouble__123_marginal_F[index41]);
            }
            this.Changed_vVector__41_iterationsDone = 1;
        }
Exemplo n.º 2
0
        /// <summary>Computations that depend on the observed value of vVector__126 and vdouble__378</summary>
        private void Changed_vVector__126_vdouble__378()
        {
            if (this.Changed_vVector__126_vdouble__378_iterationsDone == 1)
            {
                return;
            }
            this.vVector__126_marginal = new PointMass <Vector[]>(this.VVector__126);
            this.vdouble__378_marginal = new DistributionStructArray <Gaussian, double>(5622, delegate(int index126) {
                return(Gaussian.Uniform());
            });
            this.vdouble__378_marginal = Distribution.SetPoint <DistributionStructArray <Gaussian, double>, double[]>(this.vdouble__378_marginal, this.Vdouble__378);
            // The constant 'vVectorGaussian126'
            VectorGaussian vVectorGaussian126 = VectorGaussian.FromNatural(DenseVector.FromArray(new double[3] {
                0.0, 0.0, 0.0
            }), new PositiveDefiniteMatrix(new double[3, 3] {
                { 1.0, 0.0, 0.0 }, { 0.0, 1.0, 0.0 }, { 0.0, 0.0, 1.0 }
            }));

            this.vVector379_marginal_F = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian126);
            // Message from use of 'vdouble__379'
            DistributionStructArray <Gaussian, double> vdouble__379_use_B = default(DistributionStructArray <Gaussian, double>);

            // Create array for 'vdouble__379_use' Backwards messages.
            vdouble__379_use_B = new DistributionStructArray <Gaussian, double>(5622);
            for (int index126 = 0; index126 < 5622; index126++)
            {
                vdouble__379_use_B[index126] = Gaussian.Uniform();
                // Message to 'vdouble__379_use' from GaussianFromMeanAndVariance factor
                vdouble__379_use_B[index126] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(this.Vdouble__378[index126], 0.1);
            }
            DistributionRefArray <VectorGaussian, Vector> vVector379_rep_B = default(DistributionRefArray <VectorGaussian, Vector>);

            // Create array for 'vVector379_rep' Backwards messages.
            vVector379_rep_B = new DistributionRefArray <VectorGaussian, Vector>(5622);
            for (int index126 = 0; index126 < 5622; index126++)
            {
                vVector379_rep_B[index126] = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian126);
                // Message to 'vVector379_rep' from InnerProduct factor
                vVector379_rep_B[index126] = InnerProductOp.AAverageConditional(vdouble__379_use_B[index126], this.VVector__126[index126], vVector379_rep_B[index126]);
            }
            // Buffer for ReplicateOp_Divide.Marginal<VectorGaussian>
            VectorGaussian vVector379_rep_B_toDef = default(VectorGaussian);

            // Message to 'vVector379_rep' from Replicate factor
            vVector379_rep_B_toDef = ReplicateOp_Divide.ToDefInit <VectorGaussian>(vVectorGaussian126);
            // Message to 'vVector379_rep' from Replicate factor
            vVector379_rep_B_toDef = ReplicateOp_Divide.ToDef <VectorGaussian>(vVector379_rep_B, vVector379_rep_B_toDef);
            // Message to 'vVector379_marginal' from Variable factor
            this.vVector379_marginal_F = VariableOp.MarginalAverageConditional <VectorGaussian>(vVector379_rep_B_toDef, vVectorGaussian126, this.vVector379_marginal_F);
            DistributionStructArray <Gaussian, double> vdouble__379_F = default(DistributionStructArray <Gaussian, double>);

            // Create array for 'vdouble__379' Forwards messages.
            vdouble__379_F = new DistributionStructArray <Gaussian, double>(5622);
            for (int index126 = 0; index126 < 5622; index126++)
            {
                vdouble__379_F[index126] = Gaussian.Uniform();
            }
            DistributionRefArray <VectorGaussian, Vector> vVector379_rep_F = default(DistributionRefArray <VectorGaussian, Vector>);

            // Create array for 'vVector379_rep' Forwards messages.
            vVector379_rep_F = new DistributionRefArray <VectorGaussian, Vector>(5622);
            for (int index126 = 0; index126 < 5622; index126++)
            {
                vVector379_rep_F[index126] = ArrayHelper.MakeUniform <VectorGaussian>(vVectorGaussian126);
            }
            // Buffer for ReplicateOp_Divide.UsesAverageConditional<VectorGaussian>
            VectorGaussian vVector379_rep_F_marginal = default(VectorGaussian);

            // Message to 'vVector379_rep' from Replicate factor
            vVector379_rep_F_marginal = ReplicateOp_Divide.MarginalInit <VectorGaussian>(vVectorGaussian126);
            // Message to 'vVector379_rep' from Replicate factor
            vVector379_rep_F_marginal = ReplicateOp_Divide.Marginal <VectorGaussian>(vVector379_rep_B_toDef, vVectorGaussian126, vVector379_rep_F_marginal);
            // Buffer for InnerProductOp.InnerProductAverageConditional
            // Create array for replicates of 'vVector379_rep_F_index126__AMean'
            Vector[] vVector379_rep_F_index126__AMean = new Vector[5622];
            for (int index126 = 0; index126 < 5622; index126++)
            {
                // Message to 'vdouble__379' from InnerProduct factor
                vVector379_rep_F_index126__AMean[index126] = InnerProductOp.AMeanInit(vVector379_rep_F[index126]);
            }
            // Buffer for InnerProductOp.AMean
            // Create array for replicates of 'vVector379_rep_F_index126__AVariance'
            PositiveDefiniteMatrix[] vVector379_rep_F_index126__AVariance = new PositiveDefiniteMatrix[5622];
            for (int index126 = 0; index126 < 5622; index126++)
            {
                // Message to 'vdouble__379' from InnerProduct factor
                vVector379_rep_F_index126__AVariance[index126] = InnerProductOp.AVarianceInit(vVector379_rep_F[index126]);
                // Message to 'vVector379_rep' from Replicate factor
                vVector379_rep_F[index126] = ReplicateOp_Divide.UsesAverageConditional <VectorGaussian>(vVector379_rep_B[index126], vVector379_rep_F_marginal, index126, vVector379_rep_F[index126]);
            }
            // Create array for 'vdouble__379_marginal' Forwards messages.
            this.vdouble__379_marginal_F = new DistributionStructArray <Gaussian, double>(5622);
            for (int index126 = 0; index126 < 5622; index126++)
            {
                this.vdouble__379_marginal_F[index126] = Gaussian.Uniform();
                // Message to 'vdouble__379' from InnerProduct factor
                vVector379_rep_F_index126__AVariance[index126] = InnerProductOp.AVariance(vVector379_rep_F[index126], vVector379_rep_F_index126__AVariance[index126]);
                // Message to 'vdouble__379' from InnerProduct factor
                vVector379_rep_F_index126__AMean[index126] = InnerProductOp.AMean(vVector379_rep_F[index126], vVector379_rep_F_index126__AVariance[index126], vVector379_rep_F_index126__AMean[index126]);
                // Message to 'vdouble__379' from InnerProduct factor
                vdouble__379_F[index126] = InnerProductOp.InnerProductAverageConditional(vVector379_rep_F_index126__AMean[index126], vVector379_rep_F_index126__AVariance[index126], this.VVector__126[index126]);
                // Message to 'vdouble__379_marginal' from DerivedVariable factor
                this.vdouble__379_marginal_F[index126] = DerivedVariableOp.MarginalAverageConditional <Gaussian>(vdouble__379_use_B[index126], vdouble__379_F[index126], this.vdouble__379_marginal_F[index126]);
            }
            this.Changed_vVector__126_vdouble__378_iterationsDone = 1;
        }
Exemplo n.º 3
0
 /// <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;
 }
Exemplo n.º 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 '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);
            Bernoulli Rain_F = ArrayHelper.MakeUniform <Bernoulli>(this.vBernoulli21);
            // The constant 'vBernoulli18'
            Bernoulli vBernoulli18 = Bernoulli.FromLogOdds(0);

            this.Cloudy_marginal_F = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli18);
            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.vBernoulli21);
            }
            // Message to 'Rain_cond_Cloudy' from Copy factor
            Rain_cond_Cloudy_F[0] = Factor.Copy <Bernoulli>(this.vBernoulli21);
            // The constant 'vBernoulli22'
            Bernoulli vBernoulli22 = Bernoulli.FromLogOdds(0.28185115214098749);

            // Message to 'Rain_cond_Cloudy' from Copy factor
            Rain_cond_Cloudy_F[1] = Factor.Copy <Bernoulli>(vBernoulli22);
            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> >(vBernoulli18, Cloudy_selector_cases_F);
            // The constant 'vBernoulli19'
            Bernoulli vBernoulli19 = 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>(vBernoulli19);
            }
            // Message to 'Sprinkler_cond_Cloudy' from Copy factor
            Sprinkler_cond_Cloudy_F[0] = Factor.Copy <Bernoulli>(vBernoulli19);
            // Message to 'Sprinkler_cond_Cloudy' from Copy factor
            Sprinkler_cond_Cloudy_F[1] = Factor.Copy <Bernoulli>(vBernoulli18);
            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);
            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, 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());
            }
            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>(vBernoulli19);
            }
            Bernoulli Sprinkler_selector_B = ArrayHelper.MakeUniform <Bernoulli>(vBernoulli19);
            // 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>(vBernoulli19);
            // 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>(vBernoulli19);
            }
            Bernoulli Rain_cond_Sprinkler_0_selector_B = ArrayHelper.MakeUniform <Bernoulli>(this.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>(this.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>(this.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);
            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>(vBernoulli18);

            // 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, vBernoulli18, this.Cloudy_marginal_F);
            this.Rain_marginal_F   = ArrayHelper.MakeUniform <Bernoulli>(this.vBernoulli21);
            // 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>(vBernoulli19);
            // 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;
        }
Exemplo n.º 5
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;
        }
Exemplo n.º 6
0
        /// <summary>Computations that depend on the observed value of numberOfIterations and vint__0 and vint__1</summary>
        /// <param name="numberOfIterations">The number of times to iterate each loop</param>
        private void Changed_numberOfIterations_vint__0_vint__1(int numberOfIterations)
        {
            if (this.Changed_numberOfIterations_vint__0_vint__1_isDone)
            {
                return;
            }
            DistributionStructArray <Gaussian, double> vdouble__0_F;
            Gaussian vdouble__0_F_reduced;

            // Create array for 'vdouble__0' Forwards messages.
            vdouble__0_F = new DistributionStructArray <Gaussian, double>(5);
            // Message to 'vdouble__0' from GaussianFromMeanAndVariance factor
            vdouble__0_F_reduced = GaussianFromMeanAndVarianceOp.SampleAverageConditional(6.0, 9.0);
            for (int index1 = 0; index1 < 5; index1++)
            {
                vdouble__0_F[index1] = vdouble__0_F_reduced;
                vdouble__0_F[index1] = vdouble__0_F_reduced;
            }
            // Create array for 'vdouble__0_marginal' Forwards messages.
            this.vdouble__0_marginal_F = new DistributionStructArray <Gaussian, double>(5);
            DistributionStructArray <Gaussian, double> vdouble__0_use_B;

            // Create array for 'vdouble__0_use' Backwards messages.
            vdouble__0_use_B = new DistributionStructArray <Gaussian, double>(5);
            for (int index1 = 0; index1 < 5; index1++)
            {
                vdouble__0_use_B[index1] = Gaussian.Uniform();
            }
            DistributionStructArray <Gaussian, double>[] vdouble__0_uses_F;
            // Create array for 'vdouble__0_uses' Forwards messages.
            vdouble__0_uses_F = new DistributionStructArray <Gaussian, double> [2];
            // Create array for 'vdouble__0_uses' Forwards messages.
            vdouble__0_uses_F[1] = new DistributionStructArray <Gaussian, double>(5);
            for (int index1 = 0; index1 < 5; index1++)
            {
                vdouble__0_uses_F[1][index1] = Gaussian.Uniform();
            }
            DistributionStructArray <Gaussian, double> vdouble__0_uses_F_1__marginal;

            // Message to 'vdouble__0_itemvint__1_index0_' from GetItems factor
            vdouble__0_uses_F_1__marginal = GetItemsOp <double> .MarginalInit <DistributionStructArray <Gaussian, double> >(vdouble__0_uses_F[1]);

            DistributionStructArray <Gaussian, double> vdouble__0_itemvint__1_index0__F;

            // Create array for 'vdouble__0_itemvint__1_index0_' Forwards messages.
            vdouble__0_itemvint__1_index0__F = new DistributionStructArray <Gaussian, double>(6);
            for (int index0 = 0; index0 < 6; index0++)
            {
                vdouble__0_itemvint__1_index0__F[index0] = Gaussian.Uniform();
            }
            // Create array for replicates of 'vdouble11_F'
            DistributionStructArray <Gaussian, double> vdouble11_F = new DistributionStructArray <Gaussian, double>(6);

            for (int index0 = 0; index0 < 6; index0++)
            {
                vdouble11_F[index0] = Gaussian.Uniform();
            }
            // Create array for 'vdouble__0_uses' Forwards messages.
            vdouble__0_uses_F[0] = new DistributionStructArray <Gaussian, double>(5);
            for (int index1 = 0; index1 < 5; index1++)
            {
                vdouble__0_uses_F[0][index1] = Gaussian.Uniform();
            }
            DistributionStructArray <Gaussian, double> vdouble__0_uses_F_0__marginal;

            // Message to 'vdouble__0_itemvint__0_index0_' from GetItems factor
            vdouble__0_uses_F_0__marginal = GetItemsOp <double> .MarginalInit <DistributionStructArray <Gaussian, double> >(vdouble__0_uses_F[0]);

            DistributionStructArray <Gaussian, double> vdouble__0_itemvint__0_index0__F;

            // Create array for 'vdouble__0_itemvint__0_index0_' Forwards messages.
            vdouble__0_itemvint__0_index0__F = new DistributionStructArray <Gaussian, double>(6);
            for (int index0 = 0; index0 < 6; index0++)
            {
                vdouble__0_itemvint__0_index0__F[index0] = Gaussian.Uniform();
            }
            // Create array for replicates of 'vdouble8_F'
            DistributionStructArray <Gaussian, double> vdouble8_F = new DistributionStructArray <Gaussian, double>(6);

            for (int index0 = 0; index0 < 6; index0++)
            {
                vdouble8_F[index0] = Gaussian.Uniform();
            }
            // Create array for replicates of 'vdouble12_F'
            DistributionStructArray <Gaussian, double> vdouble12_F = new DistributionStructArray <Gaussian, double>(6);

            for (int index0 = 0; index0 < 6; index0++)
            {
                vdouble12_F[index0] = Gaussian.Uniform();
            }
            // Create array for replicates of 'vdouble12_B'
            DistributionStructArray <Gaussian, double> vdouble12_B = new DistributionStructArray <Gaussian, double>(6);

            for (int index0 = 0; index0 < 6; index0++)
            {
                vdouble12_B[index0] = Gaussian.Uniform();
            }
            // Create array for replicates of 'vdouble8_use_B'
            DistributionStructArray <Gaussian, double> vdouble8_use_B = new DistributionStructArray <Gaussian, double>(6);

            for (int index0 = 0; index0 < 6; index0++)
            {
                vdouble8_use_B[index0] = Gaussian.Uniform();
            }
            // Create array for replicates of 'vdouble11_use_B'
            DistributionStructArray <Gaussian, double> vdouble11_use_B = new DistributionStructArray <Gaussian, double>(6);

            for (int index0 = 0; index0 < 6; index0++)
            {
                vdouble11_use_B[index0] = Gaussian.Uniform();
            }
            for (int iteration = this.numberOfIterationsDone; iteration < numberOfIterations; iteration++)
            {
                // Message to 'vdouble__0_uses' from Replicate factor
                vdouble__0_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.vdouble__0_uses_B, vdouble__0_F, 1, vdouble__0_uses_F[1]);
                // Message to 'vdouble__0_itemvint__1_index0_' from GetItems factor
                vdouble__0_uses_F_1__marginal = GetItemsOp <double> .Marginal <DistributionStructArray <Gaussian, double>, Gaussian>(vdouble__0_uses_F[1], this.vdouble__0_uses_B[1], vdouble__0_uses_F_1__marginal);

                // Message to 'vdouble__0_uses' from Replicate factor
                vdouble__0_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.vdouble__0_uses_B, vdouble__0_F, 0, vdouble__0_uses_F[0]);
                // Message to 'vdouble__0_itemvint__0_index0_' from GetItems factor
                vdouble__0_uses_F_0__marginal = GetItemsOp <double> .Marginal <DistributionStructArray <Gaussian, double>, Gaussian>(vdouble__0_uses_F[0], this.vdouble__0_uses_B[0], vdouble__0_uses_F_0__marginal);

                for (int index0 = 0; index0 < 6; index0++)
                {
                    // Message to 'vdouble__0_itemvint__1_index0_' from GetItems factor
                    vdouble__0_itemvint__1_index0__F[index0] = GetItemsOp <double> .ItemsAverageConditional <DistributionStructArray <Gaussian, double>, Gaussian>(this.vdouble__0_itemvint__1_index0__B[index0], vdouble__0_uses_F[1], vdouble__0_uses_F_1__marginal, this.Vint__1, index0, vdouble__0_itemvint__1_index0__F[index0]);

                    // Message to 'vdouble11' from GaussianFromMeanAndVariance factor
                    vdouble11_F[index0] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(vdouble__0_itemvint__1_index0__F[index0], 1.0);
                    // Message to 'vdouble__0_itemvint__0_index0_' from GetItems factor
                    vdouble__0_itemvint__0_index0__F[index0] = GetItemsOp <double> .ItemsAverageConditional <DistributionStructArray <Gaussian, double>, Gaussian>(this.vdouble__0_itemvint__0_index0__B[index0], vdouble__0_uses_F[0], vdouble__0_uses_F_0__marginal, this.Vint__0, index0, vdouble__0_itemvint__0_index0__F[index0]);

                    // Message to 'vdouble8' from GaussianFromMeanAndVariance factor
                    vdouble8_F[index0] = GaussianFromMeanAndVarianceOp.SampleAverageConditional(vdouble__0_itemvint__0_index0__F[index0], 1.0);
                    // Message to 'vdouble12' from Difference factor
                    vdouble12_F[index0] = DoublePlusOp.AAverageConditional(vdouble8_F[index0], vdouble11_F[index0]);
                    // Message to 'vdouble12' from IsPositive factor
                    vdouble12_B[index0] = IsPositiveOp_Proper.XAverageConditional(Bernoulli.PointMass(true), vdouble12_F[index0]);
                    // Message to 'vdouble8_use' from Difference factor
                    vdouble8_use_B[index0] = DoublePlusOp.SumAverageConditional(vdouble12_B[index0], vdouble11_F[index0]);
                    // Message to 'vdouble__0_itemvint__0_index0_' from GaussianFromMeanAndVariance factor
                    this.vdouble__0_itemvint__0_index0__B[index0] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(vdouble8_use_B[index0], 1.0);
                    // Message to 'vdouble11_use' from Difference factor
                    vdouble11_use_B[index0] = DoublePlusOp.BAverageConditional(vdouble8_F[index0], vdouble12_B[index0]);
                    // Message to 'vdouble__0_itemvint__1_index0_' from GaussianFromMeanAndVariance factor
                    this.vdouble__0_itemvint__1_index0__B[index0] = GaussianFromMeanAndVarianceOp.MeanAverageConditional(vdouble11_use_B[index0], 1.0);
                }
                // Message to 'vdouble__0_uses' from GetItems factor
                this.vdouble__0_uses_B[0] = GetItemsOp <double> .ArrayAverageConditional <Gaussian, DistributionStructArray <Gaussian, double> >(this.vdouble__0_itemvint__0_index0__B, this.Vint__0, this.vdouble__0_uses_B[0]);

                // Message to 'vdouble__0_uses' from GetItems factor
                this.vdouble__0_uses_B[1] = GetItemsOp <double> .ArrayAverageConditional <Gaussian, DistributionStructArray <Gaussian, double> >(this.vdouble__0_itemvint__1_index0__B, this.Vint__1, this.vdouble__0_uses_B[1]);

                this.OnProgressChanged(new ProgressChangedEventArgs(iteration));
            }
            // Message to 'vdouble__0_use' from Replicate factor
            vdouble__0_use_B = ReplicateOp_NoDivide.DefAverageConditional <DistributionStructArray <Gaussian, double> >(this.vdouble__0_uses_B, vdouble__0_use_B);
            for (int index1 = 0; index1 < 5; index1++)
            {
                this.vdouble__0_marginal_F[index1] = Gaussian.Uniform();
                // Message to 'vdouble__0_marginal' from Variable factor
                this.vdouble__0_marginal_F[index1] = VariableOp.MarginalAverageConditional <Gaussian>(vdouble__0_use_B[index1], vdouble__0_F_reduced, this.vdouble__0_marginal_F[index1]);
            }
            this.Changed_numberOfIterations_vint__0_vint__1_isDone = true;
        }
Exemplo n.º 7
0
        /// <summary>Computations that do not depend on observed values</summary>
        private void Constant()
        {
            if (this.Constant_isDone)
            {
                return;
            }
            Gaussian t1_F = default(Gaussian);

            this.t1_marginal_F = Gaussian.Uniform();
            Gaussian t1_use_B = Gaussian.Uniform();

            // Message to 't1' from GaussianFromMeanAndVariance factor
            t1_F = GaussianFromMeanAndVarianceOp.SampleAverageConditional(1.0, 1.0);
            Gaussian[] t1_uses_F;
            Gaussian[] t1_uses_B;
            // Create array for 't1_uses' Forwards messages.
            t1_uses_F = new Gaussian[2];
            // Create array for 't1_uses' Backwards messages.
            t1_uses_B    = new Gaussian[2];
            t1_uses_B[1] = Gaussian.Uniform();
            t1_uses_B[0] = Gaussian.Uniform();
            t1_uses_F[1] = Gaussian.Uniform();
            t1_uses_F[0] = Gaussian.Uniform();
            // Message to 't1_marginal' from Variable factor
            this.t1_marginal_F = VariableOp.MarginalAverageConditional <Gaussian>(t1_use_B, t1_F, this.t1_marginal_F);
            // Message to 't1_uses' from Replicate factor
            t1_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(t1_uses_B, t1_F, 0, t1_uses_F[0]);
            // Message to 't1_uses' from Replicate factor
            t1_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(t1_uses_B, t1_F, 1, t1_uses_F[1]);
            Gaussian t2_F = default(Gaussian);

            this.t2_marginal_F = Gaussian.Uniform();
            Gaussian t2_use_B = Gaussian.Uniform();

            // Message to 't2' from GaussianFromMeanAndVariance factor
            t2_F = GaussianFromMeanAndVarianceOp.SampleAverageConditional(10.0, 1.0);
            Gaussian[] t2_uses_F;
            Gaussian[] t2_uses_B;
            // Create array for 't2_uses' Forwards messages.
            t2_uses_F = new Gaussian[2];
            // Create array for 't2_uses' Backwards messages.
            t2_uses_B    = new Gaussian[2];
            t2_uses_B[1] = Gaussian.Uniform();
            t2_uses_B[0] = Gaussian.Uniform();
            t2_uses_F[1] = Gaussian.Uniform();
            t2_uses_F[0] = Gaussian.Uniform();
            // Message to 't2_marginal' from Variable factor
            this.t2_marginal_F = VariableOp.MarginalAverageConditional <Gaussian>(t2_use_B, t2_F, this.t2_marginal_F);
            // Message to 't2_uses' from Replicate factor
            t2_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(t2_uses_B, t2_F, 0, t2_uses_F[0]);
            // Message to 't2_uses' from Replicate factor
            t2_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(t2_uses_B, t2_F, 1, t2_uses_F[1]);
            Gaussian vdouble6_F = default(Gaussian);

            this.vdouble6_marginal_F = Gaussian.Uniform();
            Gaussian vdouble6_use_B = Gaussian.Uniform();

            // Message to 'vdouble6' from Plus factor
            vdouble6_F = DoublePlusOp.SumAverageConditional(t1_uses_F[0], t2_uses_F[0]);
            // Message to 'vdouble6_marginal' from DerivedVariable factor
            this.vdouble6_marginal_F = DerivedVariableOp.MarginalAverageConditional <Gaussian>(vdouble6_use_B, vdouble6_F, this.vdouble6_marginal_F);
            Gaussian t4_F = default(Gaussian);

            this.t4_marginal_F = Gaussian.Uniform();
            Gaussian t4_use_B = Gaussian.Uniform();

            // Message to 't4' from GaussianFromMeanAndVariance factor
            t4_F = GaussianFromMeanAndVarianceOp.SampleAverageConditional(2.0, 1.0);
            Gaussian[] t4_uses_F;
            Gaussian[] t4_uses_B;
            // Create array for 't4_uses' Forwards messages.
            t4_uses_F = new Gaussian[2];
            // Create array for 't4_uses' Backwards messages.
            t4_uses_B    = new Gaussian[2];
            t4_uses_B[1] = Gaussian.Uniform();
            t4_uses_B[0] = Gaussian.Uniform();
            t4_uses_F[1] = Gaussian.Uniform();
            t4_uses_F[0] = Gaussian.Uniform();
            // Message to 't4_marginal' from Variable factor
            this.t4_marginal_F = VariableOp.MarginalAverageConditional <Gaussian>(t4_use_B, t4_F, this.t4_marginal_F);
            // Message to 't4_uses' from Replicate factor
            t4_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(t4_uses_B, t4_F, 0, t4_uses_F[0]);
            // Message to 't4_uses' from Replicate factor
            t4_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(t4_uses_B, t4_F, 1, t4_uses_F[1]);
            Gaussian vdouble10_F = default(Gaussian);

            this.vdouble10_marginal_F = Gaussian.Uniform();
            Gaussian vdouble10_use_B = Gaussian.Uniform();

            // Message to 'vdouble10' from Plus factor
            vdouble10_F = DoublePlusOp.SumAverageConditional(t1_uses_F[1], t2_uses_F[1]);
            // Message to 'vdouble10_marginal' from DerivedVariable factor
            this.vdouble10_marginal_F = DerivedVariableOp.MarginalAverageConditional <Gaussian>(vdouble10_use_B, vdouble10_F, this.vdouble10_marginal_F);
            Gaussian t5_F = default(Gaussian);

            this.t5_marginal_F = Gaussian.Uniform();
            Gaussian t5_use_B = Gaussian.Uniform();

            // Message to 't5' from Product factor
            t5_F = GaussianProductOp.ProductAverageConditional(t5_use_B, vdouble10_F, t4_uses_F[0]);
            // Message to 't5_marginal' from DerivedVariable factor
            this.t5_marginal_F = DerivedVariableOp.MarginalAverageConditional <Gaussian>(t5_use_B, t5_F, this.t5_marginal_F);
            Gaussian t7_F = default(Gaussian);

            this.t7_marginal_F = Gaussian.Uniform();
            Gaussian t7_use_B = Gaussian.Uniform();

            // Message to 't7' from Product factor
            t7_F = GaussianProductOp.ProductAverageConditional(t7_use_B, vdouble6_F, t4_uses_F[1]);
            // Message to 't7_marginal' from DerivedVariable factor
            this.t7_marginal_F   = DerivedVariableOp.MarginalAverageConditional <Gaussian>(t7_use_B, t7_F, this.t7_marginal_F);
            this.Constant_isDone = true;
        }