def run_for_parms(Ns, ms, ts, popmaps, numreg, reps, compError = False, coal_error_threshold = 0.0001): """This function runs the estimation procedure given the population sizes, mig rates, times, pop history. numreg controls the noise in the estimate of coal rates, and reps repeats the procedure multiple times. """ true_parms = [] for i in xrange(len(Ns)): if len(Ns[i]) > 1: true_parms.append(np.array(Ns[i] + ms[i])) else: true_parms.append(np.array(Ns[i])) true_rates = mig.compute_pw_coal_rates(ms, Ns, ts, popmaps) print 'True_rates:', true_rates xopts = [] estErr = [] while reps > 0: obs_rates = add_uniform_noise(true_rates, numreg) while np.min(obs_rates) < 0 or np.max(obs_rates) > 1: obs_rates = add_uniform_noise(true_rates, numreg) xopt = mig.comp_N_m(obs_rates, ts, coal_error_threshold) xopts.append(xopt) reps -= 1 if compError: estErr.append(compute_error(true_parms, xopt)) if compError: return (xopts, estErr) else: return xopts
def estimate_sim_run(self, merge_threshold = 0.01, useMigration = False, DFO = False, window = 0, hack = False): """This function estimates the pop and mig in each timeslice and returns it. If useMigration, the threshold is the migration threshold, if not the threshold is the coal rate threshold """ if DFO: self.estimatedParms = mig.comp_N_m(self.obsRates, self.timeslices, merge_threshold, useMigration, self.logVal, self.verbose) else: self.estimatedParms = mig.comp_N_m_bfgs(self.obsRates, self.timeslices, merge_threshold, useMigration, False, self.logVal, True, window, hack, variances=self.vars) return self.estimatedParms