/// <summary>Computations that depend on the observed value of FeatureIndexes and FeatureValues and InstanceCount and InstanceFeatureCounts and Labels and numberOfIterations and WeightConstraints and WeightPriors</summary>
        /// <param name="numberOfIterations">The number of times to iterate each loop</param>
        private void Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7(int numberOfIterations)
        {
            if (this.Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7_isDone)
            {
                return;
            }
            for (int iteration = this.numberOfIterationsDone; iteration < numberOfIterations; iteration++)
            {
                for (int InstanceRange = 0; InstanceRange < this.instanceCount; InstanceRange++)
                {
                    this.Weights_FeatureIndexes_F[InstanceRange] = JaggedSubarrayWithMarginalOp <double> .ItemsAverageConditional <DistributionStructArray <Gaussian, double>, Gaussian, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B[InstanceRange], this.Weights_uses_F[1], this.Weights_marginal_F, this.featureIndexes, InstanceRange, this.Weights_FeatureIndexes_F[InstanceRange]);

                    for (int InstanceFeatureRanges = 0; InstanceFeatureRanges < this.instanceFeatureCounts[InstanceRange]; InstanceFeatureRanges++)
                    {
                        this.FeatureScores_F[InstanceRange][InstanceFeatureRanges] = GaussianProductOpBase.ProductAverageConditional(this.featureValues[InstanceRange][InstanceFeatureRanges], this.Weights_FeatureIndexes_F[InstanceRange][InstanceFeatureRanges]);
                    }
                    this.Score_F[InstanceRange]          = FastSumOp.SumAverageConditional(this.FeatureScores_F[InstanceRange]);
                    this.NoisyScore_F[InstanceRange]     = GaussianFromMeanAndVarianceOp.SampleAverageConditional(this.Score_F[InstanceRange], 1.0);
                    this.NoisyScore_use_B[InstanceRange] = IsPositiveOp_Proper.XAverageConditional(Bernoulli.PointMass(this.labels[InstanceRange]), this.NoisyScore_F[InstanceRange]);
                    this.Score_B[InstanceRange]          = GaussianFromMeanAndVarianceOp.MeanAverageConditional(this.NoisyScore_use_B[InstanceRange], 1.0);
                    this.FeatureScores_B[InstanceRange]  = FastSumOp.ArrayAverageConditional <DistributionStructArray <Gaussian, double> >(this.Score_B[InstanceRange], this.Score_F[InstanceRange], this.FeatureScores_F[InstanceRange], this.FeatureScores_B[InstanceRange]);
                    for (int InstanceFeatureRanges = 0; InstanceFeatureRanges < this.instanceFeatureCounts[InstanceRange]; InstanceFeatureRanges++)
                    {
                        this.IndexedWeights_B[InstanceRange][InstanceFeatureRanges] = GaussianProductOpBase.BAverageConditional(this.FeatureScores_B[InstanceRange][InstanceFeatureRanges], this.featureValues[InstanceRange][InstanceFeatureRanges]);
                    }
                    this.Weights_marginal_F = JaggedSubarrayWithMarginalOp <double> .MarginalIncrementItems <DistributionStructArray <Gaussian, double>, Gaussian, DistributionStructArray <Gaussian, double> >(this.IndexedWeights_B[InstanceRange], this.Weights_FeatureIndexes_F[InstanceRange], this.featureIndexes, InstanceRange, this.Weights_marginal_F);
                }
                this.OnProgressChanged(new ProgressChangedEventArgs(iteration));
            }
            this.Weights_uses_B[1] = JaggedSubarrayWithMarginalOp <double> .ArrayAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_F[1], this.Weights_marginal_F, this.Weights_uses_B[1]);

            this.Weights_B = ReplicateOp_NoDivide.DefAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.Weights_B);
            this.Changed_FeatureIndexes_FeatureValues_InstanceCount_InstanceFeatureCounts_Labels_numberOfIterations_W7_isDone = true;
        }
        /// <summary>Computations that depend on the observed value of vbool1 and vdouble1 and vGaussian3</summary>
        private void Changed_vbool1_vdouble1_vGaussian3()
        {
            if (this.Changed_vbool1_vdouble1_vGaussian3_isDone)
            {
                return;
            }
            Gaussian vdouble13_F = default(Gaussian);

            this.vdouble13_marginal_F = Gaussian.Uniform();
            this.vdouble13_use_B      = Gaussian.Uniform();
            // Message to 'vdouble13' from GaussianFromMeanAndVariance factor
            vdouble13_F = GaussianFromMeanAndVarianceOp.SampleAverageConditional(0.0, 10.0);
            Gaussian[] vdouble13_uses_B;
            // Create array for 'vdouble13_uses' Backwards messages.
            vdouble13_uses_B    = new Gaussian[2];
            vdouble13_uses_B[1] = Gaussian.Uniform();
            vdouble13_uses_B[0] = Gaussian.Uniform();
            // Message to 'vdouble13_uses' from EqualRandom factor
            vdouble13_uses_B[0] = ArrayHelper.SetTo <Gaussian>(vdouble13_uses_B[0], this.VGaussian3);
            Gaussian vdouble13_0__B = default(Gaussian);

            if (this.Vbool1)
            {
                // Message to 'vdouble13_0_' from GaussianFromMeanAndVariance factor
                vdouble13_0__B = GaussianFromMeanAndVarianceOp.MeanAverageConditional(this.Vdouble1, 1.0);
                // Message to 'vdouble13_uses' from Copy factor
                vdouble13_uses_B[1] = ArrayHelper.SetTo <Gaussian>(vdouble13_uses_B[1], vdouble13_0__B);
            }
            // Message to 'vdouble13_use' from Replicate factor
            this.vdouble13_use_B = ReplicateOp_NoDivide.DefAverageConditional <Gaussian>(vdouble13_uses_B, this.vdouble13_use_B);
            // Message to 'vdouble13_marginal' from Variable factor
            this.vdouble13_marginal_F = VariableOp.MarginalAverageConditional <Gaussian>(this.vdouble13_use_B, vdouble13_F, this.vdouble13_marginal_F);
            this.Changed_vbool1_vdouble1_vGaussian3_isDone = true;
        }
 /// <summary>Computations that depend on the observed value of WeightConstraints and WeightPriors</summary>
 private void Changed_WeightConstraints_WeightPriors()
 {
     if (this.Changed_WeightConstraints_WeightPriors_isDone)
     {
         return;
     }
     this.Weights_uses_B[0] = ArrayHelper.SetTo <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B[0], this.weightConstraints);
     this.Weights_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.weightPriors, 1, this.Weights_uses_F[1]);
     this.Changed_WeightConstraints_WeightPriors_isDone = true;
 }
 /// <summary>Computations that depend on the observed value of FeatureCount and numberOfIterationsDecreased and WeightConstraints and WeightPriors and must reset on changes to FeatureValues and InstanceCount and Labels</summary>
 /// <param name="initialise">If true, reset messages that initialise loops</param>
 private void Changed_FeatureCount_numberOfIterationsDecreased_WeightConstraints_WeightPriors_Init_FeatureValues_I5(bool initialise)
 {
     if (this.Changed_FeatureCount_numberOfIterationsDecreased_WeightConstraints_WeightPriors_Init_FeatureValues_I5_isDone && ((!initialise) || this.Changed_FeatureCount_numberOfIterationsDecreased_WeightConstraints_WeightPriors_Init_FeatureValues_I5_isInitialised))
     {
         return;
     }
     this.Weights_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <DistributionStructArray <Gaussian, double> >(this.Weights_uses_B, this.weightPriors, 1, this.Weights_uses_F[1]);
     this.Changed_FeatureCount_numberOfIterationsDecreased_WeightConstraints_WeightPriors_Init_FeatureValues_I5_isDone        = true;
     this.Changed_FeatureCount_numberOfIterationsDecreased_WeightConstraints_WeightPriors_Init_FeatureValues_I5_isInitialised = true;
 }
