def test_likelihood_ratio(self): objval, thetavals = self.pest.theta_est() asym = np.arange(10, 30, 2) rate = np.arange(0, 1.5, 0.25) theta_vals = pd.DataFrame(list(product(asym, rate)), columns=self.pest.theta_names) obj_at_theta = self.pest.objective_at_theta(theta_vals) LR = self.pest.likelihood_ratio_test(obj_at_theta, objval, [0.8, 0.9, 1.0]) self.assertTrue(set(LR.columns) >= set([0.8, 0.9, 1.0])) self.assertTrue(LR[0.8].sum() == 6) self.assertTrue(LR[0.9].sum() == 10) self.assertTrue(LR[1.0].sum() == 60) # all true graphics.pairwise_plot(LR, thetavals, 0.8)
def test_bootstrap(self): objval, thetavals = self.pest.theta_est() num_bootstraps = 10 theta_est = self.pest.theta_est_bootstrap(num_bootstraps, return_samples=True) num_samples = theta_est['samples'].apply(len) self.assertTrue(len(theta_est.index), 10) self.assertTrue(num_samples.equals(pd.Series([6] * 10))) del theta_est['samples'] # apply cofidence region test CR = self.pest.confidence_region_test(theta_est, 'MVN', [0.5, 0.75, 1.0]) self.assertTrue(set(CR.columns) >= set([0.5, 0.75, 1.0])) self.assertTrue(CR[0.5].sum() == 5) self.assertTrue(CR[0.75].sum() == 7) self.assertTrue(CR[1.0].sum() == 10) # all true graphics.pairwise_plot(theta_est) graphics.pairwise_plot(theta_est, thetavals) graphics.pairwise_plot(theta_est, thetavals, 0.8, ['MVN', 'KDE', 'Rect'])
def test_bootstrap(self): objval, thetavals = self.pest.theta_est() num_bootstraps = 10 theta_est = self.pest.bootstrap(num_bootstraps) num_samples = theta_est['samples'].apply(len) self.assertTrue(len(theta_est.index), 10) self.assertTrue(num_samples.equals(pd.Series([6] * 10))) filename = os.path.abspath(os.path.join(testdir, 'pairwise.png')) if os.path.isfile(filename): os.remove(filename) graphics.pairwise_plot(theta_est, filename=filename) #self.assertTrue(os.path.isfile(filename)) filename = os.path.abspath( os.path.join(testdir, 'pairwise_bootstrap.png')) if os.path.isfile(filename): os.remove(filename) graphics.pairwise_bootstrap_plot(theta_est, thetavals, 0.8, filename=filename)
def test_pairwise_plot(self): graphics.pairwise_plot(self.A, alpha=0.8, distributions=['Rect', 'MVN', 'KDE'])
### Parameter estimation with entire data set objval, thetavals = pest.theta_est() if mpii.rank in [0, None]: print("objective value=", str(objval)) print("theta-star=", str(thetavals)) ### Parameter estimation with bootstrap alpha = 0.8 num_bootstraps = 10 bootstrap_theta = pest.bootstrap(num_bootstraps) if mpii.rank in [0, None]: print("Bootstrap:") print(bootstrap_theta) grph.pairwise_plot(bootstrap_theta, filename="RB.png") grph.pairwise_bootstrap_plot(bootstrap_theta, thetavals, alpha, filename="RB_boot.png") ### Likelihood ratio alpha = 0.8 search_ranges = {} search_ranges["asymptote"] = np.arange(10, 30, 2) # np.arange(10, 30, 0.01) search_ranges["rate_constant"] = np.arange(0, 1.5, 0.1) # np.arange(0, 1.5, 0.005) SSE = pest.likelihood_ratio(search_ranges=search_ranges) if mpii.rank in [0, None]: print("Likelihood Ratio:") print(SSE)