Ejemplo n.º 1
0
    def predict_ratio(self, theta0, theta1, x, log=False):
        # If just one theta given, broadcast to number of samples
        theta0 = expand_array_2d(theta0, x.shape[0])
        theta1 = expand_array_2d(theta1, x.shape[0])

        self.global_model = self.global_model.to(self.device, self.dtype)
        theta0_tensor = tensor(theta0).to(self.device, self.dtype)
        theta1_tensor = tensor(theta1).to(self.device, self.dtype)
        x_tensor = tensor(x).to(self.device, self.dtype)

        _, log_likelihood_theta0 = self.global_model.log_likelihood(
            theta0_tensor, x_tensor)
        _, log_likelihood_theta1 = self.global_model.log_likelihood(
            theta1_tensor, x_tensor)

        log_likelihood_theta0 = log_likelihood_theta0.detach().numpy()
        log_likelihood_theta1 = log_likelihood_theta1.detach().numpy()

        if log:
            return log_likelihood_theta0 - log_likelihood_theta1
        return np.exp(log_likelihood_theta0 - log_likelihood_theta1)
Ejemplo n.º 2
0
    def predict_score(self, theta, x):
        # If just one theta given, broadcast to number of samples
        theta = expand_array_2d(theta, x.shape[0])

        self.maf = self.maf.to(self.device, self.dtype)
        theta_tensor = tensor(theta).to(self.device, self.dtype)
        x_tensor = tensor(x).to(self.device, self.dtype)

        _, _, score = self.maf.log_likelihood_and_score(theta_tensor, x_tensor)

        score = score.detach().numpy()

        return score
Ejemplo n.º 3
0
    def predict_checkpoint_scores(self, theta, z_checkpoints):
        # If just one theta given, broadcast to number of samples
        theta = expand_array_2d(theta, z_checkpoints.shape[0])

        self.step_model = self.step_model.to(self.device, self.dtype)
        theta_tensor = tensor(theta).to(self.device, self.dtype)
        z_checkpoints = tensor(z_checkpoints).to(self.device, self.dtype)

        that_xv_checkpoints = self.step_model.forward_trajectory(
            theta_tensor, z_checkpoints)
        that_xv_checkpoints = that_xv_checkpoints.detach().numpy()

        return that_xv_checkpoints
Ejemplo n.º 4
0
    def predict_density(self, theta, x, log=False):
        # If just one theta given, broadcast to number of samples
        theta = expand_array_2d(theta, x.shape[0])

        self.maf = self.maf.to(self.device, self.dtype)
        theta_tensor = tensor(theta).to(self.device, self.dtype)
        x_tensor = tensor(x).to(self.device, self.dtype)

        _, log_likelihood = self.maf.log_likelihood(theta_tensor, x_tensor)
        log_likelihood = log_likelihood.detach().numpy()

        if log:
            return log_likelihood
        return np.exp(log_likelihood)