def compute_beta(self, coord_target, target_levels=None, dataset_coord=None, dataset_levels=None, tau=0.006):
        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.pca.dataset_coord.T
            dataset_levels = [dic_slice.level for dic_slice in self.dictionary.slices]

        beta = []
        if self.param.mode_weight_similarity:
            mode_weight = [val/sum(self.pca.kept_eigenval) for val in self.pca.kept_eigenval]
        else:
            mode_weight = None

        # 3D TARGET
        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):
                    if mode_weight is None:
                        square_norm = np.linalg.norm((coord_projected_slice - coord_slice_j), 2)
                    else:
                        from scipy.spatial.distance import wminkowski
                        square_norm = wminkowski(coord_projected_slice, coord_slice_j, 2, mode_weight)

                    if target_levels is not None and target_levels is not [None] and self.param.use_levels:
                        if self.param.equation_id == 1:
                            # EQUATION #1 (better results ==> kept)
                            beta_slice.append(exp(-self.param.weight_gamma*abs(target_levels[i_target] - dataset_levels[j_slice]))*exp(-tau*square_norm))  # TODO: before = no absolute
                        elif self.param.equation_id == 2:
                            # EQUATION #2
                            if target_levels[i_target] == dataset_levels[j_slice]:
                                beta_slice.append(exp(tau*square_norm))
                            else:
                                beta_slice.append(exp(-tau*square_norm)/self.param.weight_gamma*abs(target_levels[i_target] - dataset_levels[j_slice])) #TODO: before = no absolute

                    else:
                        beta_slice.append(exp(-tau*square_norm))

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

                beta.append(beta_slice)

        # 2D TARGET
        else:
            for j_slice, coord_slice_j in enumerate(dataset_coord):
                if mode_weight is None:
                    square_norm = np.linalg.norm((coord_target - coord_slice_j), 2)
                else:
                    from scipy.spatial.distance import wminkowski
                    square_norm = wminkowski(coord_target, coord_slice_j, 2, mode_weight)
                if target_levels is not None and self.param.use_levels:
                    '''
                    if target_levels == dataset_levels[j_slice]:
                        beta.append(exp(tau*square_norm))
                    else:
                        beta.append(exp(-tau*square_norm)/self.param.weight_gamma*abs(target_levels - dataset_levels[j_slice]))
                    '''
                    beta.append(exp(-self.param.weight_gamma*abs(target_levels - dataset_levels[j_slice]))*exp(-tau*square_norm) )#TODO: before = no absolute
                else:
                    beta.append(exp(-tau*square_norm))

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

        return np.asarray(beta)

    # ------------------------------------------------------------------------------------------------------------------
Construct default body classes for a page
dataset/ETHPy150Open neuropoly/spinalcordtoolbox/dev/sct_segment_gray_matter_asman/2015-08-17-full_scripts_before_cleaning/sct_asman.py/Model.compute_beta--crossover with--dataset/ETHPy150Open Wtower/django-ninecms/ninecms/utils/render.py/NodeView.construct_classes