Example #1
0
    def get_reconstruction_loss(self, x, px_rate, px_r, px_dropout, **kwargs):
        # Reconstruction Loss
        if self.reconstruction_loss == "nb":
            reconst_loss = -log_nb_positive(x, px_rate, px_r).sum(dim=-1) + 0.5*mean_square_error_positive(x, px_rate).sum(dim=-1)
        elif self.reconstruction_loss == "zinb":
            reconst_loss = -log_nb_positive(x, px_rate, px_r).sum(dim=-1) + 0.5*mean_square_error_positive(x, px_rate).sum(dim=-1)

        return reconst_loss
Example #2
0
    def get_reconstruction_loss(self, x, px_rate, px_r, px_dropout, **kwargs):
        # Reconstruction Loss
        if self.reconstruction_loss == "zinb":
            reconst_loss = -log_nb_positive(x, px_rate, px_r).sum(dim=-1)
        elif self.reconstruction_loss == "nb":
            reconst_loss = 0.5*mean_square_error_positive(x, px_rate).sum(dim=-1) - log_zip_positive(x, px_rate, px_dropout).sum(dim=-1)
            px_rate[x > 0] = 0
            reconst_loss = reconst_loss + 0.05*px_rate.sum(dim=-1)

        elif self.reconstruction_loss == "mse":
            reconst_loss = mean_square_error_positive(x, px_rate).sum(dim=-1)
        return reconst_loss