How to use the clinica.pipelines.machine_learning.voxel_based_io.load_data function in clinica

To help you get started, we’ve selected a few clinica examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github aramis-lab / AD-DL / Code / tensorflow / three_d_cnn / three_d_cnn_utils.py View on Github external
def get_x(self):
        """

        Returns: a numpy 2d-array.

        """
        if self._x is not None:
            return self._x

        print 'Loading ' + str(len(self.get_images())) + ' subjects'
        self._x, self._orig_shape, self._data_mask = vbio.load_data(self._images, mask=self._mask_zeros)
        print 'Subjects loaded'

        return self._x
github aramis-lab / clinica / clinica / pipelines / machine_learning / input.py View on Github external
def get_x(self):
        """

        Returns: a numpy 2d-array.

        """
        if self._x is not None:
            return self._x

        print('Loading ' + str(len(self.get_images())) + ' subjects')
        self._x, self._orig_shape, self._data_mask = vbio.load_data(self._images, mask=self._mask_zeros)
        print('Subjects loaded')

        return self._x
github aramis-lab / clinica / clinica / pipelines / machine_learning / voxel_based_svm.py View on Github external
def svm_binary_classification(image_list, diagnosis_list, output_directory, kernel_function=None, existing_gram_matrix=None, mask_zeros=True, scale_data=False, balanced=False, outer_folds=10, inner_folds=10, n_threads=10, c_range=np.logspace(-6, 2, 17), save_gram_matrix=False, save_subject_classification=False, save_dual_coefficients=False, scaler=None, data_mask=None, save_original_weights=False, save_features_image=True):

    if (kernel_function is None and existing_gram_matrix is None) | (kernel_function is not None and existing_gram_matrix is not None):
        raise ValueError('Kernel_function and existing_gram_matrix are mutually exclusive parameters.')

    results = dict()
    dx_filter = np.unique(diagnosis_list)

    print('Loading ' + str(len(image_list)) + ' subjects')
    x0, orig_shape, data_mask = load_data(image_list, mask=mask_zeros)
    print('Subjects loaded')
    if scale_data:
        x_all = scale(x0)
    else:
        x_all = x0

    if existing_gram_matrix is None:
        if kernel_function is not None:
            print('Calculating Gram matrix')
            gram_matrix = kernel_function(x_all)
            print('Gram matrix calculated')
        else:
            raise ValueError('If a Gram matrix is not provided a function to calculate it (kernel_function) is a required input.')
    else:
        gram_matrix = existing_gram_matrix
        if (gram_matrix.shape[0] != gram_matrix.shape[1]) | (gram_matrix.shape[0] != len(image_list)):
github aramis-lab / clinica / clinica / pipelines / machine_learning / voxel_based_svm_old.py View on Github external
def linear_svm_binary_classification(image_list, diagnose_list, output_directory,
                                     mask_zeros=True, balanced=False,
                                     outer_folds=10, inner_folds=10, n_threads=10, c_range=np.logspace(-6, 2, 17),
                                     save_gram_matrix=False, save_subject_classification=False,
                                     save_original_weights=False, save_features_image=True):

    results = dict()
    dx_filter = np.unique(diagnose_list)

    print 'Loading ' + str(len(image_list)) + ' subjects'

    x0, orig_shape, data_mask = load_data(image_list, mask=mask_zeros)

    print 'Subjects loaded'
    print 'Calculating Gram matrix'

    x_all = scale(np.nan_to_num(x0))
    gram_matrix = gram_matrix_linear(x_all)

    print 'Gram matrix calculated'

    if save_gram_matrix:
        np.savetxt(join(output_directory, 'gram_matrix.txt'), gram_matrix)

    # Allow loading precalculated gram_matrix?
    # gram_matrix = np.loadtxt(input_gram_matrix)

    for i in range(len(dx_filter)):