Skip to content

Commit

Permalink
Finishes something
Browse files Browse the repository at this point in the history
  • Loading branch information
PTNobel committed Feb 6, 2025
1 parent 752265c commit 8948b0a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions randalo/modeling_layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ def to_cvxpy(self, y, z):
class MSELoss(Loss):
def __init__(self, weights=None):
self.weights = weights

def func(self, y, z):
return self.weights * (y - z) ** 2

Expand Down
5 changes: 3 additions & 2 deletions utils/sherlock_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ def __init__(self):
with open(model_cache, 'wb') as fd:
pickle.dump({'betas': state.betas, 'lmda_path': state.lmda_path, 'intercepts': state.intercepts}, fd)

train_risk = lambda x, y: torch.sum(weights * (x - y)**2) / torch.sum(weights)
weights_t = torch.from_numpy(weights)
train_risk = lambda x, y: torch.sum(weights_t * (x - y)**2) / torch.sum(weights_t)
loss = torch.nn.MSELoss()
L = state.betas.shape[0]
oos = np.empty(L)
Expand All @@ -106,7 +107,7 @@ def __init__(self):
ins[i] = loss(torch.from_numpy(y_hat_train[i]), torch.from_numpy(y_train))

ti_alo = time.monotonic()
ld, alo, ts, r2 = ai.get_alo_for_sweep(y_train, state, train_risk, weights, 20)
ld, alo, ts, r2 = ai.get_alo_for_sweep(y_train, state, train_risk, weights_t, 20)
tf_alo = time.monotonic()

np.savez(sys.argv[1], alo_lamda=ld, full_lamda=state.lmda_path, alo=alo, oos=oos, in_sample=ins, ts=ts, r2=r2, solve_time=tf_solve - ti_solve, alo_time=tf_alo - ti_alo)

0 comments on commit 8948b0a

Please sign in to comment.