def compute_beta(self, coord_target, target_levels=None, dataset_coord=None, dataset_levels=None, tau=0.01):
        """
        Compute the model similarity (beta) between each model slice and each target image slice

        beta_j = (1/Z)exp(-tau*square_norm(target_coordinate - slice_j_coordinate))

        Z is the partition function that enforces the constraint that sum(beta)=1

        :param coord_target: coordinates of the target image in the reduced model space

        :param tau: weighting parameter indicating the decay constant associated with a geodesic distance
        between a given dictionary slice and a projected target image slice

        :return:
        """
        if dataset_coord is None:
            # in the dataset_coord matrix, each column correspond to the projection of one of the original data image,
            # the transpose operator .T enable the loop to iterate over all the images coord
            dataset_coord = self.model.pca.dataset_coord.T
            dataset_levels = [dic_slice.level for dic_slice in self.model.dictionary.slices]

        beta = []

        # TODO: SEE IF WE NEED TO CHECK THE SECOND DIMENSION OF COORD TARGET OR THE FIRST ...
        if isinstance(coord_target[0], (list, np.ndarray)):
            for i_target, coord_projected_slice in enumerate(coord_target):
                beta_slice = []
                for j_slice, coord_slice_j in enumerate(dataset_coord):
                    square_norm = np.linalg.norm((coord_slice_j - coord_projected_slice), 2)
                    if target_levels is not None:
                        if target_levels[i_target] == dataset_levels[j_slice]:
                            beta_slice.append(exp(tau*square_norm))
                        else:
                            beta_slice.append(exp(-tau*square_norm)/1.2*(target_levels[i_target] - dataset_levels[j_slice]))
                    else:
                        beta_slice.append(exp(tau*square_norm))

                try:
                    beta_slice /= np.sum(beta_slice)
                except ZeroDivisionError:
                    sct.printv('WARNING : similarities are null', self.model.param.verbose, 'warning')
                    print beta_slice

                beta.append(beta_slice)
        else:
            for j_slice, coord_slice_j in enumerate(dataset_coord):
                square_norm = np.linalg.norm((coord_target - coord_slice_j), 2)
                if target_levels is not None:
                    if target_levels == dataset_levels[j_slice]:
                        beta.append(exp(tau*square_norm))
                    else:
                        beta.append(exp(-tau*square_norm)/1.2*(target_levels - dataset_levels[j_slice]))
                else:
                    beta.append(exp(tau*square_norm))

            try:
                beta /= np.sum(beta)
            except ZeroDivisionError:
                sct.printv('WARNING : similarities are null', self.model.param.verbose, 'warning')
                print beta

        return np.asarray(beta)

    # ------------------------------------------------------------------------------------------------------------------
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/sct_segment_gray_matter_asman/sct_asman_old.py/TargetSegmentationPairwise.compute_beta/swapped operands of `-`