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

Momentum Implemented #34

Open
wants to merge 1 commit into
base: igapt
Choose a base branch
from
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
33 changes: 22 additions & 11 deletions gapt/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -411,16 +411,23 @@ def forward(self, x: Tensor, labels: Tensor = None, z: Tensor = None):
if self.use_mask:
# unnormalize the last jet label - the normalized # of particles per jet
# (between 1/``num_particles`` and 1) - to between 0 and ``num_particles`` - 1
num_jet_particles = (labels[:, -1] * self.num_particles).int() - 1
#num_jet_particles = (labels[:, -1] * self.num_particles).int() - 1
momentum_jet_particles = labels[:, -2]
# sort the particles by the first noise feature per particle, and the first
# ``num_jet_particles`` particles receive a 1-mask, the rest 0.

#mask = (
# (x[:, :, 0].argsort(1).argsort(1) <= num_jet_particles.unsqueeze(1))
# .unsqueeze(2)
# .float()
#)
mask = (
(x[:, :, 0].argsort(1).argsort(1) <= num_jet_particles.unsqueeze(1))
(x[:, :, 0].argsort(1).argsort(1) <= momentum_jet_particles.unsqueeze(1))
.unsqueeze(2)
.float()
)
logging.debug(
f"x \n {x[:2, :, 0]} \n num particles \n {num_jet_particles[:2]} \n gen mask \n {mask[:2]}"
f"x \n {x[:2, :, 0]} \n num particles \n {momentum_jet_particles[:2]} \n gen mask \n {mask[:2]}"
)
else:
mask = None
Expand All @@ -429,17 +436,19 @@ def forward(self, x: Tensor, labels: Tensor = None, z: Tensor = None):
x = self.input_embedding(x)

# Concatenate global noise and # particles depending on conditioning
if self.n_normalized:
num_jet_particles = labels[:, -1]
else:
num_jet_particles += 1
#if self.n_normalized:
# num_jet_particles = labels[:, -1]
#else:
# num_jet_particles += 1
momentum_jet_particles = labels[:, -2]
# if self.noise_conditioning or self.n_conditioning:
# if self.noise_conditioning and self.n_conditioning:
# z = torch.cat((z, num_jet_particles.unsqueeze(1)), dim=1)
# elif self.n_conditioning:
# z = num_jet_particles.unsqueeze(1).float()
if self.n_conditioning:
z = torch.cat((z, num_jet_particles.unsqueeze(1)), dim=1)
#z = torch.cat((z, num_jet_particles.unsqueeze(1)), dim=1)
z = torch.cat((z, momentum_jet_particles.unsqueeze(1)), dim=1)
z = self.global_noise_net(z)

for sab in self.sabs:
Expand Down Expand Up @@ -580,10 +589,12 @@ def forward(self, x: Tensor, labels: Tensor = None):
# Use # particles for conditioning
if self.n_conditioning:
if self.n_normalized:
num_jet_particles = labels[:, -1]
#num_jet_particles = labels[:, -1]
momentum_jet_particles = labels[:, -2]
else:
num_jet_particles = (labels[:, -1] * self.num_particles).int()
z = torch.cat([z, num_jet_particles.unsqueeze(1).float()], dim=1)
#num_jet_particles = (labels[:, -1] * self.num_particles).int()
momentum_jet_particles = labels[:, -2]
z = torch.cat([z, momentum_jet_particles.unsqueeze(1).float()], dim=1)

z = self.cond_net(z)

Expand Down
2 changes: 1 addition & 1 deletion train.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def main():
"particle_features": JetNet.all_particle_features
if args.mask
else JetNet.all_particle_features[:-1],
"jet_features": "num_particles"
"jet_features": ["pt","num_particles"]
if (args.clabels or args.mask_c or args.gapt_mask)
else None,
"particle_normalisation": particle_norm,
Expand Down