Пример #1
0
    def test_full_keys(self):  # noqa:D102
        # Create an iterator over the 20 subjects.
        all_subjects = (self.data[:, :, :, i] for i in range(20))
        option = 'full'

        # Check the keys are identical.
        self.assertEqual(sorted(functional_dimensionality(
            all_subjects, 20, self.mask, option=option).keys()),
            sorted(output.dictionary_full.keys()))
Пример #2
0
    def test_functional_dimensionality_res(self):  # noqa:D102
        # Create an iterator over the 20 subjects.
        all_subjects = np.asarray([self.data[:, :, :, i] for i in range(20)])
        option = 'full'
        res = np.random.random(all_subjects.shape)

        # Check the keys are identical.
        self.assertEqual(sorted(functional_dimensionality(
            all_subjects, 20, self.mask, res=res, option=option).keys()),
            sorted(output.dictionary_full.keys()))
Пример #3
0
    def test_mean(self):  # noqa:D102
        for d in range(1, 10):
            # Get some randomly generated data with d dimensions as ground
            # truth:
            data = demo_data(nvoxels=self.nvoxels, nsubs=self.nsubs,
                             functional_dims=d, nconditions=16)
            # Create an iterator over the 20 subjects.
            all_subjects = (data[:, :, :, i] for i in range(20))
            option = 'mean'

            self.assertEqual(d, functional_dimensionality(
                all_subjects, self.nsubs, self.mask, option=option)
                ['winning_model'].mean())
Пример #4
0
    def test_mean_values(self):  # noqa:D102
        # Create an iterator over the 20 subjects.
        all_subjects = (self.data[:, :, :, i] for i in range(20))
        option = 'mean'

        # Loop through to compare the contents of both dictionaries:
        for (key, value) in functional_dimensionality(
                all_subjects, self.nsubs, self.mask, option=option).items():
            if key == 'subject_ID':
                self.assertTrue((value == output.dictionary_mean[key]).all())
            else:
                self.assertTrue(np.allclose(value,
                                            output.dictionary_mean[key]))
Пример #5
0
import pandas as pd

# load the sample data.
data = np.load('./demos/demo_data/sample_data.npy')
# "data" has the shape (64, 16, 6, 20), containing beta values for 64 voxels,
# 16 conditions, 6 sessions, 20 subjects.
nsubs = 20

# Create the subject IDs.
subject_IDs = [str(i) for i in range(1, nsubs + 1)]

# Create a 4*4*4 mask (all True) for the 64 voxels.
mask = np.ones((4, 4, 4), dtype='bool')

# Create an iterator over the 20 subjects.
all_subjects = (data[:, :, :, i] for i in range(nsubs))

# Find the dimensionality.
results = functional_dimensionality(all_subjects,
                                    nsubs,
                                    mask,
                                    subject_IDs=subject_IDs,
                                    option='mean')

# Put the output results into a dataframe and save as a CSV file.
df = pd.DataFrame.from_dict(results)
df.to_csv('./demos/demo_data/demo_real_data_output.csv')

# Show the median dimensionality:
print(df['winning_model'].median())
Пример #6
0
#!/usr/bin/env python3

from funcdim.funcdim import functional_dimensionality
import numpy as np

# load the sample data.
data = np.load('demo_data/sample_data.npy')
# "data" has the shape (64, 16, 6, 20), containing beta values for 64 voxels,
# 16 conditions, 6 sessions, 20 subjects.

# Create a 4*4*4 mask (all True) for the 64 voxels.
mask = np.ones((4, 4, 4), dtype='bool')

# Create an iterator over the 20 subjects.
all_subjects = (data[:, :, :, i] for i in range(20))

# Find the dimensionality.
results = functional_dimensionality(all_subjects, 20, mask)

print(results)