コード例 #1
0
        public RandomPopulationSettings MapFrom(Individual individual)
        {
            //add age first
            var populationSettings = new RandomPopulationSettings();

            if (individual == null)
            {
                return(populationSettings);
            }

            var population = individual.OriginData.SpeciesPopulation;

            populationSettings.BaseIndividual      = individual;
            populationSettings.NumberOfIndividuals = CoreConstants.DEFAULT_NUMBER_OF_INDIVIDUALS_IN_POPULATION;
            int genderCount = individual.AvailableGenders().Count();

            foreach (var gender in individual.AvailableGenders())
            {
                populationSettings.AddGenderRatio(new GenderRatio {
                    Gender = gender, Ratio = 100 / genderCount
                });
            }

            if (population.IsAgeDependent)
            {
                var ageParameter = individual.Organism.Parameter(CoreConstants.Parameter.AGE);
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(ageParameter));
            }

            if (individual.IsPreterm)
            {
                var gestationalAgeParameter = individual.Organism.Parameter(CoreConstants.Parameter.GESTATIONAL_AGE);
                populationSettings.AddParameterRange(discretedParameterRangeFrom(gestationalAgeParameter, numericListOfValues(gestationalAgeParameter)));
            }

            if (population.IsHeightDependent)
            {
                var heightParameter = individual.Organism.Parameter(CoreConstants.Parameter.MEAN_HEIGHT);
                populationSettings.AddParameterRange(parameterRangeFrom(heightParameter));
            }

            var weightParameter = individual.Organism.Parameter(CoreConstants.Parameter.MEAN_WEIGHT);

            if (population.IsAgeDependent)
            {
                populationSettings.AddParameterRange(parameterRangeFrom(weightParameter));
            }
            else
            {
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(weightParameter));
            }

            if (population.IsHeightDependent)
            {
                var bmiParameter = individual.Organism.Parameter(CoreConstants.Parameter.BMI);
                populationSettings.AddParameterRange(parameterRangeFrom(bmiParameter));
            }
            return(populationSettings);
        }