Ejemplo n.º 5
0
        /// <summary>Computations that depend on the observed value of x1</summary>
        private void Changed_x1()
        {
            if (this.Changed_x1_isDone)
            {
                return;
            }
            Gaussian x2_F = default(Gaussian);

            this.x2_marginal_F = Gaussian.Uniform();
            Gaussian x2_use_B = Gaussian.Uniform();

            // Message to 'x2' from GaussianFromMeanAndVariance factor
            x2_F = GaussianFromMeanAndVarianceOp.SampleAverageConditional(0.0, 100.0);
            // Message to 'x2_marginal' from Variable factor
            this.x2_marginal_F = VariableOp.MarginalAverageConditional <Gaussian>(x2_use_B, x2_F, this.x2_marginal_F);
            Gaussian vdouble26_F = default(Gaussian);

            this.vdouble26_marginal_F = Gaussian.Uniform();
            Gaussian vdouble26_use_B = Gaussian.Uniform();

            Gaussian[] vdouble26_uses_F;
            Gaussian[] vdouble26_uses_B;
            // Create array for 'vdouble26_uses' Forwards messages.
            vdouble26_uses_F = new Gaussian[2];
            // Create array for 'vdouble26_uses' Backwards messages.
            vdouble26_uses_B    = new Gaussian[2];
            vdouble26_uses_B[1] = Gaussian.Uniform();
            vdouble26_uses_B[0] = Gaussian.Uniform();
            vdouble26_uses_F[1] = Gaussian.Uniform();
            vdouble26_uses_F[0] = Gaussian.Uniform();
            // Message to 'vdouble26' from Difference factor
            vdouble26_F = DoublePlusOp.AAverageConditional(x2_F, this.X1);
            // Message to 'vdouble26' from Copy factor
            vdouble26_F = Distribution.SetPoint <Gaussian, double>(vdouble26_F, Factor.Copy <double>(0.0));
            // FactorManager.Any(vdouble26_F, vdouble26_F) is now updated in all contexts
            // Message to 'vdouble26_uses' from Replicate factor
            vdouble26_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(vdouble26_uses_B, vdouble26_F, 0, vdouble26_uses_F[0]);
            // Message to 'vdouble26_uses' from Replicate factor
            vdouble26_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(vdouble26_uses_B, vdouble26_F, 1, vdouble26_uses_F[1]);
            // Message to 'vdouble26_uses' from Replicate factor
            vdouble26_uses_F[0] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(vdouble26_uses_B, vdouble26_F, 0, vdouble26_uses_F[0]);
            // FactorManager.Any(vdouble26_uses_F[0], vdouble26_uses_F[0]) is now updated in all contexts
            // Message to 'vdouble26_marginal' from DerivedVariable factor
            this.vdouble26_marginal_F = DerivedVariableOp.MarginalAverageConditional <Gaussian>(vdouble26_use_B, vdouble26_uses_F[0], this.vdouble26_marginal_F);
            // Message to 'vdouble26_uses' from Replicate factor
            vdouble26_uses_F[1] = ReplicateOp_NoDivide.UsesAverageConditional <Gaussian>(vdouble26_uses_B, vdouble26_F, 1, vdouble26_uses_F[1]);
            // FactorManager.Any(vdouble26_uses_F[1], vdouble26_uses_F[1]) is now updated in all contexts
            // Message to 'vdouble26_marginal' from DerivedVariable factor
            this.vdouble26_marginal_F = DerivedVariableOp.MarginalAverageConditional <Gaussian>(vdouble26_use_B, vdouble26_uses_F[1], this.vdouble26_marginal_F);
            this.x1_marginal_F        = Gaussian.Uniform();
            // Message to 'x1_marginal' from DerivedVariable factor
            this.x1_marginal_F = DerivedVariableOp.MarginalAverageConditional <Gaussian, double>(this.X1, this.x1_marginal_F);
            // FactorManager.Any(vdouble26_marginal_F, vdouble26_marginal_F) is now updated in all contexts
            this.Changed_x1_isDone = true;
        }
        /// <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 FeatureRange = 0; FeatureRange < this.featureCount; FeatureRange++)
     {
         this.Weights_depth1_B[FeatureRange] = ArrayHelper.SetTo <Gaussian>(this.Weights_depth1_B[FeatureRange], this.Weights_depth1_rep_B_toDef[FeatureRange]);
     }
     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_B[_iv]);
     }
     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;
 }
Ejemplo n.º 8
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;
        }
Ejemplo n.º 9
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;
        }