-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed the jax algorithm with what I discovered from the nn
- Loading branch information
Showing
3 changed files
with
11 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ def forward(self, x): | |
|
||
num_epochs = 50 # sample number of epoch -- can play with this/set this as a hyperparameter | ||
num_samples = 100 # number of samples per time step | ||
lamb = 0.60 | ||
lamb = 10 | ||
|
||
T = 7 | ||
ts = 0.1 | ||
|
@@ -154,11 +154,11 @@ def sample_initial(num_samples: int = num_samples) -> List[List[float]]: | |
cont = lambda p, i: torch.linalg.vector_norm(torch.relu(C@torch.linalg.inv(bases[i])@(p-centers[i])-mu*g)) | ||
# cont = lambda p, i: torch.linalg.vector_norm(torch.relu([email protected](bases[i])@(p-centers[i])-torch.diag(mu)@g)) | ||
# cont = lambda p, i: torch.linalg.vector_norm(torch.relu([email protected](bases[i])@(p-center)-mu*g)) | ||
loss = (1-lamb)*mu + lamb*torch.sum(torch.stack([cont(point, i) for point in post_points[:, i, 1:]]))/len(post_points[:,i,1:]) | ||
# loss = 25*torch.linalg.vector_norm(mu) + torch.sum(torch.stack([cont(point, i) for point in post_points[:, i, 1:]])) | ||
# loss = (1-lamb)*mu + lamb*torch.sum(torch.stack([cont(point, i) for point in post_points[:, i, 1:]]))/len(post_points[:,i,1:]) | ||
loss = mu + lamb*torch.sum(torch.stack([cont(point, i) for point in post_points[:, i, 1:]])) | ||
|
||
if i==len(times)-1 and (epoch+1)%10==0: | ||
f = 1 | ||
# if i==len(times)-1 and (epoch+1)%10==0: | ||
# f = 1 | ||
# Backward pass and optimize | ||
# pretty sure I'll need to modify this if I'm not doing batch training | ||
# will just putting optimizer on the earlier for loop help? | ||
|
@@ -178,7 +178,8 @@ def sample_initial(num_samples: int = num_samples) -> List[List[float]]: | |
t = torch.tensor([times[i]], dtype=torch.float32) | ||
mu = model(t) | ||
cont = lambda p, i: torch.linalg.vector_norm(torch.relu(C@torch.linalg.inv(bases[i])@(p-centers[i])-mu*g)) | ||
loss = (1-lamb)*mu + lamb*torch.sum(torch.stack([cont(point, i) for point in post_points[:, i, 1:]]))/len(post_points[:,i,1:]) | ||
loss = mu + lamb*torch.sum(torch.stack([cont(point, i) for point in post_points[:, i, 1:]]))/len(post_points[:,i,1:]) | ||
# loss = (1-lamb)*mu + lamb*torch.sum(torch.stack([cont(point, i) for point in post_points[:, i, 1:]]))/len(post_points[:,i,1:]) | ||
print(f'loss: {loss.item():.4f}, mu: {mu.item():.4f}, time: {t.item():.1f}') | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters