Esempio n. 1
0
def test_profile_with_fixed_parameters():
    """Test using profiles with fixed parameters."""
    obj = test_objective.rosen_for_sensi(max_sensi_order=1)['obj']

    lb = -2 * np.ones(5)
    ub = 2 * np.ones(5)
    problem = pypesto.Problem(objective=obj,
                              lb=lb,
                              ub=ub,
                              x_fixed_vals=[0.5, -1.8],
                              x_fixed_indices=[0, 3])

    optimizer = optimize.ScipyOptimizer(options={'maxiter': 50})
    result = optimize.minimize(problem=problem,
                               optimizer=optimizer,
                               n_starts=2)

    for i_method, next_guess_method in enumerate([
            'fixed_step', 'adaptive_step_order_0', 'adaptive_step_order_1',
            'adaptive_step_regression'
    ]):
        print(next_guess_method)
        profile.parameter_profile(problem=problem,
                                  result=result,
                                  optimizer=optimizer,
                                  next_guess_method=next_guess_method)

        # standard plotting
        axes = visualize.profiles(result, profile_list_ids=i_method)
        assert len(axes) == 3
        visualize.profile_cis(result, profile_list=i_method)
Esempio n. 2
0
    def test_default_profiling(self):
        # loop over  methods for creating new initial guesses
        method_list = [
            'fixed_step', 'adaptive_step_order_0', 'adaptive_step_order_1',
            'adaptive_step_regression'
        ]
        for i_run, method in enumerate(method_list):
            # run profiling
            result = profile.parameter_profile(problem=self.problem,
                                               result=self.result,
                                               optimizer=self.optimizer,
                                               next_guess_method=method)

            # check result
            self.assertTrue(
                isinstance(result.profile_result.list[i_run][0],
                           profile.ProfilerResult))
            self.assertEqual(len(result.profile_result.list), i_run + 1)
            self.assertEqual(len(result.profile_result.list[i_run]), 2)

            # check whether profiling needed maybe too many steps
            steps = result.profile_result.list[i_run][0]['ratio_path'].size
            if method == 'adaptive_step_regression':
                self.assertTrue(
                    steps < 20, 'Profiling with regression based '
                    'proposal needed too many steps.')
                self.assertTrue(
                    steps > 1, 'Profiling with regression based '
                    'proposal needed not enough steps.')
            elif method == 'adaptive_step_order_1':
                self.assertTrue(
                    steps < 25, 'Profiling with 1st order based '
                    'proposal needed too many steps.')
                self.assertTrue(
                    steps > 1, 'Profiling with 1st order based '
                    'proposal needed not enough steps.')
            elif method == 'adaptive_step_order_0':
                self.assertTrue(
                    steps < 100, 'Profiling with 0th order based '
                    'proposal needed too many steps.')
                self.assertTrue(
                    steps > 1, 'Profiling with 0th order based '
                    'proposal needed not enough steps.')

            # standard plotting
            visualize.profiles(result, profile_list_ids=i_run)
            visualize.profile_cis(result, profile_list=i_run)
Esempio n. 3
0
def test_profile_cis():
    """Test the profile approximate confidence interval visualization."""
    result = create_profile_result()
    visualize.profile_cis(result, confidence_level=0.99)
    visualize.profile_cis(result, show_bounds=True, profile_indices=[0])