Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion boplay/acq_funs/gamma_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def estimate_gamma_params(
s = np.log(x_mean) - np.log(x).mean(axis=1)
for _ in range(max_iters):
grad = (np.log(k) - digamma(k) - s) / (1.0 / k - polygamma(1, k) + 1e-8)
grad += k**2 * wd
grad += (k - 1) ** 2 * wd
Copy link
Collaborator

Choose a reason for hiding this comment

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

exponential bistro for the win!!!!

k -= grad * lr
k = k.clip(min=k_min, max=k_max)
theta = x_mean / k
Expand Down
8 changes: 7 additions & 1 deletion boplay/acq_funs/ves_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ def optimize_adam(
max_iters: int, the maximum number of iterations
tol: float, the tolerance for the optimization
lr: float, the learning rate for the optimization
wd: float, weight decay centered at 1

Returns:
theta: pt.Tensor, shape (n_x, 4)
final_loss: float, the optimized loss
"""
opt = pt.optim.Adam([theta], lr=lr, amsgrad=True, weight_decay=wd)
opt = pt.optim.Adam([theta], lr=lr, amsgrad=True, weight_decay=0)
prev_loss = float("inf")
L = loss_fn(theta)

Expand All @@ -67,6 +68,11 @@ def optimize_adam(
L = loss_fn(theta)
L.backward()
opt.step()

# Apply custom weight decay centered at 1
if wd > 0:
with pt.no_grad():
theta.data -= wd * (theta.data - 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

theta here can be more general than k-values in a gamma distro. (this code isn't being used in experiments atm so not an issue for the deadline)


# Early stopping
if abs(prev_loss - L.item()) < tol:
Expand Down