Skip to content

Commit

Permalink
Merge pull request #316 from mstevens-uk/ICDF
Browse files Browse the repository at this point in the history
Converted Param.h icdf arrays from double array to InverseCdf class
  • Loading branch information
weshinsley authored Jun 19, 2020
2 parents fa11c42 + 2839d99 commit 863389f
Show file tree
Hide file tree
Showing 7 changed files with 165 additions and 82 deletions.
4 changes: 3 additions & 1 deletion covid-sim.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<ClCompile Include="src\MicroCellPosition.cpp" />
<ClCompile Include="src\Direction.cpp" />
<ClCompile Include="src\Geometry\Vector2.cpp" />
<ClCompile Include="src\InverseCdf.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\BinIO.h" />
Expand Down Expand Up @@ -133,8 +134,9 @@
<ClInclude Include="src\Models\Household.h" />
<ClInclude Include="src\Models\Microcell.h" />
<ClInclude Include="src\Models\Person.h" />
<ClInclude Include="src\InverseCdf.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>
</Project>
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# CMakeLists.txt for src directory

# Set up the IDE
set(MAIN_SRC_FILES CovidSim.cpp BinIO.cpp Rand.cpp Error.cpp Dist.cpp Kernels.cpp Bitmap.cpp SetupModel.cpp CalcInfSusc.cpp Sweep.cpp Update.cpp Param.cpp MicroCellPosition.cpp Direction.cpp)
set(MAIN_HDR_FILES CovidSim.h BinIO.h Rand.h Constants.h Country.h Error.h Dist.h Kernels.h Bitmap.h Model.h Param.h SetupModel.h ModelMacros.h InfStat.h CalcInfSusc.h Sweep.h Update.h MicroCellPosition.hpp Direction.hpp)
set(MAIN_SRC_FILES CovidSim.cpp BinIO.cpp Rand.cpp Error.cpp Dist.cpp Kernels.cpp Bitmap.cpp SetupModel.cpp CalcInfSusc.cpp Sweep.cpp Update.cpp Param.cpp MicroCellPosition.cpp Direction.cpp InverseCdf.cpp)
set(MAIN_HDR_FILES CovidSim.h BinIO.h Rand.h Constants.h Country.h Error.h Dist.h Kernels.h Bitmap.h Model.h Param.h SetupModel.h ModelMacros.h InfStat.h CalcInfSusc.h Sweep.h Update.h MicroCellPosition.hpp Direction.hpp InverseCdf.h)
source_group(covidsim\\main FILES ${MAIN_SRC_FILES} ${MAIN_HDR_FILES})

# CovidSim target
Expand Down
79 changes: 30 additions & 49 deletions src/CovidSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,6 @@ int GetInputParameter2(FILE*, FILE*, const char*, const char*, void*, int, int,
int GetInputParameter2all(FILE*, FILE*, FILE*, const char*, const char*, void*, int, int, int);
int GetInputParameter3(FILE*, const char*, const char*, void*, int, int, int);

void SetICDF(double* icdf, double startValue);


///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** /////
///// ***** ///// ***** ///// ***** ///// ***** ///// ***** GLOBAL VARIABLES (some structures in CovidSim.h file and some containers) - memory allocated later.
///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** ///// ***** /////
Expand Down Expand Up @@ -110,8 +107,11 @@ int PlaceDistDistrib[NUM_PLACE_TYPES][MAX_DIST], PlaceSizeDistrib[NUM_PLACE_TYPE
/* int NumPC,NumPCD; */
const int MAXINTFILE = 10;

/* default start value for icdf arrays */
const int ICDF_START = 100;
// default start value for icdf double arrays (was hardcoded as 100)
const double ICDF_START = 100.0;

void GetInverseCdf(FILE* param_file_dat, FILE* preparam_file_dat, const char* icdf_name, InverseCdf* inverseCdf,
double start_value = ICDF_START);

int main(int argc, char* argv[])
{
Expand Down Expand Up @@ -1027,30 +1027,25 @@ void ReadParams(char* ParamFile, char* PreParamFile)
}
s /= ((double)k);
for (i = 0; i <= k; i++) P.infectiousness[i] /= s;
for (i = 0; i <= CDF_RES; i++) P.infectious_icdf[i] = exp(-1.0);
P.infectious_icdf.assign_exponent(-1.0);
}
else
{
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Infectious period inverse CDF", "%lf", (void*)P.infectious_icdf, CDF_RES + 1, 1, 0))
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Infectious period inverse CDF", "%lf", (void*)P.infectious_icdf.get_values(), CDF_RES + 1, 1, 0))
{
SetICDF(P.infectious_icdf, ICDF_START);
P.infectious_icdf.set_neg_log(ICDF_START);
}
k = (int)ceil(P.InfectiousPeriod * P.infectious_icdf[CDF_RES] / P.TimeStep);
if (k >= MAX_INFECTIOUS_STEPS) ERR_CRITICAL("MAX_INFECTIOUS_STEPS not big enough\n");
for (i = 0; i < k; i++) P.infectiousness[i] = 1.0;
P.infectiousness[k] = 0;
for (i = 0; i <= CDF_RES; i++) P.infectious_icdf[i] = exp(-P.infectious_icdf[i]);
P.infectious_icdf.assign_exponent();
}
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include latent period", "%i", (void*) & (P.DoLatent), 1, 1, 0)) P.DoLatent = 0;
if (P.DoLatent)
{
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Latent period", "%lf", (void*) & (P.LatentPeriod), 1, 1, 0);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Latent period inverse CDF", "%lf", (void*)P.latent_icdf, CDF_RES + 1, 1, 0))
{
SetICDF(P.latent_icdf, 1e10);
}
for (i = 0; i <= CDF_RES; i++)
P.latent_icdf[i] = exp(-P.latent_icdf[i]);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "Latent period inverse CDF", &P.latent_icdf, 1e10);
}

