Пример #1
0
        static public ConditionalGaussianDistribution GetInstance()

        {
            ConditionalGaussianDistribution aLinearGaussian = new ConditionalGaussianDistribution();

            return(aLinearGaussian);
        }
        public ConditionalGaussianDistribution CreateDistributionGaussianOrNull(Branch branch, OptimizationParameterList gaussianParameters)
        {
            if (branch.Length == 0)
            {
                Debug.WriteLine("Branch length of zero observed");
            }

            ConditionalGaussianDistribution plainConditionalDistribution = GetPlainConditionalGaussianDistribution(branch, gaussianParameters);

            return(plainConditionalDistribution);
        }
        protected override ConditionalGaussianDistribution GetPlainConditionalGaussianDistribution(BranchOrLeaf branchOrLeaf, OptimizationParameterList gaussianParameters)
        {
            double alphaTimesVariance = gaussianParameters["AlphaVariance"].Value;

            ConditionalGaussianDistribution plainConditionalDistribution = ConditionalGaussianDistribution.GetInstance();

            // 0 (const part of mean) ax + b, Mean := b
            plainConditionalDistribution.Mean = 0;
            // 1 (ax + b = x), linearCoefficent := a.
            plainConditionalDistribution.LinearCoefficent = 1;
            plainConditionalDistribution.Variance         = alphaTimesVariance * branchOrLeaf.Length;
            return(plainConditionalDistribution);
        }
        protected override ConditionalGaussianDistribution GetPlainConditionalGaussianDistribution(BranchOrLeaf branchOrLeaf, OptimizationParameterList gaussianParameters)
        {
            double alphaTimesVariance = gaussianParameters["AlphaVariance"].Value;
            double mean  = gaussianParameters["Mean"].Value;
            double alpha = gaussianParameters["Alpha"].Value;

            ConditionalGaussianDistribution plainConditionalDistribution = ConditionalGaussianDistribution.GetInstance();
            double root1MinusAlphaTimesBranchLength = Math.Sqrt(1 - alpha * branchOrLeaf.Length);

            // ax + b, Mean := b
            plainConditionalDistribution.Mean = mean * (1.0 - root1MinusAlphaTimesBranchLength);
            // ax + b = x, LinearCoefficent := a
            plainConditionalDistribution.LinearCoefficent = root1MinusAlphaTimesBranchLength;
            plainConditionalDistribution.Variance         = alphaTimesVariance * branchOrLeaf.Length;
            return(plainConditionalDistribution);
        }
        public ConditionalGaussianDistribution CreateDistributionGaussianOrNull(
            Leaf leaf,
            OptimizationParameterList gaussianParameters,
            Converter <Leaf, SufficientStatistics> predictorLeafToBoolStats)
        {
            if (leaf.Length == 0)
            {
                Debug.WriteLine("Branch length of zero observed");
            }

            ConditionalGaussianDistribution plainConditionalDistribution = GetPlainConditionalGaussianDistribution(leaf, gaussianParameters);

            BooleanStatistics hasPredictor = (BooleanStatistics)predictorLeafToBoolStats(leaf);

            if (hasPredictor.IsMissing())
            {
                return(null); // Predictor data is missing, so skip this leaf.
            }

            double delta = GetOffset(gaussianParameters);

            return(LabelledLeafDistributionGaussian.CreateDistributionGaussianOrNull(plainConditionalDistribution, hasPredictor, delta));
        }