PattanaikL / GeoMol

MIT License
152 stars 43 forks source link

Problems about loss computation #11

Open psp3dcg opened 2 years ago

psp3dcg commented 2 years ago

Hi, Great Work! Could you please tell me the reason of subtracting the angle loss and the dihedral loss (at the bottom of code)? Thank U~ ` def batch_molecule_loss(self, true_stats, model_stats, ignore_neighbors): """ Compute loss for one pair of model/true molecules

    :param true_stats: tuple of masked true stat tensors (len 5)
    :param model_stats: tuple of masked model stat tensors (len 5)
        one-hop: (n_neighborhoods, 4)
        two-hop: (n_neighborhoods, 4, 4)
        angle: (n_neighborhoods, 6)
        dihedral: (2, n_dihedral_pairs, 9)
        three-hop: (n_dihedral_pairs, 9)
    :return: molecular loss for the batch (n_batch)
    """

    # unpack stats
    model_one_hop, model_two_hop, model_angles, model_dihedrals, model_three_hop = model_stats
    true_one_hop, true_two_hop, true_angles, true_dihedrals, true_three_hop = true_stats

    # calculate losses
    one_hop_loss, two_hop_loss, angle_loss = self.local_loss(true_one_hop, true_two_hop, true_angles,
                                                             model_one_hop, model_two_hop, model_angles)
    dihedral_loss, three_hop_loss = self.pair_loss(true_dihedrals, model_dihedrals, true_three_hop, model_three_hop)

    # writing
    self.one_hop_loss.append(one_hop_loss)
    self.two_hop_loss.append(two_hop_loss)
    self.angle_loss.append(angle_loss)
    self.dihedral_loss.append(dihedral_loss)
    self.three_hop_loss.append(three_hop_loss)

    if ignore_neighbors:
        return one_hop_loss + two_hop_loss - angle_loss
    else:
        return one_hop_loss + two_hop_loss - angle_loss + three_hop_loss - dihedral_loss`
octavian-ganea commented 2 years ago

Hi. Please see eq 8 from our paper where the angle losses are negative log-likelihoods of von Mises distributions, thus they can be written as - cos(theta - theta^*). So the losses above are just the cos() part.

psp3dcg commented 2 years ago

Hi. Please see eq 8 from our paper where the angle losses are negative log-likelihoods of von Mises distributions, thus they can be written as - cos(theta - theta^*). So the losses above are just the cos() part. OK,thank you for your quick reply~