if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Include symptoms", "%i", (void*) & (P.DoSymptoms), 1, 1, 0)) P.DoSymptoms = 0;
Expand Down Expand Up @@ -1165,32 +1160,18 @@ void ReadParams(char* ParamFile, char* PreParamFile)
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_SARIToDeath", "%lf", (void*)(P.Mean_SARIToDeath), NUM_AGE_GROUPS, 1, 0);
GetInputParameter(ParamFile_dat, PreParamFile_dat, "Mean_CriticalToDeath", "%lf", (void*)(P.Mean_CriticalToDeath), NUM_AGE_GROUPS, 1, 0);
}
//// Get ICDFs
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "MildToRecovery_icdf" , "%lf", (void*)P.MildToRecovery_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.MildToRecovery_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToRecovery_icdf" , "%lf", (void*)P.ILIToRecovery_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.ILIToRecovery_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToDeath_icdf" , "%lf", (void*)P.ILIToDeath_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.ILIToDeath_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToRecovery_icdf" , "%lf", (void*)P.SARIToRecovery_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.SARIToRecovery_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CriticalToCritRecov_icdf" , "%lf", (void*)P.CriticalToCritRecov_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.CriticalToCritRecov_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CritRecovToRecov_icdf" , "%lf", (void*)P.CritRecovToRecov_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.CritRecovToRecov_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "ILIToSARI_icdf" , "%lf", (void*)P.ILIToSARI_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.ILIToSARI_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToCritical_icdf" , "%lf", (void*)P.SARIToCritical_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.SARIToCritical_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "SARIToDeath_icdf" , "%lf", (void*)P.SARIToDeath_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.SARIToDeath_icdf , ICDF_START);
if (!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "CriticalToDeath_icdf" , "%lf", (void*)P.CriticalToDeath_icdf , CDF_RES + 1, 1, 0)) SetICDF(P.CriticalToDeath_icdf , ICDF_START);

// exponentiate
for (int quantile = 0; quantile <= CDF_RES; quantile++)
{
P.MildToRecovery_icdf [quantile] = exp(- P.MildToRecovery_icdf [quantile]);
P.ILIToRecovery_icdf [quantile] = exp(- P.ILIToRecovery_icdf [quantile]);
P.ILIToDeath_icdf [quantile] = exp(- P.ILIToDeath_icdf [quantile]);
P.ILIToSARI_icdf [quantile] = exp(- P.ILIToSARI_icdf [quantile]);
P.SARIToRecovery_icdf [quantile] = exp(- P.SARIToRecovery_icdf [quantile]);
P.SARIToDeath_icdf [quantile] = exp(- P.SARIToDeath_icdf [quantile]);
P.SARIToCritical_icdf [quantile] = exp(- P.SARIToCritical_icdf [quantile]);
P.CriticalToCritRecov_icdf [quantile] = exp(- P.CriticalToCritRecov_icdf [quantile]);
P.CritRecovToRecov_icdf [quantile] = exp(- P.CritRecovToRecov_icdf [quantile]);
P.CriticalToDeath_icdf [quantile] = exp(- P.CriticalToDeath_icdf [quantile]);
}

