Exemple #1
0
 def test_likelihood_ratio(self):
     # tbd: write the plot file(s) to a temp dir and delete in cleanup
     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.85, 0.9, 0.95])
     
     self.assertTrue(set(LR.columns) >= set([0.8, 0.85, 0.9, 0.95]))
     
     filename = os.path.abspath(os.path.join(testdir, 'pairwise_LR_plot.png'))
     if os.path.isfile(filename):
         os.remove(filename)
     parmest.pairwise_plot(LR, thetavals, 0.8,  filename=filename)
Exemple #2
0
    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() == 7)
        self.assertTrue(LR[0.9].sum() == 11)
        self.assertTrue(LR[1.0].sum() == 60)  # all true

        parmest.pairwise_plot(LR, thetavals, 0.8)
Exemple #3
0
    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']
        
        filename = os.path.abspath(os.path.join(testdir, 'pairwise_bootstrap.png'))
        if os.path.isfile(filename):
            os.remove(filename)
        parmest.pairwise_plot(theta_est, filename=filename)
        #self.assertTrue(os.path.isfile(filename))
        
        filename = os.path.abspath(os.path.join(testdir, 'pairwise_bootstrap_theta.png'))
        if os.path.isfile(filename):
            os.remove(filename)
        parmest.pairwise_plot(theta_est, thetavals, filename=filename)
        #self.assertTrue(os.path.isfile(filename))
        
        filename = os.path.abspath(os.path.join(testdir, 'pairwise_bootstrap_theta_CI.png'))
        if os.path.isfile(filename):
            os.remove(filename)
        parmest.pairwise_plot(theta_est, thetavals, 0.8, ['MVN', 'KDE', 'Rect'],
                                         filename=filename)
Exemple #4
0
    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

        parmest.pairwise_plot(theta_est)
        parmest.pairwise_plot(theta_est, thetavals)
        parmest.pairwise_plot(theta_est, thetavals, 0.8,
                              ['MVN', 'KDE', 'Rect'])
    expr = sum((data.y[i] - model.response_function[data.hour[i]])**2
               for i in data.index)
    return expr


pest = parmest.Estimator(rooney_biegler_model, data, theta_names, SSE)
obj, theta = pest.theta_est()
print(obj)
print(theta)

### Parameter estimation with bootstrap resampling

bootstrap_theta = pest.theta_est_bootstrap(50, seed=4581)
print(bootstrap_theta.head())

parmest.pairwise_plot(bootstrap_theta, theta, 0.8, ['MVN', 'KDE', 'Rect'])

### Likelihood ratio test

asym = np.arange(10, 30, 2)
rate = np.arange(0, 1.5, 0.1)
theta_vals = pd.DataFrame(list(product(asym, rate)), columns=theta_names)

obj_at_theta = pest.objective_at_theta(theta_vals)
print(obj_at_theta.head())

LR = pest.likelihood_ratio_test(obj_at_theta, obj, [0.8, 0.85, 0.9, 0.95])
print(LR.head())

parmest.pairwise_plot(LR, theta, 0.8)
           ((float(data['cc1']) - model.cc)**2)*(1/2) + \
           ((float(data['cc2']) - model.cc)**2)*(1/2) + \
            (float(data['cd'])  - model.cd)**2
    return expr

pest = parmest.Estimator(reactor_design_model, data, theta_names, SSE_multisensor)
obj, theta = pest.theta_est()
print(obj)
print(theta)

### Parameter estimation with bootstrap resampling

bootstrap_theta = pest.theta_est_bootstrap(50)
print(bootstrap_theta.head())

parmest.pairwise_plot(bootstrap_theta)
parmest.pairwise_plot(bootstrap_theta, theta, 0.8, ['MVN', 'KDE', 'Rect'])

### Likelihood ratio test

k1 = [0.83]
k2 = np.arange(1.48, 1.79, 0.05) # Only vary k2 and k3 in this example
k3 = np.arange(0.000155, 0.000185, 0.000005)
theta_vals = pd.DataFrame(list(product(k1, k2, k3)), columns=theta_names)
    
obj_at_theta = pest.objective_at_theta(theta_vals)
print(obj_at_theta.head())

LR = pest.likelihood_ratio_test(obj_at_theta, obj, [0.8, 0.85, 0.9, 0.95])
print(LR.head())
Exemple #7
0
 def test_pairwise_plot(self):
     parmest.pairwise_plot(self.A,
                           alpha=0.8,
                           distributions=['Rect', 'MVN', 'KDE'])
Exemple #8
0

solver_options = {"max_iter": 6000}  # not really needed in this case

pest = parmest.Estimator(rooney_biegler_model, data, theta_names, SSE,
                         solver_options)
obj, theta = pest.theta_est()
print(obj)
print(theta)

### Parameter estimation with bootstrap resampling

bootstrap_theta = pest.theta_est_bootstrap(50, seed=4581)
print(bootstrap_theta.head())

parmest.pairwise_plot(bootstrap_theta, title='Bootstrap theta')
parmest.pairwise_plot(bootstrap_theta,
                      theta,
                      0.8, ['MVN', 'KDE', 'Rect'],
                      title='Bootstrap theta with confidence regions')

### Likelihood ratio test

asym = np.arange(10, 30, 2)
rate = np.arange(0, 1.5, 0.1)
theta_vals = pd.DataFrame(list(product(asym, rate)), columns=theta_names)

obj_at_theta = pest.objective_at_theta(theta_vals)
print(obj_at_theta.head())

LR = pest.likelihood_ratio_test(obj_at_theta, obj, [0.8, 0.85, 0.9, 0.95])
Exemple #9
0
           (float(data['cd']) - model.cd)**2
    return expr


pest = parmest.Estimator(reactor_design_model, data, theta_names, SSE)
obj, theta = pest.theta_est()
print(obj)
print(theta)

### Parameter estimation with 'leave-N-out'
# Example use case: For each combination of data where one data point is left
# out, estimate theta
lNo_theta = pest.theta_est_leaveNout(1)
print(lNo_theta.head())

parmest.pairwise_plot(lNo_theta, theta)

### Leave one out/boostrap analysis
# Example use case: leave 50 data points out, run 75 bootstrap samples with the
# remaining points, determine if the theta estimate using the points left out
# is inside or outside an alpha region based on the bootstrap samples, repeat
# 10 times. Results are stored as a list of tuples, see API docs for information.
lNo = 50
lNo_samples = 10
bootstrap_samples = 75
dist = 'MVN'
alphas = [0.7, 0.8, 0.9]

results = pest.leaveNout_bootstrap_test(lNo,
                                        lNo_samples,
                                        bootstrap_samples,