-
Notifications
You must be signed in to change notification settings - Fork 11
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
https://github.com/ziatdinovmax/pyroVED/issues/54 #55
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3b8bf13
added VAE_gp notebook
afcf15e
Revert "added VAE_gp notebook"
65eb3d9
added VAE_gp notebook
5ed1df6
Update VAE_gp.ipynb
utkarshp1161 bf14bd4
add: predict_on_latent
aff77c5
add: gp
43a708f
add: test, feature: ivae.predict_on_labels
bdd8008
gp trains in gp.py
0b3f6cf
remove error.txt
8fdc918
mod: (z, z_decoded) in ivae.predict_on_latent
ce0b58d
mod: (z, z_decoded) in ivae.predict_on_latent
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,3 +127,5 @@ dmypy.json | |
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
*tar.gz |
Large diffs are not rendered by default.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import pyro | ||
import pyro.contrib.gp as gp | ||
import torch | ||
from tqdm import tqdm | ||
def gp_model(input_dim: int = None, encoded_X: torch.Tensor = None, y: torch.Tensor = None, gp_iterations: int = 1): | ||
""" | ||
Returns a GP model trained on the encoded data. | ||
Args: | ||
input_dim: Dimensionality of the input data. | ||
encoded_X: Encoded data. | ||
y: Target data. | ||
Returns: | ||
gpr: GP regression model. | ||
""" | ||
# Define and train the GP model | ||
print("Training GP model...") | ||
kernel = gp.kernels.RBF(input_dim=encoded_X.shape[1]) | ||
gpr = gp.models.GPRegression(encoded_X, y, kernel) | ||
optimizer = torch.optim.Adam(gpr.parameters(), lr=0.005) | ||
loss_fn = pyro.infer.Trace_ELBO().differentiable_loss | ||
loss = loss_fn(gpr.model, gpr.guide) | ||
for _ in tqdm(range(gp_iterations)): | ||
optimizer.zero_grad() | ||
loss.backward() | ||
optimizer.step() | ||
print("GP model trained.") | ||
|
||
return gpr |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import pytest | ||
import torch | ||
import pyro | ||
import pyro.contrib.gp as gp | ||
from pyroved.utils import gp_model | ||
from pyroved import models | ||
|
||
def test_gp_model_output_shape(): | ||
input_dim = 3 | ||
num_samples = 5 | ||
encoded_X = torch.randn(num_samples, input_dim) # Random tensor for encoded_X | ||
y = torch.randn(num_samples) # Random tensor for y | ||
gpr = gp_model(input_dim, encoded_X, y) | ||
with torch.no_grad(): | ||
predictions, _ = gpr(encoded_X) | ||
assert predictions.shape == y.shape, "Output tensor shape mismatch" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Almost there... Instead of returning z, we should be returning z_decoded, which is z passed through a trained decoder. In this particular case, we can obtain it simply as z_decoded = self.manifold2d(d, plot=False).
I'm curious if there's a specific reason you don't want to train GP inside utils/gp.py?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was having something else in mind, basically having the latent coordinates rather than decoded ones. Changed as per this suggestion.
Changed training to utils. Right, this way its more modular.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In principle, we can have all three. Something like
Let me know if you would like to add this. Other than that I'm ready to merge it.