//// Get InverseCDFs
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "MildToRecovery_icdf", &P.MildToRecovery_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "ILIToRecovery_icdf", &P.ILIToRecovery_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "ILIToDeath_icdf", &P.ILIToDeath_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "SARIToRecovery_icdf", &P.SARIToRecovery_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "CriticalToCritRecov_icdf", &P.CriticalToCritRecov_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "CritRecovToRecov_icdf", &P.CritRecovToRecov_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "ILIToSARI_icdf", &P.ILIToSARI_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "SARIToCritical_icdf", &P.SARIToCritical_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "SARIToDeath_icdf", &P.SARIToDeath_icdf);
GetInverseCdf(ParamFile_dat, PreParamFile_dat, "CriticalToDeath_icdf", &P.CriticalToDeath_icdf);

if(!GetInputParameter2(ParamFile_dat, PreParamFile_dat, "Prop_Mild_ByAge", "%lf", (void*)P.Prop_Mild_ByAge, NUM_AGE_GROUPS, 1, 0))
for(i = 0; i < NUM_AGE_GROUPS; i++)
Expand Down Expand Up @@ -5749,14 +5730,14 @@ int GetInputParameter3(FILE* dat, const char* SItemName, const char* ItemType, v
return FindFlag;
}

/* helper function to set icdf arrays */
void SetICDF(double* icdf, double startValue)

void GetInverseCdf(FILE* param_file_dat, FILE* preparam_file_dat, const char* icdf_name, InverseCdf* inverseCdf,
double start_value)
{
icdf[CDF_RES] = startValue;
for (int i = 0; i < CDF_RES; i++)
icdf[i] = -log(1 - ((double)i) / CDF_RES);
if (!GetInputParameter2(param_file_dat, preparam_file_dat, icdf_name, "%lf", (void*)inverseCdf->get_values(), CDF_RES + 1, 1, 0))
{
inverseCdf->set_neg_log(start_value);
}
inverseCdf->assign_exponent();
}




77 changes: 77 additions & 0 deletions src/InverseCdf.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#include "InverseCdf.h"
#include <cmath>
#include "Rand.h"


/**
* Function: set_neg_log
*
* Purpose: set defaults if not present in parameter file
* @param start_value - the value to use for cdf_values_[CDF_RES]
* @return void
*/
void InverseCdf::set_neg_log(double start_value)
{
cdf_values_[CDF_RES] = start_value;
for (int i = 0; i < CDF_RES; i++)
cdf_values_[i] = -log(1 - ((double)i) / CDF_RES);
}

/**
* Function: assign_exponent
*
* Purpose: exponentiate each quantile
* @return void
*/
void InverseCdf::assign_exponent()
{
for (int quantile = 0; quantile <= CDF_RES; quantile++)
{
cdf_values_[quantile] = exp(-cdf_values_[quantile]);
}
}


/**
* Function: assign_exponent
*
* Purpose: exponentiate each quantile
* @param value - value of the exponent
* @return void
*/
void InverseCdf::assign_exponent(double value)
{
for (int i = 0; i <= CDF_RES; i++)
{
cdf_values_[i] = exp(value);
}
}


/**
* Function: choose
*
* Purpose: choose a value from the InverseCdf data
* @param Mean
* @param tn - thread number
* @param timesteps_per_day
* @return value chosen from InverseCdf data
*/
unsigned short int InverseCdf::choose(double Mean, int tn, double timesteps_per_day)
{
unsigned short int Value;
int i;
double q, ti;

i = (int)floor(q = ranf_mt(tn) * CDF_RES); //// note q defined here as well as i.
q -= ((double)i); //// remainder

//// weighted average (sort of) between quartile values from CDF_RES. logged as it was previously exponentiated in ReadParams. Minus as exp(-cdf) was done in ReadParaams. Sort of
ti = -Mean * log(q * cdf_values_[i + 1] + (1.0 - q) * cdf_values_[i]);
Value = (unsigned short int) floor(0.5 + (ti * timesteps_per_day));

return Value;
}



34 changes: 34 additions & 0 deletions src/InverseCdf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#pragma once

#include "Constants.h"

class InverseCdf
{
double cdf_values_[CDF_RES + 1];

public:

void set_neg_log(double start_value);

void assign_exponent();

void assign_exponent(double value);

unsigned short int choose(double Mean, int tn, double timesteps_per_day);

// Getter
double* get_values()
{
return cdf_values_;
}

// Overloading [] operator to access elements in array style
double& operator[](int i)
{
return cdf_values_[i];
}
};




