Skip to content

Commit

Permalink
Revisions from reviewer comments
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewgthomas committed Feb 25, 2015
1 parent 255373b commit ace1552
Show file tree
Hide file tree
Showing 8 changed files with 290 additions and 55 deletions.
28 changes: 28 additions & 0 deletions Optimal Birth Intervals/App.config
Original file line number Diff line number Diff line change
@@ -1,8 +1,36 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Optimal_Birth_Intervals.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Optimal_Birth_Intervals.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<appSettings>
<!--<add key="WorkingDir" value="D:\Data\Birth Intervals\"/> -->
<!-- "C:\Anth\Birth Intervals\" <- laptop -->
<!-- "D:\Data\Birth Intervals\" <- anth computer -->
</appSettings>
<userSettings>
<Optimal_Birth_Intervals.Properties.Settings>
<setting name="MaxAge" serializeAs="String">
<value>50</value>
</setting>
<setting name="ProbabilisticAFB" serializeAs="String">
<value>False</value>
</setting>
</Optimal_Birth_Intervals.Properties.Settings>
</userSettings>
<applicationSettings>
<Optimal_Birth_Intervals.Properties.Settings>
<setting name="ForwardIterations" serializeAs="String">
<value>150</value>
</setting>
<setting name="MaternalMortalityFunc" serializeAs="String">
<value>J</value>
</setting>
</Optimal_Birth_Intervals.Properties.Settings>
</applicationSettings>
</configuration>
165 changes: 116 additions & 49 deletions Optimal Birth Intervals/BirthIntervals.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ partial class BirthIntervals
{
#region Constants
int numFamilies = 987;
const int motherAgeMax = 91;
int motherArrayMax = 76;
const int maxTback = 75;
int motherAgeMax = 91;
int motherArrayMax = 76; // calculated from motherAgeMax
//const int maxTback = 75; // not needed -- model runs to convergence
const int maxTforward = 150;

int ageAtMaturity;
int ageAtMaturity; // this is calculated by importFamiliesFromString() from the family structures in families.txt

const string appWorkingDir = @"WorkingDir";
#endregion
Expand Down Expand Up @@ -92,13 +92,16 @@ partial class BirthIntervals
// Read in family structures and initialise fitness/decision arrays
public BirthIntervals()
{
// start by importing family structures and calculating a lookup table for them
importFamiliesFromString();
CalculateLookupTable();

// before initialising arrays, set some global variables
motherAgeMax = Properties.Settings.Default.MaxAge + 1; // add 1 because we don't want death state in output array
numFamilies = family.Count;
motherArrayMax = motherAgeMax - ageAtMaturity;

// set up fitness and strategy arrays
InitialiseArrays();
InitialisePopulationGrowthRate();

Expand Down Expand Up @@ -398,21 +401,26 @@ double calcSurvChild(int motherAge, int[] currentFamily, bool giveBirth, int chi
// only those 10 and over can help
if (age >= 10)
{
double helpModifier = 5.0; // or 10.0 (originally)

switch (siblingHelp)
{
case MortalityParam.None:
break;

case MortalityParam.Low:
weight -= 0.1;
//weight -= 0.1;
weight += (double)(.5 - (age * .03333)) * -1.0;
break;

case MortalityParam.Medium:
weight += (double)(-.5 * (age - 10.0) / 10.0);
//weight += (double)(-.5 * (age - 10.0) / helpModifier);
weight += (double)(1 - (age * .06666)) * -1.0;
break;

case MortalityParam.High:
weight += (double)(-1.0 * (age - 10.0) / 10.0);
//weight += (double)(-1.0 * (age - 10.0) / helpModifier);
weight += (double)(1 - (age * 0.0357)) * -1.0;
break;
}
}
Expand Down Expand Up @@ -445,62 +453,86 @@ double calcSurvMother(int motherAge, int[] currentFamily, bool giveBirth, int fa
/* Maternal mortality in childbirth
* These parameters get varied for no increase with age, or a low, medium and high age-related increase as shown in Figure 1b
*/
double alphaBirth = 0.0, betaBirth = 0.0, gammaBirth = 0.0;

switch (childbirthMortality)
if (giveBirth && childbirthMortality != MortalityParam.None)
{
case MortalityParam.None:
alphaBirth = 0.0;
betaBirth = 0.0;
gammaBirth = 0.0;
break;

case MortalityParam.Low:
// values from Blanc et al. 2013
alphaBirth = 1.424218e-05;
betaBirth = 5.415419e-04;
gammaBirth = 7.492639e-03;
break;

case MortalityParam.Medium:
// values from Blanc et al. 2013
alphaBirth = 1.394538e-05;
betaBirth = 5.268179e-04;
gammaBirth = 8.448535e-03;
break;

case MortalityParam.High:
// values from Blanc et al. 2013
alphaBirth = 1.236674e-05;
betaBirth = 4.478437e-04;
gammaBirth = 9.056053e-03;
break;
muBirth = calcMaternalMortality(motherAge);
}

/* MORALITY RISK DUE TO CHILDBIRTH
/* calculate survival
* Constant value is the extrinsic adult mortality rate.
*/
double initialRiskChildbirthMortality = 0.0;
double muExtrinsic = silerA2;
memoSurvival = Math.Exp((-1.0 * muExtrinsic) - muSen - muBirth);

if (giveBirth)
// and return survival
return memoSurvival;
}

// returns the mother's probability of dying during childbirth given her age
private double calcMaternalMortality(int motherAge)
{
double muBirth = 0.0;
double alphaBirth = 0.0, betaBirth = 0.0, gammaBirth = 0.0;

// calculate maternal morality
// J-shaped maternal mortality ratios from Blanc et al. (2013)
// (http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0059864)
if (Properties.Settings.Default.MaternalMortalityFunc == "J")
{
if (childbirthMortality == MortalityParam.None)
// what level of maternal mortality?
switch (childbirthMortality)
{
muBirth = 0.0;
case MortalityParam.Low:
alphaBirth = 1.424218e-05;
betaBirth = 5.415419e-04;
gammaBirth = 7.492639e-03;
break;

case MortalityParam.Medium:
alphaBirth = 1.394538e-05;
betaBirth = 5.268179e-04;
gammaBirth = 8.448535e-03;
break;

case MortalityParam.High:
alphaBirth = 1.236674e-05;
betaBirth = 4.478437e-04;
gammaBirth = 9.056053e-03;
break;
}

// Maternal mortality ratios from Blanc et al. 2013 (http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0059864)
// a * (age^2) - b * age + c
muBirth = (alphaBirth * Math.Pow(motherAge, 2)) - (betaBirth * motherAge) + gammaBirth;
}

/* calculate survival
* Constant value is the extrinsic adult mortality rate.
*/
double muExtrinsic = silerA2;
memoSurvival = Math.Exp((-1.0 * muExtrinsic) - muSen - muBirth);
// Exponential maternal mortality fitted from Grimes (1994)
// as used in from Shanley et al. (2007)
else if (Properties.Settings.Default.MaternalMortalityFunc == "E")
{
// what level of maternal mortality?
switch (childbirthMortality)
{
case MortalityParam.Low:
alphaBirth = 0.002928;
betaBirth = 0.1;
break;

// and return survival
return memoSurvival;
case MortalityParam.Medium:
alphaBirth = 0.000485;
betaBirth = 0.181221;
break;

case MortalityParam.High:
alphaBirth = 1e-6;
betaBirth = 0.5;
break;
}

// (a * Exp(b * (age - ageAtMaturity))) + (silerA2 - a)
muBirth = (alphaBirth * Math.Exp(betaBirth * (motherAge - ageAtMaturity))) + (silerA2 - alphaBirth);
}

return muBirth;
}
#endregion

Expand Down Expand Up @@ -556,6 +588,41 @@ private void exploreStateSpace()
}
}
}