コード例 #2
0
        protected override async Task Context()
        {
            await base.Context();

            _newIndividual = new Individual();
            _newAgeRange   = new ParameterRange {
                ParameterName = CoreConstants.Parameters.AGE
            };
            _newWeightRange = new ParameterRange {
                ParameterName = CoreConstants.Parameters.MEAN_WEIGHT
            };

            _snapshot = await sut.MapToSnapshot(_randomPopulationSettings);

            _snapshot.ProportionOfFemales = _proportionOfFemale;

            A.CallTo(() => _parameterRangeMapper.MapToModel(_snapshot.Age, A <ParameterRangeSnapshotContext> .That.Matches(x => x.ParameterRange == _newAgeRange))).Returns(_newAgeRange);
            A.CallTo(() => _parameterRangeMapper.MapToModel(_snapshot.Weight, A <ParameterRangeSnapshotContext> .That.Matches(x => x.ParameterRange == _newWeightRange))).Returns(_newWeightRange);
            A.CallTo(() => _individualMapper.MapToModel(_snapshotIndividual, _snapshotContext)).Returns(_newIndividual);

            _mappedSettings = new RandomPopulationSettings();
            A.CallTo(() => _populationSettingsMapper.MapFrom(_newIndividual)).Returns(_mappedSettings);
            _mappedSettings.AddParameterRange(_newAgeRange);
            _mappedSettings.AddParameterRange(_newWeightRange);

            _maleRatio = new GenderRatio
            {
                Gender = _genderRepository.Male,
                Ratio  = 50
            };

            _femaleRatio = new GenderRatio
            {
                Gender = _genderRepository.Female,
                Ratio  = 50
            };

            _mappedSettings.AddGenderRatio(_maleRatio);
            _mappedSettings.AddGenderRatio(_femaleRatio);

            _snapshot.DiseaseStateParameters = null;
        }
 protected override void Context()
 {
     base.Context();
     _individual = A.Fake <Individual>();
     A.CallTo(() => _individual.AvailableGenders()).Returns(new List <Gender> {
         _genderRepository.Male, _genderRepository.Female
     });
     _populationSettings                   = new RandomPopulationSettings();
     _batchPopSettings                     = new Batch.PopulationSettings();
     _batchPopSettings.Population          = "Population";
     _batchPopSettings.MinAge              = 25;
     _batchPopSettings.MaxAge              = 40;
     _batchPopSettings.MinGestationalAge   = 30;
     _batchPopSettings.MinHeight           = 10;
     _batchPopSettings.MaxHeight           = 20;
     _batchPopSettings.MinWeight           = double.NaN;
     _batchPopSettings.MaxWeight           = 40;
     _batchPopSettings.MinBMI              = 8;
     _batchPopSettings.MaxBMI              = double.NaN;
     _batchPopSettings.NumberOfIndividuals = 2589;
     _batchPopSettings.ProportionOfFemales = 40;
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.BMI
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.AGE
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.MEAN_HEIGHT
     });
     _populationSettings.AddParameterRange(new ParameterRange {
         ParameterName = CoreConstants.Parameter.MEAN_WEIGHT
     });
     _populationSettings.AddGenderRatio(new GenderRatio {
         Gender = _genderRepository.Male
     });
     _populationSettings.AddGenderRatio(new GenderRatio {
         Gender = _genderRepository.Female
     });
     A.CallTo(() => _individualFactory.CreateStandardFor(A <OriginData> ._)).Returns(_individual);
     A.CallTo(() => _popSettingsMapper.MapFrom(_individual)).Returns(_populationSettings);
 }
        protected override void Context()
        {
            base.Context();
            _individual = A.Fake <Individual>();
            Gender male = new Gender {
                Name = CoreConstants.Gender.Male
            };
            Gender female = new Gender {
                Name = CoreConstants.Gender.Female
            };

            A.CallTo(() => _individual.AvailableGenders()).Returns(new[] { male, female });
            _settings = new RandomPopulationSettings();
            _settings.BaseIndividual = _individual;
            _settings.AddGenderRatio(new GenderRatio {
                Gender = male, Ratio = 100
            });
            _settings.AddGenderRatio(new GenderRatio {
                Gender = female, Ratio = 0
            });
        }
        public RandomPopulationSettings MapFrom(Individual individual)
        {
            var populationSettings = new RandomPopulationSettings();

            if (individual == null)
            {
                return(populationSettings);
            }

            var population = individual.OriginData.Population;

            populationSettings.BaseIndividual      = individual;
            populationSettings.NumberOfIndividuals = CoreConstants.DEFAULT_NUMBER_OF_INDIVIDUALS_IN_POPULATION;

            var genderCount = individual.AvailableGenders.Count;

            foreach (var gender in individual.AvailableGenders)
            {
                populationSettings.AddGenderRatio(new GenderRatio {
                    Gender = gender, Ratio = 100 / genderCount
                });
            }

            var organism = individual.Organism;

            if (individual.IsAgeDependent)
            {
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(organism.Parameter(AGE)));
            }

            if (individual.IsPreterm)
            {
                var gestationalAgeParameter = organism.Parameter(GESTATIONAL_AGE);
                populationSettings.AddParameterRange(discreteParameterRangeFrom(gestationalAgeParameter, numericListOfValues(gestationalAgeParameter)));
            }

            var weightParameter = organism.Parameter(MEAN_WEIGHT);

            populationSettings.AddParameterRange(population.IsAgeDependent ? parameterRangeFrom(weightParameter) : constrainedParameterRangeFrom(weightParameter));

            if (population.IsHeightDependent)
            {
                populationSettings.AddParameterRange(parameterRangeFrom(organism.Parameter(MEAN_HEIGHT)));
                populationSettings.AddParameterRange(parameterRangeFrom(organism.Parameter(BMI)));
            }

            individual.OriginData.DiseaseStateParameters.Each(x =>
            {
                var parameter = individual.OriginData.DiseaseState.Parameter(x.Name);
                populationSettings.AddParameterRange(constrainedParameterRangeFrom(parameter));
            });
            return(populationSettings);
        }
        protected override void Context()
        {
            base.Context();
            _individual = A.Fake <Individual>();
            _settings   = new RandomPopulationSettings();
            A.CallTo(() => _individualToPopulationSettingsMapper.MapFrom(_individual)).Returns(_settings);
            var male = new Gender {
                Name = CoreConstants.Gender.MALE
            };
            var female = new Gender {
                Name = CoreConstants.Gender.FEMALE
            };

            _settings.BaseIndividual = _individual;
            _settings.AddGenderRatio(new GenderRatio {
                Gender = male, Ratio = 100
            });
            _settings.AddGenderRatio(new GenderRatio {
                Gender = female, Ratio = 0
            });
        }
コード例 #7
0
        protected override async Task Context()
        {
            await base.Context();

            _newIndividual = new Individual();

            _snapshot = await sut.MapToSnapshot(_randomPopulationSettings);

            _snapshot.ProportionOfFemales = null;
            A.CallTo(() => _individualMapper.MapToModel(_snapshotIndividual)).Returns(_newIndividual);

            _mappedSettings = new RandomPopulationSettings();
            A.CallTo(() => _populationSettingsMapper.MapFrom(_newIndividual)).Returns(_mappedSettings);
            _unknownGender = new GenderRatio
            {
                Gender = new Gender {
                    Id = "Gender"
                },
                Ratio = 100
            };
            _mappedSettings.AddGenderRatio(_unknownGender);
        }
コード例 #8
0
        public RandomPopulationSettings MapFrom(PopulationSettingsDTO populationSettingsDTO)
        {
            var populationSettings = new RandomPopulationSettings();

            populationSettings.BaseIndividual      = _cloner.Clone(populationSettingsDTO.Individual);
            populationSettings.NumberOfIndividuals = populationSettingsDTO.NumberOfIndividuals.ConvertedTo <int>();

            //first add one gender with ration 100 for each available gender
            populationSettingsDTO.AvailableGenders().Each(g => populationSettings.AddGenderRatio(new GenderRatio {
                Gender = g, Ratio = 100
            }));

            //in case of multiple gender, adjust the ration according to the feamales proportion
            if (populationSettingsDTO.HasMultipleGenders)
            {
                populationSettings.GenderRatio(populationSettingsDTO.Female).Ratio = populationSettingsDTO.ProportionOfFemales;
                populationSettings.GenderRatio(populationSettingsDTO.Male).Ratio   = 100 - populationSettingsDTO.ProportionOfFemales;
            }

            populationSettingsDTO.Parameters.Each(p => populationSettings.AddParameterRange(p.ParameterRange));
            return(populationSettings);
        }