def main():
    """
    Entry point for analysis
    """

    rsms = load_rsms()
    rdms = {partition: 1 - x for (partition, x) in rsms.items()}

    intersubject_corr_dict = {}
    for partition_name, partition_rdms in rdms.items():
        lower_tris = np.array([
            get_lower_tri(subject_rdm, with_diagonal=True)
            for subject_rdm in partition_rdms
        ])
        lower_tri_corrs = np.corrcoef(lower_tris)

        # reduce symmetric corrmat by taking lower triangle (without diagonal)
        pairwise_intersubject_corrs = get_lower_tri(lower_tri_corrs)
        intersubject_corr_dict[partition_name] = pairwise_intersubject_corrs

        print(f"Mean intersub RDM corr in {partition_name}")
        report_ttest_1_sample(pairwise_intersubject_corrs, print_mean_var=True)

    print(f"Lateral vs. medial difference")
    report_ttest_2_sample(intersubject_corr_dict["VTC_lateral"],
                          intersubject_corr_dict["VTC_medial"])
def get_partition_weights(
    thresh="thr_75",
    glm_dir="GLM_vanilla",
    metric=PRIMARY_METRIC,
    r2_control=False,
    noise_type="none",
):
    rsms = load_rsms(
        thresh=thresh,
        glm_dir=glm_dir,
        r2_control=r2_control,
        metric=metric,
        noise_type=noise_type,
    )
    rdms = {partition: 1 - x for (partition, x) in rsms.items()}
    regressors = build_regressors()

    # fit domain, category, and depth weights to each rdm
    partition_weights = {}
    for partition in PARTITIONS:
        partition_rdms = rdms[partition]

        weights_list = []
        for rdm in partition_rdms:
            lower_tri_rdm = get_lower_tri(rdm, with_diagonal=True)
            weights = fit_rdm(lower_tri_rdm, regressors, method="lsq")
            weights_list.append(weights)

        partition_weights[partition] = np.stack(weights_list)

    return partition_weights
Exemplo n.º 3
0
def get_partition_weights(
    thresh="thr_75", glm_dir="GLM_vanilla", r2_control=False, noise_type="none"
):
    rsms = load_rsms(
        thresh=thresh, glm_dir=glm_dir, r2_control=r2_control, noise_type=noise_type
    )
    rdms_by_depth = {
        partition: np.array([1 - split_by_depth(rsm) for rsm in partition_rsms])
        for (partition, partition_rsms) in rsms.items()
    }
    regressors = build_regressors()

    partition_weights = {}
    for partition in PARTITIONS:
        partition_rdms = rdms_by_depth[partition]
        subject_weights = []
        for subject_rdms in partition_rdms:
            depth_weights = []
            for depth_rdm in subject_rdms:
                weights = fit_rdm(
                    get_lower_tri(depth_rdm, with_diagonal=True),
                    regressors,
                    method="lsq",
                )
                depth_weights.append(weights)
            subject_weights.append(np.stack(depth_weights))
        partition_weights[partition] = np.stack(subject_weights)

    return partition_weights
Exemplo n.º 4
0
def load_rdms():
    """
    Retrieve distance matrices for "true" (3T 2.4mm) and "simulated" (7T downsampled
    2.4mm) data
    """

    sessions = {
        "true": {
            "fsid_session": "C1051_20161006",
            "glm_dir": "GLM_vanilla"
        },
        "simulated": {
            "fsid_session": "C1051_20160212",
            "glm_dir": "GLM_vanilla_sim2pt4",
        },
    }

    rdms = {}
    for session_name, session_info in sessions.items():
        rdms[session_name] = {}
        for partition in PARTITIONS:
            rsm = load_single_rsm(
                PATHS["rsms"],
                session_info["fsid_session"],
                glm_dir=session_info["glm_dir"],
                partition=partition,
            )
            rdms[session_name][partition] = get_lower_tri(1 - rsm,
                                                          with_diagonal=True)

    return rdms
Exemplo n.º 5
0
def build_regressors(add_intercept=True):
    """
    Provides regressor matrix for linear fits
    """
    regressor_indices = [
        np.repeat(np.arange(5), 2),  # domains
        np.arange(10),  # categories
    ]

    regressors = []
    for indices in regressor_indices:
        base = np.zeros((10, 10))
        xx, yy = np.meshgrid(indices, indices)
        base[xx == yy] = 1

        regressors.append(get_lower_tri(1 - base, with_diagonal=True))

    if add_intercept:
        ones_matrix = np.ones((10, 10))
        regressors.append(get_lower_tri(ones_matrix, with_diagonal=True))

    return np.array(regressors)
Exemplo n.º 6
0
def main():
    """
    Entry point for analysis
    """

    rsms = load_rsms()
    rdms = {name: 1 - rsm for (name, rsm) in rsms.items()}

    partition_pairs = {
        "lateral-medial": ["VTC_lateral", "VTC_medial"],
        "lateral-V1": ["VTC_lateral", "hOc1"],
        "medial-V1": ["VTC_medial", "hOc1"],
    }

    pair_corrs = {}
    for name, pair in partition_pairs.items():
        rdms_a = rdms[pair[0]]
        rdms_b = rdms[pair[1]]

        subject_corrs = []
        for a, b in zip(rdms_a, rdms_b):
            lower_tri_a = get_lower_tri(a)
            lower_tri_b = get_lower_tri(b)
            corr = np.corrcoef(np.stack((lower_tri_a, lower_tri_b)))[0, 1]
            subject_corrs.append(corr)

        print(f"\nCorrelations between {pair[0]} and {pair[1]}")
        pair_corrs[name] = np.array(subject_corrs)
        report_ttest_1_sample(np.array(subject_corrs), print_mean_var=True)

    print(f"\nt-test between lateral-medial and lateral-V1")
    report_ttest_2_sample(pair_corrs["lateral-medial"],
                          pair_corrs["lateral-V1"])

    print(f"\nt-test between lateral-medial and medial-V1")
    report_ttest_2_sample(pair_corrs["lateral-medial"],
                          pair_corrs["medial-V1"])
Exemplo n.º 7
0
def prepare_dataframe(hires_rdms, lowres_rdms):
    """
    Sets up pandas dataframe with the following fields:
        - partitions
        - subjects
        - data_srcs (resolutions)
        - magnitudes
    """

    data_src_list = list()
    subjects_list = list()
    partitions_list = list()
    magnitudes_list = list()

    for data_src_idx, rdms in enumerate([hires_rdms, lowres_rdms]):

        for partition_idx, partition_name in enumerate(["VTC_lateral", "VTC_medial"]):

            # extract mean of lower triangle of partition RDM, keeping diagonal
            # because values are strictly positive, no need to take absolute value here
            partition_rdms = rdms[partition_name]
            lower_triangle_means = np.array(
                [np.mean(get_lower_tri(x, with_diagonal=True)) for x in partition_rdms]
            )

            for sub_idx, val in enumerate(lower_triangle_means):
                magnitudes_list.append(val)
                data_src_list.append(data_src_idx)
                subjects_list.append(sub_idx)
                partitions_list.append(partition_idx)

    subjects_list = np.array(subjects_list)
    data_src_list = np.array(data_src_list)
    partitions_list = np.array(partitions_list)
    magnitudes_list = np.array(magnitudes_list)

    data = {
        "partitions": partitions_list,
        "subjects": subjects_list,
        "data_srcs": data_src_list,
        "magnitudes": magnitudes_list,
    }

    return pd.DataFrame(data=data)