public double TeenageSubfecundityProbability(int motherAge)
{
double pBirth = 1;

// assign probabilities of giving birth
// linear from 0.25 at age 15 to 1.0 at age 20 -- y = 0.25 + 0.15.x
switch (motherAge)
{
case 15:
pBirth = 0.25;
break;

case 16:
pBirth = 0.4; //0.5;
break;

case 17:
pBirth = 0.55; //0.75;
break;

case 18:
pBirth = 0.7;
break;

case 19:
pBirth = 0.85;
break;

default:
break;
}

return pBirth;
}
#endregion

#region File import methods
Expand Down
14 changes: 14 additions & 0 deletions Optimal Birth Intervals/ForwardIteration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,20 @@ void findFMax(int motherAge, int familyIndex, int arrayIndex)
if (births[arrayIndex][familyIndex] == true)
giveBirth = true;

// probabilistic age at first birth (teenage sub-fecundity)?
if (Properties.Settings.Default.ProbabilisticAFB && motherAge < 20) // only if mother is younger than 20
{
double pBirth = TeenageSubfecundityProbability(motherAge);

Random rnd = new Random();
if (rnd.NextDouble() >= pBirth)
{
// do not give birth this year
giveBirth = false;
births[arrayIndex][familyIndex] = false;
}
}

// calculate fitness based on mother's age, current family structure and optimal birth decision
FwdCalcF(motherAge, family[familyIndex].ToArray(), familyIndex, arrayIndex, giveBirth);
}
Expand Down
9 changes: 9 additions & 0 deletions Optimal Birth Intervals/Optimal Birth Intervals.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,21 @@
<Compile Include="PowerSet.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Properties\Settings.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<DependentUpon>Settings.settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Include="App.config">
<SubType>Designer</SubType>
</None>
<EmbeddedResource Include="fam.in" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="families.txt" />
Expand Down
7 changes: 1 addition & 6 deletions Optimal Birth Intervals/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,10 +395,6 @@ private static MortalityParam parseArgs(string arg)
returnedValue = MortalityParam.Low;
break;

case "J":
returnedValue = MortalityParam.Jshaped;
break;

default:
returnedValue = MortalityParam.None;
break;
Expand All @@ -414,7 +410,6 @@ enum MortalityParam
None,
High,
Medium,
Low,
Jshaped
Low
}
}
36 changes: 36 additions & 0 deletions Optimal Birth Intervals/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Optimal Birth Intervals")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Microsoft")]
[assembly: AssemblyProduct("Optimal Birth Intervals")]
[assembly: AssemblyCopyright("Copyright © Microsoft 2012")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bc201870-d084-41a3-aeb2-db578107a540")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
Loading

0 comments on commit ace1552

Please sign in to comment.