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

Fix nonlinear policy #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions bolero_bayes_opt/representation/ul_policies.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,17 +348,20 @@ def average_return(policy_params):
else:
scale_factor = 1 # Don't do scaling since the scales are unknown

# Refine policy determined in model-free way by performing L-BFGS on
# the model.
from bolero.optimizer.cmaes import fmin as fmin_cmaes
policy.W /= scale_factor
x_lbfgs, _ = \
fmin_cmaes(average_return, x0=policy.W.flatten(), maxfun=maxfun,
eval_initial_x=True, variance=variance, maximize=True,
*args, **kwargs)

# Set weights of linear policy
policy.W = x_lbfgs.reshape(policy.W.shape)
policy.W *= scale_factor

return policy
try:
# Refine policy determined in model-free way by performing CMA-ES on
# the model.
from bolero.optimizer.cmaes import fmin as fmin_cmaes
policy.W /= scale_factor
W_cmaes, _ = \
fmin_cmaes(average_return, x0=policy.W.flatten(), maxfun=maxfun,
eval_initial_x=True, variance=variance, maximize=True,
*args, **kwargs)

# Set weights of linear policy
policy.W = W_cmaes.reshape(policy.W.shape)
policy.W *= scale_factor
except AttributeError:
pass # policy is not a linear model

return policy