def __init__(self, id, parameters): self.id = id self.rng = RVGs.RNG(seed=id) self.params = parameters self.gillespie = Markov.Gillespie( transition_rate_matrix=parameters.rateMatrix) self.stateMonitor = PatientStateMonitor(parameters=parameters)
def __init__(self, err_sigma): """" :param err_sigma is the standard deviation of noise term """ SimModel.__init__(self) # create a normal distribution to model noise self._err = RVGs.Normal(loc=0, scale=err_sigma)
def __init__(self, therapy): self.therapy = therapy self.probMatrixRVG = [ ] # list of dirichlet distributions for transition probabilities self.lnRelativeRiskRVG = None # normal distribution for the natural log of the treatment relative risk self.annualStateCostRVG = [ ] # list of gamma distributions for the annual cost of states self.annualStateUtilityRVG = [ ] # list of beta distributions for the annual utility of states # create Dirichlet distributions for transition probabilities j = 0 for prob in Data.PROB_MATRIX: self.probMatrixRVG.append(RVGs.Dirichlet(a=prob[j:])) j += 1 # treatment relative risk rr_ci = [1.2, 3] # confidence interval of the treatment relative risk # find the mean and st_dev of the normal distribution assumed for ln(RR) # sample mean ln(RR) mean_ln_rr = math.log(Data.TREATMENT_RR) # sample standard deviation of ln(RR) std_ln_rr = \ (math.log(rr_ci[1]) - math.log(rr_ci[0])) / (2 * stat.norm.ppf(1 - 0.05 / 2)) # create a normal distribution for ln(RR) self.lnRelativeRiskRVG = RVGs.Normal(loc=mean_ln_rr, scale=std_ln_rr) # create gamma distributions for annual state cost for cost in Data.ANNUAL_STATE_COST_NO: # if cost is zero, add a constant 0, otherwise add a gamma distribution if cost == 0: self.annualStateCostRVG.append(RVGs.Constant(value=0)) else: # find shape and scale of the assumed gamma distribution # no data available to estimate the standard deviation, so we assumed st_dev=cost / 5 fit_output = MM.get_gamma_params(mean=cost, st_dev=cost / 5) # append the distribution self.annualStateCostRVG.append( RVGs.Gamma(a=fit_output["a"], loc=0, scale=fit_output["scale"])) # create beta distributions for annual state utility for utility in Data.ANNUAL_STATE_UTILITY_0: # if utility is zero, add a constant 0, otherwise add a beta distribution if utility == 0: self.annualStateCostRVG.append(RVGs.Constant(value=0)) else: # find alpha and beta of the assumed beta distribution # no data available to estimate the standard deviation, so we assumed st_dev=cost / 4 fit_output = MM.get_beta_params(mean=utility, st_dev=utility / 4) # append the distribution self.annualStateUtilityRVG.append( RVGs.Beta(a=fit_output["a"], b=fit_output["b"]))
def __init__(self, id, parameters): """ initiates a patient :param id: ID of the patient :param parameters: an instance of the parameters class """ self.id = id self.rng = RVGs.RNG( seed=id) # random number generator for this patient self.params = parameters # gillespie algorithm self.gillespie = Markov.Gillespie( transition_rate_matrix=parameters.rateMatrix) self.stateMonitor = PatientStateMonitor( parameters=parameters) # patient state monitor
def get_obj_value(self, x, seed_index=0): """ returns one realization from x^2+noise """ # create a random number generator rng = RVGs.RNG(seed=seed_index) accum_penalty = 0 # accumulated penalty # test the feasibility if x[1] < 1: accum_penalty += self._penalty * pow(x[1] - 1, 2) x[1] = 1 return (x[0] + 1) * (x[0] + 1) + x[1] * x[1] + self._err.sample( rng) + accum_penalty