Ejemplo n.º 1
0
def main():
    """
    Entry point for analysis
    """

    noise_type = "gaussian" if ARGS.use_noisy_lowres else "none"

    # load both RSM types and covert to RDMs
    hires_rsms = load_rsms(glm_dir="GLM_vanilla")
    lowres_rsms = load_rsms(glm_dir="GLM_vanilla_sim2pt4", noise_type=noise_type)

    hires_rdms = {partition: 1 - x for (partition, x) in hires_rsms.items()}
    lowres_rdms = {partition: 1 - x for (partition, x) in lowres_rsms.items()}

    # get pandas dataframe
    data = prepare_dataframe(hires_rdms, lowres_rdms)

    # report on mean per data source
    hires_data = data[data.data_srcs == 0]
    lowres_data = data[data.data_srcs == 1]

    print("Hires RDM Magnitude vs. Lowres")
    report_ttest_2_sample(
        hires_data.magnitudes, lowres_data.magnitudes, print_mean_var=True
    )

    # run analysis of variance
    fpath = f"{PATHS['r_scripts']}/data/mean_abs_rdm.csv"
    data.to_csv(fpath)
    subprocess.call(
        f"Rscript --vanilla {PATHS['r_scripts']}/mean_abs_rdm_script.r {fpath}",
        shell=True,
    )
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
Ejemplo 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
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"])
Ejemplo n.º 5
0
def make_plots(glm_dir, save_dir):
    """
    Entry point for script
    """

    rsm_plot_params = {
        "beta": {"cmap": plot_utils.blueblackred, "clim": [0, 1]},
        "tnorm": {"cmap": plot_utils.blueblackred, "clim": [0, 1]},
        "tstat": {"cmap": plot_utils.blueblackred, "clim": [-0.5, 0.5]},
        "zscore": {"cmap": plot_utils.blueblackred, "clim": [-0.5, 0.5]},
        "znorm": {"cmap": plot_utils.blueblackred, "clim": [-0.5, 0.5]},
        "betasub": {"cmap": plot_utils.blueblackred, "clim": [-0.5, 0.5]},
    }

    rdm_plot_params = {
        "beta": {"cmap": plot_utils.blueblackred, "clim": [0, 1]},
        "tnorm": {"cmap": plot_utils.blueblackred, "clim": [0, 1]},
        "tstat": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]},
        "zscore": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]},
        "znorm": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]},
        "betasub": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]},
    }

    key_order = ["znorm", "tstat", "zscore", "betasub", "tnorm", "beta"]
    for metric in key_order:
        print(f"Plotting metric: {metric}")
        rsms = load_rsms(metric=metric, glm_dir=glm_dir)
        mds_anchor = get_MDS_anchor(rsms)

        mean_rsms = {}
        mean_rdms = {}
        for rsm_name, rsm in rsms.items():
            mean_rsms[rsm_name] = np.mean(rsm, axis=0, keepdims=True)
            mean_rdms[rsm_name] = np.mean(1 - rsm, axis=0, keepdims=True)

        # align the group-average RSMs to the mds anchor
        aligned_embeddings = plot_utils.embed_rsms(
            mean_rsms, alignment_anchor=mds_anchor
        )

        plot_helper(
            mean_rdms,
            aligned_embeddings,
            rdm_plot_params[metric],
            f"{save_dir}/{metric}_rdms.png",
        )
        plot_helper(
            mean_rsms,
            aligned_embeddings,
            rsm_plot_params[metric],
            f"{save_dir}/{metric}_rsms.png",
        )
Ejemplo n.º 6
0
def main():
    """
    Entry point for script
    """
    save_dir = f"{PATHS['figures']}/figure_8af_rdms_by_depth"
    mkdirquiet(save_dir)

    # define some colormaps and limits here for each metric (maybe move to constants?)
    plot_params = {
        "tstat": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]},
        "zscore": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]},
        "znorm": {"cmap": plot_utils.blueblackred, "clim": [0.5, 1.5]},
    }

    for metric in plot_params.keys():
        print(f"Plotting metric: {metric}")
        rsms = load_rsms(metric=metric)
        mean_rdms_by_depth = {
            partition: np.mean(
                [1 - split_by_depth(rsm) for rsm in partition_rsms], axis=0
            )
            for (partition, partition_rsms) in rsms.items()
        }

        base = 6
        fig, axes = plt.subplots(figsize=(base * 3, base * 2), nrows=2, ncols=3)

        for partition_idx, partition in enumerate(PARTITIONS):
            if partition == "hOc1":
                continue
            rdm_dict = {
                f"{partition}_{x}": mean_rdms_by_depth[partition][x] for x in range(3)
            }

            plot_utils.plot_rdms(
                axes[partition_idx, :],
                rdm_dict,
                cmap=plot_params[metric]["cmap"],
                clim=plot_params[metric]["clim"],
            )

        savefig(f"{save_dir}/{metric}.png")
        plt.close(fig)
def get_partition_weights(glm_dir="GLM_vanilla", noise_type="none"):
    rsms = load_rsms(glm_dir=glm_dir, 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()
    }

    # fit domain, category, and depth weights to each rdm
    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:
                domain_weights_list = []

                for domain_idx in range(5):
                    start = domain_idx * 2
                    end = start + 2
                    domain_rdm = depth_rdm[start:end, start:end]

                    within_category_mean = np.mean(
                        (domain_rdm[0, 0], domain_rdm[1, 1]))
                    between_category_mean = np.mean(
                        (domain_rdm[0, 1], domain_rdm[1, 0]))

                    domain_weights_list.append(
                        [within_category_mean, between_category_mean])

                depth_weights.append(np.stack(domain_weights_list))
            subject_weights.append(np.stack(depth_weights))
        partition_weights[partition] = np.stack(subject_weights)

    return partition_weights
Ejemplo n.º 8
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"])
Ejemplo n.º 9
0
def main():
    """
    Entry point for analysis
    """
    rsms = load_rsms()
    compute_reliability_full(rsms)