Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] REPS / C-REPS analytical gradient benchmarks #81

Merged
merged 12 commits into from
Aug 15, 2018
Merged

[MRG] REPS / C-REPS analytical gradient benchmarks #81

merged 12 commits into from
Aug 15, 2018

Conversation

RicardoDominguez
Copy link
Contributor

Benchmarks as suggested in #70

@@ -0,0 +1,344 @@
# Authors: Jan Hendrik Metzen <jhm@informatik.uni-bremen.de>
# Alexander Fabisch <afabisch@informatik.uni-bremen.de>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add yourself here, also in the other files.

from bolero.utils.log import get_logger


def solve_dual_contextual_reps(S, R, epsilon, min_eta, approx_grad = True):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use PEP8:

def solve_dual_contextual_reps(S, R, epsilon, min_eta, approx_grad=True): 

return d, eta, nu


class CREPSOptimizer(ContextualOptimizer):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem with copying the whole file is that if there are any changes in (c)reps in the future, you have to copy them to the benchmark. You should make a subclass of CREPSOptimizer that overrides set_evaluation_feedback. The same should be done for the REPSOptimizer.

for i in range(n_trials):
r = eval_loop(Rosenbrock, opt, n_dims, n_iter)
total_time = time.time() - start_time
print name, 'completed in average time of', round(total_time / n_trials, 2), 'seconds'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to be compatible to Python 3 soon. For example:

print("%s: %s %.2f %s" % (name, 'completed in average time of', round(total_time / n_trials, 2), 'seconds'))

total_time = time.time() - start_time
print name, 'completed in average time of', round(total_time / n_trials, 2), 'seconds'
rwds = -np.maximum.accumulate(r)
print name, 'minimum found', rwds[-1]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use parentheses for prints.

x = np.zeros(n_dims)

optimizers = {
"Numerical gradient": REPSOptimizer(x, random_state=0, approx_grad = True),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PEP8

@@ -49,15 +49,21 @@ def solve_dual_reps(R, epsilon, min_eta):

# Definition of the dual function
def g(eta): # Objective function
return eta * epsilon + eta * logsumexp(R / eta, b=1.0 / len(R))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes should already be in master, please rebase:

git fetch <remote>
git rebase <remote>/master
# resolve conflicts if there are any


# Perform the actual optimization of the dual function
if approx_grad:
r = fmin_l_bfgs_b(g, x0, approx_grad=True, bounds=bounds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't mix tabs and spaces.


def show_results(results):
"""Display results."""
for objective_name, objective_results in results.items():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You cannot recognize any difference between both curves. Maybe there is a better way, for example, using a dashed and a solid line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have used a dashed line so that both lines can be seen, but there is no difference between both curves as the solutions found are the same.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, looks better now!

@AlexanderFabisch AlexanderFabisch changed the title REPS / C-REPS analytical gradient benchmarks [MRG] REPS / C-REPS analytical gradient benchmarks Aug 13, 2018
@RicardoDominguez
Copy link
Contributor Author

I am not sure if I have rebased properly, I am getting the feeling that I haven't.

@RicardoDominguez
Copy link
Contributor Author

I have definitely messed up with the rebase, please ignore until I fix it.

@AlexanderFabisch
Copy link
Contributor

I have definitely messed up with the rebase, please ignore until I fix it.

The diff looks good but it says I cannot merge. Let me know if you are not able to solve this problem. Maybe this helps?

@RicardoDominguez
Copy link
Contributor Author

RicardoDominguez commented Aug 15, 2018

@AlexanderFabisch I think the rebase is correct now, let me know if I have missed anything :)

@AlexanderFabisch
Copy link
Contributor

flake8 gave me the following output:

flake8 *.py
creps_benchmark.py:16:1: E122 continuation line missing indentation or outdented
creps_benchmark.py:23:1: E302 expected 2 blank lines, found 1
creps_benchmark.py:40:1: E305 expected 2 blank lines after class or function definition, found 1
creps_benchmark.py:41:13: E203 whitespace before ':'
creps_benchmark.py:74:1: E302 expected 2 blank lines, found 1
creps_benchmark.py:91:80: E501 line too long (86 > 79 characters)
creps_benchmark.py:94:1: E302 expected 2 blank lines, found 1
creps_benchmark.py:101:80: E501 line too long (85 > 79 characters)
creps_benchmark.py:126:1: E302 expected 2 blank lines, found 1
creps_numerical.py:51:21: E128 continuation line under-indented for visual indent
creps_numerical.py:59:5: E265 block comment should start with '# '
reps_benchmark.py:18:1: E302 expected 2 blank lines, found 1
reps_benchmark.py:29:1: E305 expected 2 blank lines after class or function definition, found 1
reps_numerical.py:47:1: E101 indentation contains mixed spaces and tabs
reps_numerical.py:47:1: W191 indentation contains tabs
reps_numerical.py:49:1: E101 indentation contains mixed spaces and tabs

Mixed tabs and spaces are critical. That should not go to the master.

@AlexanderFabisch
Copy link
Contributor

Looks good to me apart from that!

@AlexanderFabisch
Copy link
Contributor

If you zoom in you can really see that the analytical version is performing consistently better.

@RicardoDominguez
Copy link
Contributor Author

Mixed tabs and spaces are critical. That should not go to the master.

Sorry about that, I thought my editor picked those things up. Now flake8 doesn't complain.

@AlexanderFabisch AlexanderFabisch merged commit a52ce2b into rock-learning:master Aug 15, 2018
@AlexanderFabisch
Copy link
Contributor

Great, thanks for the contribution!

@RicardoDominguez
Copy link
Contributor Author

My pleasure!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants