private IEnumerable <ParameterDistributionMetaData> scaleDistributions(TableFormulaParameter <IDistributedParameter> parameter, IEnumerable <ParameterDistributionMetaData> distributionsToScale)
        {
            //Retrieve the mean height parameter for the given origin data
            var originData          = parameter.OriginData;
            var individualParameter = parameter.Parameter;

            bool needHeightScaling = needScaling(originData, individualParameter);

            if (!needHeightScaling)
            {
                return(distributionsToScale);
            }

            //retrieve the height distribution for the original individual
            var heightDistributions = allDistributionsFor(_allHeightDistributionMaleParameters, _allHeightDistributionFemaleParameters, originData).ToList();

            var heightDistributionParameters = distributionParametersFor(heightDistributions, originData);

            double meanHeight = heightDistributionParameters.Item1;
            double deviation  = heightDistributionParameters.Item2;
            var    heigthDistributionFormula = distributionFrom(DistributionTypes.Normal, meanHeight, deviation);

            double currentHeight = originData.Height.GetValueOrDefault(meanHeight);

            //same height, not need to scale
            if (ValueComparer.AreValuesEqual(meanHeight, currentHeight))
            {
                return(distributionsToScale);
            }

            //is used in order to retrieve the percentile
            double currentPercentile = heigthDistributionFormula.CalculatePercentileForValue(currentHeight);
            double alpha             = individualParameter.ParentContainer.Parameter(CoreConstants.Parameter.ALLOMETRIC_SCALE_FACTOR).Value;

            var currentOriginData = originData.Clone();
            var scaledParameterDistributionMetaData = new List <ParameterDistributionMetaData>();

            foreach (var originDistributionMetaData in distributionsToScale)
            {
                var distributionMetaData = ParameterDistributionMetaData.From(originDistributionMetaData);
                currentOriginData.Age = originDistributionMetaData.Age;
                double hrelForAge = calculateRelativeHeightForAge(heightDistributions, currentOriginData, currentPercentile);

                scaleDistributionMetaData(distributionMetaData, hrelForAge, alpha);
                scaledParameterDistributionMetaData.Add(distributionMetaData);
            }

            return(scaledParameterDistributionMetaData);
        }
예제 #2
0
        private IReadOnlyList <ParameterDistributionMetaData> scaleDistributions(TableFormulaParameter <IDistributedParameter> parameter, IReadOnlyList <ParameterDistributionMetaData> distributionsToScale)
        {
            //Retrieve the mean height parameter for the given origin data
            var originData          = parameter.OriginData;
            var individualParameter = parameter.Parameter;

            bool needHeightScaling = needScaling(originData, individualParameter);

            if (!needHeightScaling)
            {
                return(distributionsToScale);
            }

            var(meanHeight, currentHeight, currentPercentile, heightDistributionSamples) = heightDistributionsFor(originData);

            //same height, not need to scale
            if (ValueComparer.AreValuesEqual(meanHeight, currentHeight))
            {
                return(distributionsToScale);
            }

            //is used in order to retrieve the percentile
            double alpha = individualParameter.ParentContainer.Parameter(CoreConstants.Parameters.ALLOMETRIC_SCALE_FACTOR).Value;

            var currentOriginData = originData.Clone();
            var scaledParameterDistributionMetaData = new List <ParameterDistributionMetaData>();

            foreach (var originDistributionMetaData in distributionsToScale)
            {
                var distributionMetaData = ParameterDistributionMetaData.From(originDistributionMetaData);
                currentOriginData.Age.Value = originDistributionMetaData.Age;

                var(mean, deviation) = heightDistributionSamples(currentOriginData);
                double heightAtPercentile = valueFrom(DistributionTypes.Normal, mean, deviation, currentPercentile);
                double hrelForAge         = heightAtPercentile / mean;

                scaleDistributionMetaData(distributionMetaData, hrelForAge, alpha);
                scaledParameterDistributionMetaData.Add(distributionMetaData);
            }

            return(scaledParameterDistributionMetaData);
        }
 protected override void Because()
 {
     _copy = ParameterDistributionMetaData.From(sut);
 }