10 changes: 7 additions & 3 deletions src/Param.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "Country.h"
#include "Constants.h"
#include "InverseCdf.h"
#include "MicroCellPosition.hpp"

#include "Geometry/Size.h"
Expand Down Expand Up @@ -82,10 +83,13 @@ struct Param
double LongitudeCutLine; // Longitude to image earth is cut at to produce a flat map. Default -360 degrees (effectively -180). Use to ensure countries have a contiguous boundary
double SpatialBoundingBox[4], LocationInitialInfection[MAX_NUM_SEED_LOCATIONS][2], InitialInfectionsAdminUnitWeight[MAX_NUM_SEED_LOCATIONS], TimeStepsPerDay;
double FalsePositiveRate, FalsePositivePerCapitaIncidence, FalsePositiveAgeRate[NUM_AGE_GROUPS];
double latent_icdf[CDF_RES + 1], infectious_icdf[CDF_RES + 1], infectious_prof[INFPROF_RES + 1], infectiousness[MAX_INFECTIOUS_STEPS];
double infectious_prof[INFPROF_RES + 1], infectiousness[MAX_INFECTIOUS_STEPS];

// use the wrapper class InverseCdf instead of the raw data type to enable code re-use
InverseCdf latent_icdf, infectious_icdf;
InverseCdf MildToRecovery_icdf, ILIToRecovery_icdf, SARIToRecovery_icdf, CriticalToCritRecov_icdf, CritRecovToRecov_icdf;
InverseCdf ILIToSARI_icdf, SARIToCritical_icdf, ILIToDeath_icdf, SARIToDeath_icdf, CriticalToDeath_icdf;

double MildToRecovery_icdf[CDF_RES + 1], ILIToRecovery_icdf[CDF_RES + 1], SARIToRecovery_icdf[CDF_RES + 1], CriticalToCritRecov_icdf[CDF_RES + 1], CritRecovToRecov_icdf[CDF_RES + 1];
double ILIToSARI_icdf[CDF_RES + 1], SARIToCritical_icdf[CDF_RES + 1], ILIToDeath_icdf[CDF_RES + 1], SARIToDeath_icdf[CDF_RES + 1], CriticalToDeath_icdf[CDF_RES + 1];
/// means for above icdf's.
double Mean_MildToRecovery[NUM_AGE_GROUPS], Mean_ILIToRecovery[NUM_AGE_GROUPS], Mean_SARIToRecovery[NUM_AGE_GROUPS], Mean_CriticalToCritRecov[NUM_AGE_GROUPS], Mean_CritRecovToRecov[NUM_AGE_GROUPS];
double Mean_TimeToTest, Mean_TimeToTestOffset, Mean_TimeToTestCriticalOffset, Mean_TimeToTestCritRecovOffset;
Expand Down
39 changes: 12 additions & 27 deletions src/Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ using namespace Geometry;
//adding function to record an event: ggilani - 10/10/2014
void RecordEvent(double, int, int, int, int); //added int as argument to InfectSweep to record run number: ggilani - 15/10/14

unsigned short int ChooseFromICDF(double *, double, int);
Severity ChooseFinalDiseaseSeverity(int, int);

