private void addParametersTo <T>(T parameterContainer, OriginData originData, IEnumerable <string> calculationMethods, Func <ParameterMetaData, bool> predicate, IFormulaCache formulaCache = null) where T : IContainer { //RATE PARAMETERS foreach (ParameterRateMetaData parameterRateDefinition in _parameterQuery.ParameterRatesFor(parameterContainer, calculationMethods, predicate)) { //parameter already available, var parameter = _parameterFactory.CreateFor(parameterRateDefinition, formulaCache); if (shouldAddRateParameterTo(parameterContainer, parameter)) { parameterContainer.Add(parameter); } } //CONSTANT PARAMETERS foreach (ParameterValueMetaData parameterDefinition in _parameterQuery.ParameterValuesFor(parameterContainer, originData, predicate)) { parameterContainer.Add(_parameterFactory.CreateFor(parameterDefinition)); } //DISTRIBUTION PARAMETERS foreach (var distributionGroup in _parameterQuery.ParameterDistributionsFor(parameterContainer, originData, predicate).GroupBy(dist => dist.ParameterName)) { var parameter = _parameterFactory.CreateFor(distributionGroup.ToList(), originData); //Parameter might be distributed only for a few species if (parameterContainer.ContainsName(parameter.Name)) { parameterContainer.RemoveChild(parameterContainer.Parameter(parameter.Name)); } parameterContainer.Add(parameter); } }
private void addAgeDependentPercentileValues(ParameterValues parameterValues, RandomPopulation randomPopulation, IDistributedParameter parameter, Individual individual) { var originData = individual.OriginData.Clone(); var allAges = randomPopulation.AllValuesFor(_entityPathResolver.PathFor(individual.Organism.Parameter(CoreConstants.Parameter.AGE))).ToList(); var allGender = randomPopulation.AllGenders.ToList(); var allValues = randomPopulation.AllValuesFor(_entityPathResolver.PathFor(parameter)).ToList(); var allPercentiles = new double[allValues.Count].InitializeWith(0); originData.GestationalAge = CoreConstants.NOT_PRETERM_GESTATIONAL_AGE_IN_WEEKS; //cache female and male distributions originData.Gender = _genderRepository.Female; var allFemalesDistributions = _parameterQuery.ParameterDistributionsFor(parameter.ParentContainer, originData, p => string.Equals(p.ParameterName, parameter.Name)).ToList(); originData.Gender = _genderRepository.Male; var allMaleDistributions = _parameterQuery.ParameterDistributionsFor(parameter.ParentContainer, originData, p => string.Equals(p.ParameterName, parameter.Name)).ToList(); for (int individualIndex = 0; individualIndex < randomPopulation.NumberOfItems; individualIndex++) { //create orgin data for individual i originData.Age = allAges[individualIndex]; var distributions = allFemalesDistributions; if (_genderRepository.Male == allGender[individualIndex]) { distributions = allMaleDistributions; } if (distributions.Count == 0) { allPercentiles[individualIndex] = CoreConstants.DEFAULT_PERCENTILE; } else { allPercentiles[individualIndex] = percentileFrom(distributions, originData, allValues[individualIndex]); } } addPercentileValues(parameterValues, allPercentiles); }