예제 #1
0
def test_profiles():
    # create the necessary results
    result_1 = create_profile_result()
    result_2 = create_profile_result()

    # test a standard call
    visualize.profiles(result_1)

    # test plotting of lists
    visualize.profiles([result_1, result_2])
예제 #2
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)
예제 #3
0
def test_profiles_with_options():
    # create the necessary results
    result = create_profile_result()
    result.profile_result.list.append([result.profile_result.list[0][1], None])

    # alternative figure size and plotting options
    (_, _, _, _, ref_point) = create_plotting_options()
    alt_fig_size = (9.0, 8.0)

    # test a call with some specific options
    visualize.profiles(result,
                       reference=ref_point,
                       size=alt_fig_size,
                       profile_list_ids=[0, 1],
                       legends=['profile list 0', 'profile list 1'],
                       colors=[[1., .3, .3, .5], [.5, .9, .4, .3]])
예제 #4
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)