// state transition helpers
Expand Down Expand Up @@ -471,7 +470,7 @@ void DoIncub(int ai, unsigned short int ts, int tn, int run)
if (!P.DoSeverity || a->inf == InfStat_InfectiousAsymptomaticNotCase) //// if not doing severity or if person asymptomatic.
{
if (P.DoInfectiousnessProfile) a->recovery_or_death_time = a->latent_time + (unsigned short int) (P.InfectiousPeriod * P.TimeStepsPerDay);
else a->recovery_or_death_time = a->latent_time + ChooseFromICDF(P.infectious_icdf, P.InfectiousPeriod, tn);
else a->recovery_or_death_time = a->latent_time + P.infectious_icdf.choose(P.InfectiousPeriod, tn, P.TimeStepsPerDay);
}
else
{
Expand All @@ -488,33 +487,33 @@ void DoIncub(int ai, unsigned short int ts, int tn, int run)

//// choose events and event times
if (a->Severity_Final == Severity_Mild)
a->recovery_or_death_time = CaseTime + ChooseFromICDF(P.MildToRecovery_icdf, P.Mean_MildToRecovery[age], tn);
a->recovery_or_death_time = CaseTime + P.MildToRecovery_icdf.choose(P.Mean_MildToRecovery[age], tn, P.TimeStepsPerDay);
else if (a->Severity_Final == Severity_Critical)
{
a->SARI_time = CaseTime + ChooseFromICDF(P.ILIToSARI_icdf , P.Mean_ILIToSARI[age], tn);
a->Critical_time = a->SARI_time + ChooseFromICDF(P.SARIToCritical_icdf , P.Mean_SARIToCritical[age], tn);
a->SARI_time = CaseTime + P.ILIToSARI_icdf.choose(P.Mean_ILIToSARI[age], tn, P.TimeStepsPerDay);
a->Critical_time = a->SARI_time + P.SARIToCritical_icdf.choose(P.Mean_SARIToCritical[age], tn, P.TimeStepsPerDay);
if (a->to_die)
a->recovery_or_death_time = a->Critical_time + ChooseFromICDF(P.CriticalToDeath_icdf , P.Mean_CriticalToDeath[age], tn);
a->recovery_or_death_time = a->Critical_time + P.CriticalToDeath_icdf.choose(P.Mean_CriticalToDeath[age], tn, P.TimeStepsPerDay);
else
{
a->RecoveringFromCritical_time = a->Critical_time + ChooseFromICDF(P.CriticalToCritRecov_icdf , P.Mean_CriticalToCritRecov[age], tn);
a->recovery_or_death_time = a->RecoveringFromCritical_time + ChooseFromICDF(P.CritRecovToRecov_icdf , P.Mean_CritRecovToRecov[age], tn);
a->RecoveringFromCritical_time = a->Critical_time + P.CriticalToCritRecov_icdf.choose(P.Mean_CriticalToCritRecov[age], tn, P.TimeStepsPerDay);
a->recovery_or_death_time = a->RecoveringFromCritical_time + P.CritRecovToRecov_icdf.choose(P.Mean_CritRecovToRecov[age], tn, P.TimeStepsPerDay);
}
}
else if (a->Severity_Final == Severity_SARI)
{
a->SARI_time = CaseTime + ChooseFromICDF(P.ILIToSARI_icdf, P.Mean_ILIToSARI[age], tn);
a->SARI_time = CaseTime + P.ILIToSARI_icdf.choose(P.Mean_ILIToSARI[age], tn, P.TimeStepsPerDay);
if (a->to_die)
a->recovery_or_death_time = a->SARI_time + ChooseFromICDF(P.SARIToDeath_icdf , P.Mean_SARIToDeath[age], tn);
a->recovery_or_death_time = a->SARI_time + P.SARIToDeath_icdf.choose(P.Mean_SARIToDeath[age], tn, P.TimeStepsPerDay);
else
a->recovery_or_death_time = a->SARI_time + ChooseFromICDF(P.SARIToRecovery_icdf , P.Mean_SARIToRecovery[age], tn);
a->recovery_or_death_time = a->SARI_time + P.SARIToRecovery_icdf.choose(P.Mean_SARIToRecovery[age], tn, P.TimeStepsPerDay);
}
else /*i.e. if Severity_Final == Severity_ILI*/
{
if (a->to_die)
a->recovery_or_death_time = CaseTime + ChooseFromICDF(P.ILIToDeath_icdf , P.Mean_ILIToDeath[age], tn);
a->recovery_or_death_time = CaseTime + P.ILIToDeath_icdf.choose(P.Mean_ILIToDeath[age], tn, P.TimeStepsPerDay);
else
a->recovery_or_death_time = CaseTime + ChooseFromICDF(P.ILIToRecovery_icdf , P.Mean_ILIToRecovery[age], tn);
a->recovery_or_death_time = CaseTime + P.ILIToRecovery_icdf.choose(P.Mean_ILIToRecovery[age], tn, P.TimeStepsPerDay);
}
}

Expand Down Expand Up @@ -1377,20 +1376,6 @@ Severity ChooseFinalDiseaseSeverity(int AgeGroup, int tn)
return DiseaseSeverity;
}

unsigned short int ChooseFromICDF(double *ICDF, double Mean, int tn)
{
unsigned short int Value;
int i;
double q, ti;

i = (int)floor(q = ranf_mt(tn) * CDF_RES); //// note q defined here as well as i.
q -= ((double)i); //// remainder
ti = -Mean * log(q * ICDF[i + 1] + (1.0 - q) * ICDF[i]); //// weighted average (sort of) between quartile values from CDF_RES. logged as it was previously exponentiated in ReadParams. Minus as exp(-cdf) was done in ReadParaams. Sort of
Value = (unsigned short int) floor(0.5 + (ti * P.TimeStepsPerDay));

return Value;
}

void SusceptibleToRecovered(int cellIndex)
{
Cells[cellIndex].S--;
Expand Down

0 comments on commit 863389f

Please sign in to comment.