Exemple #1
0
        private TableFormula createTableFormulaFrom(TableFormulaParameter <IDistributedParameter> parameter, IReadOnlyList <ParameterDistributionMetaData> allDistributionsWithAgeStrictBiggerThanOriginData)
        {
            if (allDistributionsWithAgeStrictBiggerThanOriginData.Count == 0)
            {
                return(null);
            }

            var tableFormula = _formulaFactory.CreateDistributedTableFormula();

            updateTableFormulaFrom(tableFormula, parameter.Parameter);
            tableFormula.Percentile = parameter.Percentile;

            if (parameter.PercentileIsInvalid)
            {
                throw new PKSimException(PKSimConstants.Error.CannotCreateAgingSimulationWithInvalidPercentile(_fullPathDisplayResolver.FullPathFor(parameter.Parameter), parameter.Percentile));
            }

            //0 because of the offset with age
            tableFormula.AddPoint(0, parameter.Value, DistributionMetaData.From(parameter.Parameter));

            foreach (var scaledDistribution in scaleDistributions(parameter, allDistributionsWithAgeStrictBiggerThanOriginData))
            {
                var age   = ageWithOffsetInMin(scaledDistribution.Age, parameter.OriginData.Age.Value);
                var value = valueFrom(scaledDistribution, parameter.Percentile);
                tableFormula.AddPoint(age, value, DistributionMetaData.From(scaledDistribution));
            }

            return(tableFormula);
        }
Exemple #2
0
        private TableFormula createTableFormulaFrom(IDistributedParameter individualParameter, IReadOnlyList <ParameterDistributionMetaData> allDistributionsWithAgeStrictBiggerThanOriginData)
        {
            var parameter = new TableFormulaParameter <IDistributedParameter>
            {
                OriginData = _baseOriginData,
                Parameter  = individualParameter,
                Value      = individualParameter.Value,
                Percentile = individualParameter.Percentile
            };

            return(createTableFormulaFrom(parameter, allDistributionsWithAgeStrictBiggerThanOriginData));
        }
        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);
        }
Exemple #4
0
        private void addAgingDataToPopulationSimulation <TParameter>(
            PopulationSimulation populationSimulation,
            string parameterPath,
            TParameter parameter,
            Func <TableFormulaParameter <TParameter>, TableFormula> tableFormulaRetriever) where TParameter : IParameter
        {
            if (populationSimulation == null || !_createAgingDataInPopulationSimulation)
            {
                return;
            }

            var originData     = _baseOriginData.Clone();
            var allAges        = populationSimulation.AllOrganismValuesFor(CoreConstants.Parameters.AGE, _entityPathResolver);
            var allGAs         = populationSimulation.AllOrganismValuesFor(Constants.Parameters.GESTATIONAL_AGE, _entityPathResolver);
            var allHeights     = populationSimulation.AllOrganismValuesFor(CoreConstants.Parameters.HEIGHT, _entityPathResolver);
            var allGender      = populationSimulation.AllGenders(_genderRepository).ToList();
            var allValues      = populationSimulation.AllValuesFor(parameterPath).ToList();
            var allPercentiles = populationSimulation.AllPercentilesFor(parameterPath)
                                 .Select(x => x.CorrectedPercentileValue()).ToList();

            var tableFormulaParameter = new TableFormulaParameter <TParameter> {
                OriginData = originData, Parameter = parameter
            };

            for (int individualIndex = 0; individualIndex < populationSimulation.NumberOfItems; individualIndex++)
            {
                //create origin data for individual i
                originData.Age.Value            = allAges[individualIndex];
                originData.GestationalAge.Value = allGAs[individualIndex];
                originData.Height.Value         = allHeights[individualIndex];
                originData.Gender                = allGender[individualIndex];
                tableFormulaParameter.Value      = allValues[individualIndex];
                tableFormulaParameter.Percentile = allPercentiles[individualIndex];

                var tableFormula = tableFormulaRetriever(tableFormulaParameter);
                if (tableFormula == null)
                {
                    continue;
                }

                populationSimulation.AddAgingTableFormula(parameterPath, individualIndex, tableFormula);
            }
        }
Exemple #5
0
        private void createPopulationHeightTableParameter(
            string heightParameterPath,
            IDistributedParameter meanHeightParameter,
            PopulationSimulation populationSimulation
            )
        {
            if (populationSimulation == null || !_createAgingDataInPopulationSimulation)
            {
                return;
            }

            var originData = _baseOriginData.Clone();
            var allAges    = populationSimulation.AllOrganismValuesFor(CoreConstants.Parameters.AGE, _entityPathResolver);
            var allGAs     = populationSimulation.AllOrganismValuesFor(Constants.Parameters.GESTATIONAL_AGE, _entityPathResolver);
            var allHeights = populationSimulation.AllOrganismValuesFor(CoreConstants.Parameters.HEIGHT, _entityPathResolver);
            var allGender  = populationSimulation.AllGenders(_genderRepository).ToList();

            var tableFormulaParameter = new TableFormulaParameter <IDistributedParameter> {
                OriginData = originData, Parameter = meanHeightParameter
            };

            for (int individualIndex = 0; individualIndex < populationSimulation.NumberOfItems; individualIndex++)
            {
                //create origin data for individual i
                originData.Age.Value            = allAges[individualIndex];
                originData.GestationalAge.Value = allGAs[individualIndex];
                originData.Height.Value         = allHeights[individualIndex];
                originData.Gender           = allGender[individualIndex];
                tableFormulaParameter.Value = originData.Height.Value;

                var heightDistributions = heightDistributionsFor(originData);
                tableFormulaParameter.Percentile = heightDistributions.currentPercentile;

                var distributions = allDistributionsWithAgeStrictBiggerThanOriginData(_allHeightDistributionMaleParameters, _allHeightDistributionFemaleParameters, tableFormulaParameter.OriginData);
                var tableFormula  = createTableFormulaFrom(tableFormulaParameter, distributions);
                if (tableFormula == null)
                {
                    continue;
                }

                populationSimulation.AddAgingTableFormula(heightParameterPath, individualIndex, tableFormula);
            }
        }
Exemple #6
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);
        }