def simulate(self, sim_length): """ simulate patient over specified simulation length """ # random number generated for patient self._rng = RndCls.RNG(self._id) k = 0 # current time step # while patient is alive and simulation length not yet reached while self._stateMonitor.get_if_alive( ) and k * self._delta_t < sim_length: # find the transition probabilities of the future states trans_probs = self._parameters.get_transition_prob( self._stateMonitor.get_current_state()) # create empirical distribution empirical_dist = RndCls.Empirical(trans_probs) # sample from empirical distribution to get new state (returns an integer) new_state_index = empirical_dist.sample(self._rng) # update health state self._stateMonitor.update(k, Parameters.HealthStates(new_state_index)) # increment time step k += 1
def simulate(self, sim_length): """ simulate the patient over the specified simulation length """ # random number generator for this patient self._rng = rndClasses.RNG(self._id) k = 0 # current time step # while the patient is alive and simulation length is not yet reached while self._stateMonitor.get_if_alive( ) and k * self._delta_t < sim_length: # find the transition probabilities of the future states trans_probs = self._param.get_transition_prob( self._stateMonitor.get_current_state()) # create an empirical distribution empirical_dist = rndClasses.Empirical(trans_probs) # sample from the empirical distribution to get a new state # (returns an integer from {0, 1, 2, ...}) new_state_index = empirical_dist.sample(self._rng) # update health state self._stateMonitor.update(k, P.HealthStats(new_state_index)) # increment time step k += 1
def simulate(self, sim_length): """ simulate the patient over the specified simulation length """ # random number generator for this patient self._rng = rndClasses.RNG(self._id) k = 0 # current time step # while the patient is alive and simulation length is not yet reached while (self.healthstat != 3 or self.healthstat != 4) and k * delta_t < sim_length: # find the transition probabilities of the future states trans_probs = TRANS[self.THERAPY][self.healthstat] # create an empirical distribution empirical_dist = rndClasses.Empirical(trans_probs) # sample from the empirical distribution to get a new state # (returns an integer from {0, 1, 2, ...}) new_state_index = empirical_dist.sample(self._rng) if self.healthstat == 1: self.STROKE += 1 #caculate cost and utality cost = TRANS_COST[self.THERAPY][self.healthstat] * delta_t utility = TRANS_UTILITY[self.THERAPY][self.healthstat] * delta_t # update total discounted cost and utility (corrected for the half-cycle effect) self.totalDiscountCost += \ EconCls.pv(cost, Discount_Rate*delta_t, k + 1) self.totalDiscountUtility += \ EconCls.pv(utility, Discount_Rate*delta_t, k + 1) # update health state self.healthstat = new_state_index[0] # increment time step k += 1 self.survival = k * delta_t
def simulate(self, sim_length): """ simulate the single patient over a simulation length""" # random number generator for this patient self._rng = Rand.RNG(self._id) k = 0 # current time step # while the patient is alive and the simulation length is not yet reached while self._stateMonitor.get_if_alive( ) and k * self._delta_t < sim_length: # find the transition probabilities of the future states trans_prob = self._parameters.get_transition_prob( self._stateMonitor.get_current_state()) # create an empirical distribution empirical_dist = Rand.Empirical(trans_prob) # sample from the empirical distribution to get a new state new_state_index = empirical_dist.sample(self._rng) # update health state self._stateMonitor.update(k, Parameter.HealthState(new_state_index)) # increment time step k += 1
def __init__(self, seed, therapy): #initialize base class _Parameters.__init__(self,therapy) self._rng = Random.RNG(seed) # random number generator to sample from parameter distributions self._infectionProbMatrixRVG = [] # list of dirichlet distributions for transition probabilities self._lnRelativeRiskRVG = None # random variate generator for the natural log of the treatment relative risk self._annualStateCostRVG = [] # list of random variate generators for the annual cost of states self._annualStateUtilityRVG = [] # list of random variate generators for the annual utility of states #transition probabilities # j = 0 # for prob in Data.TRANS_MATRIX: # self._infectionProbMatrixRVG.append(Random.Dirichlet(prob[j:])) # j += 1 # annual state cost for cost in Data.ANNUAL_STATE_COST: # find shape and scale of the assumed gamma distribution estDic = Est.get_gamma_params(mean=cost, st_dev=cost/4) # append the distribution self._annualStateCostRVG.append( Random.Gamma(a=estDic["a"], loc=0, scale=estDic["scale"])) # annual state utility for utility in Data.ANNUAL_STATE_UTILITY: # find alpha and beta of the assumed beta distribution estDic = Est.get_beta_params(mean=utility, st_dev=utility/4) # append the distribution self._annualStateUtilityRVG.append( Random.Beta(a=estDic["a"], b=estDic["b"])) # resample parameters self.__resample()
def __init__(self, seed, therapy): # initializing the base class _Parameters.__init__(self, therapy) self._rng = Random.RNG( seed ) # random number generator to sample from parameter distributions self._hivProbMatrixRVG = [ ] # list of dirichlet distributions for transition probabilities self._lnRelativeRiskRVG = None # random variate generator for the natural log of the treatment relative risk self._annualStateCostRVG = [ ] # list of random variate generators for the annual cost of states self._annualStateUtilityRVG = [ ] # list of random variate generators for the annual utility of states # HIV transition probabilities j = 0 for prob in Data.TRANS_MATRIX: self._hivProbMatrixRVG.append(Random.Dirichlet(prob[j:])) j += 1 # treatment relative risk # find the mean and st_dev of the normal distribution assumed for ln(RR) if self._therapy == Therapies.MONO: sample_mean_lnRR = math.log(Data.Treatment_RR_GC) sample_std_lnRR = \ (math.log(Data.Treatment_RR_G_CI[1])-math.log(Data.Treatment_RR_G_CI[0]))/(2*stat.norm.ppf(1-0.05/2)) self._lnRelativeRiskRVG = Random.Normal(loc=sample_mean_lnRR, scale=sample_std_lnRR) else: sample_mean_lnRR = math.log(Data.Treatment_RR_GC) sample_std_lnRR = \ (math.log(Data.Treatment_RR_GC_CI[1]) - math.log(Data.Treatment_RR_GC_CI[0])) / ( 2 * stat.norm.ppf(1 - 0.05 / 2)) self._lnRelativeRiskRVG = Random.Normal(loc=sample_mean_lnRR, scale=sample_std_lnRR) # annual state cost for cost in Data.MONTHLY_STATE_COST: # find shape and scale of the assumed gamma distribution estDic = Est.get_gamma_params(mean=cost, st_dev=cost / 4) # append the distribution self._annualStateCostRVG.append( Random.Gamma(a=estDic["a"], loc=0, scale=estDic["scale"])) # annual state utility for utility in Data.MONTHLY_STATE_UTILITY: # find alpha and beta of the assumed beta distribution estDic = Est.get_beta_params(mean=utility, st_dev=utility / 4) # append the distribution self._annualStateUtilityRVG.append( Random.Beta(a=estDic["a"], b=estDic["b"])) # resample parameters self.__resample()
def simulate(self, sim_length): """ simulate the patient over the specified simulation length """ # random number generator for this patient self._rng = rndClasses.RNG(self._id) # from now on use random number generator from support library k = 0 while self._stateMonitor.get_if_alive() and k*self._delta_t < sim_length: trans_prob = self._param.get_transition_prob(self._stateMonitor.get_current_state()) empirical_dist = rndClasses.Empirical(trans_prob) new_state_index = empirical_dist.sample(self._rng) self._stateMonitor.update(k, P.HealthStats(new_state_index)) k += 1
def __init__(self, seed, therapy): # initializing the base class _Parameters.__init__(self, therapy) self._rng = Random.RNG( seed ) # random number generator to sample from parameter distributions self._hivProbMatrixRVG = [ ] # list of dirichlet distributions for transition probabilities self._lnRelativeRiskRVG = None # random variate generator for the treatment relative risk self._annualStateCostRVG = [ ] # list of random variate generators for the annual cost of states self._annualStateUtilityRVG = [ ] # list of random variate generators for the annual utility of states # HIV transition probabilities j = 0 for prob in Data.TRANS_MATRIX: self._hivProbMatrixRVG.append(Random.Dirichlet(prob[j:])) j += 1 # treatment relative risk # find the mean and st_dev of the normal distribution assumed for ln(RR) sample_mean_lnRR = math.log(Data.TREATMENT_RR) sample_std_lnRR = (Data.TREATMENT_RR_CI[1] - Data.TREATMENT_RR_CI[0] ) / (2 * stat.norm.ppf(1 - 0.05 / 2)) self._lnRelativeRiskRVG = Random.Normal(mean=sample_mean_lnRR, st_dev=sample_std_lnRR) # annual state cost for cost in Data.ANNUAL_STATE_COST: # find shape and scale of the assumed gamma distribution shape, scale = Est.get_gamma_parameters(mean=cost, st_dev=cost / 4) # append the distribution self._annualStateCostRVG.append(Random.Gamma(shape, scale)) # annual state utility for utility in Data.ANNUAL_STATE_UTILITY: # find alpha and beta of the assumed beta distribution a, b = Est.get_beta_parameters(mean=utility, st_dev=utility / 5) # append the distribution self._annualStateUtilityRVG.append(Random.Beta(a, b)) # resample parameters self.__resample()
def simulate(self, sim_length): self._rng = RndClasses.RNG(self._id) t = 0 while self._healthStateMonitor.get_if_alive( ) and t * self._delta_t < sim_length: trans_prob = self._param.get_prob_matrix( self._healthStateMonitor.get_current_state()) empirical_dist = RndClasses.Empirical(trans_prob) new_state_index = empirical_dist.sample(self._rng) self._healthStateMonitor.update( t, Parameters.HealthStates(new_state_index)) t += 1
def __init__(self, seed, therapy): self._rng = Random.RNG( seed ) # random number generator to sample from parameter distributions self._StrokeProbMatrixRVG = [ ] # list of dirichlet distributions for transition probabilities self._lnRelativeRiskRVG = None # random variate generator for the treatment relative risk # Stroke transition probabilities j = 0 for prob in Data.TRANS_MATRIX: self._StrokeProbMatrixRVG.append(Random.Dirichlet(prob[j:])) j += 1 # resample parameters self.__resample()
def __init__(self, seed, therapy): # initializing the base class _Parameters.__init__(self, therapy) self._rng = Random.RNG( seed ) # random number generator to sample from parameter distributions self._hivProbMatrixRVG_LDCT = [ ] # list of dirichlet distributions for transition probabilities of LDCT self._hivProbMatrixRVG_PLCO = [] #self._lnRelativeRiskRVG = None # random variate generator for the natural log of the treatment relative risk self._annualStateCostRVG = [ ] # list of random variate generators for the annual cost of states self._annualStateUtilityRVG = [ ] # list of random variate generators for the annual utility of states # HIV transition probabilities j = 0 for prob in Data.TRANS_MATRIX_LDCT: self._hivProbMatrixRVG_LDCT.append(Random.Dirichlet(prob[j:])) j += 1 # you should make sure everything you use is not "0" in the dirichlet for prob in Data.TRANS_MATRIX_PLCO: self._hivProbMatrixRVG_PLCO.append(Random.Dirichlet(prob[j:])) j += 1 # treatment relative risk # find the mean and st_dev of the normal distribution assumed for ln(RR) # annual state cost, we assume gamma distribution for cost in Data.ANNUAL_STATE_COST: # find shape and scale of the assumed gamma distribution estDic = Est.get_gamma_params(mean=cost, st_dev=cost / 4) # append the distribution self._annualStateCostRVG.append( Random.Gamma(a=estDic["a"], loc=0, scale=estDic["scale"])) # annual state utility, we assume beta distribution for utility in Data.ANNUAL_STATE_UTILITY: # find alpha and beta of the assumed beta distribution estDic = Est.get_beta_params(mean=utility, st_dev=utility / 4) # append the distribution self._annualStateUtilityRVG.append( Random.Beta(a=estDic["a"], b=estDic["b"]))
def simulate(self, sim_length): """ simulate the patient over the specified simulation length """ # random number generator for this patient self._rng = rndClasses.RNG(self._id) k = 0 # current time step # while the patient is alive and simulation length is not yet reached while self.healthstat!=3 and k < sim_length: # find the transition probabilities of the future states trans_probs = TRANS_MATRIX[self.healthstat] # create an empirical distribution empirical_dist = rndClasses.Empirical(trans_probs) # sample from the empirical distribution to get a new state # (returns an integer from {0, 1, 2, ...}) new_state_index = empirical_dist.sample(self._rng) # update health state self.healthstat =new_state_index[0] # increment time step k += 1 self.survival=k+1
def simulate_fiveshort(self, sim_length_short): """ simulate the patient over the specified simulation length """ # random number generator for this patient self._rng = rndClasses.RNG(self._id) if self.vaccine == 0: k = 0 # while the patient is alive and simulation length is not yet reached while (self.healthstat != 8) and k * ma.delta_t < sim_length_short: # find the transition probabilities of the future states trans_probs = ma.prob_matrix[0][self.healthstat] # create an empirical distribution empirical_dist = rndClasses.Empirical(trans_probs) # sample from the empirical distribution to get a new state # (returns an integer from {0, 1, 2, ...}) new_state_index = empirical_dist.sample(self._rng) # caculate cost and utality cost = ma.cost_matrix[ self. healthstat] + ma.salary * ma.work_loss_day[self.healthstat] utility = ma.utility_matrix[self.healthstat] * ma.delta_t # update total discounted cost and utility (corrected for the half-cycle effect) self.totalDiscountCost += \ EconCls.pv(cost, ma.discount_rate * ma.delta_t, k + 1) self.totalDiscountUtility += \ EconCls.pv(utility, ma.discount_rate * ma.delta_t, k + 1) # update diseases: if self.healthstat == HealthStats.Pneumoniae.value: self.pneumonaie += 1 if self.healthstat == HealthStats.Meningitis.value: self.meningitis += 1 if self.healthstat == HealthStats.AOM_T.value or self.healthstat == HealthStats.AOM_NT.value: self.aom += 1 # update disability number if self.healthstat == HealthStats.Disability.value: self._ndisability = 1 # update deafness number if self.healthstat == HealthStats.Deaf.value: self._ndeaf = 1 # update health state self.healthstat = new_state_index[0] #update number of deahts if self.healthstat == HealthStats.DEATH.value: self._ndeath = 1 # increment time step k += 1 if self.vaccine == 1: k = 0 while (self.healthstat != 8) and k * ma.delta_t < sim_length_short: # find the transition probabilities of the future states trans_probsv = ma.prob_matrix_vaccine[0][self.healthstat] # create an empirical distribution empirical_distv = rndClasses.Empirical(trans_probsv) # sample from the empirical distribution to get a new state # (returns an integer from {0, 1, 2, ...}) new_state_indexv = empirical_distv.sample(self._rng) # caculate cost and utality cost = ma.cost_matrix[ self. healthstat] + ma.salary * ma.work_loss_day[self.healthstat] utility = ma.utility_matrix[self.healthstat] * ma.delta_t # update total discounted cost and utility (corrected for the half-cycle effect) self.totalDiscountCost += \ EconCls.pv(cost, ma.discount_rate * ma.delta_t, k + 1) self.totalDiscountUtility += \ EconCls.pv(utility, ma.discount_rate * ma.delta_t, k + 1) # update diseases: if self.healthstat == HealthStats.Pneumoniae.value: self.pneumonaie += 1 if self.healthstat == HealthStats.Meningitis.value: self.meningitis += 1 if self.healthstat == HealthStats.AOM_T.value or self.healthstat == HealthStats.AOM_NT.value: self.aom += 1 # update disability number if self.healthstat == HealthStats.Disability.value: self._ndisability = 1 # update deafness number if self.healthstat == HealthStats.Deaf.value: self._ndeaf = 1 # update health state self.healthstat = new_state_indexv[0] #update number of deahts if self.healthstat == HealthStats.DEATH.value: self._ndeath = 1 if k == 3: self.shot += 1 self.totalDiscountCost+= \ EconCls.pv(ma.vaccine_administration+ma.vaccine_cost, ma.discount_rate * ma.delta_t, k + 1) if k == 5: self.shot += 1 self.totalDiscountCost+= \ EconCls.pv(ma.vaccine_administration+ma.vaccine_cost, ma.discount_rate * ma.delta_t, k + 1) if k == 11: self.shot += 1 self.totalDiscountCost+= \ EconCls.pv(ma.vaccine_administration+ma.vaccine_cost, ma.discount_rate * ma.delta_t, k + 1) # increment time step k += 1 if self.healthstat == 3: for i in (6, 16): self.totalDiscountCost += EconCls.pv(2746, ma.discount_rate, i + 1)