예제 #1
0
파일: plots.py 프로젝트: rmkujala/brainnets
def plot_pooled_correlation_dists_by_condition(cfg):
    """
    Plot the pooled (ie. combined, pooled) correlation distributions
    separately for each of the conditions (each list in fname_group_list)
    corresponds to a condition.

    Parameters
    ----------
    cfg : dict
        the user-specified config dictionary.
        The following keys are required::

            "group_1_mat_fnames"
            "group_2_mat_fnames"
            "group_1_color"
            "group_2_color"
            "group_1_label"
            "group_2_label"

    Returns
    -------
    fig : the matplotlib figure object
    """
    # CFGCHANGE?
    config.require(cfg, [
        "group_1_mat_fnames", "group_2_mat_fnames", "group_1_color",
        "group_2_color", "group_1_label", "group_2_label"
    ])
    fname_group_list = [cfg["group_1_mat_fnames"], cfg["group_2_mat_fnames"]]
    colors = [cfg["group_1_color"], cfg["group_2_color"]]
    labels = [cfg["group_1_label"], cfg["group_2_label"]]

    n_bins = 100
    corr_bins, corr_bin_centers = aux.get_lin_bins(n_bins, -1, 1.)
    bin_counts = [np.zeros(n_bins) for f in fname_group_list]

    fig = plt.figure()
    ax = fig.add_subplot(111)
    for i, fname_group in enumerate(fname_group_list):
        for fname in fname_group:
            flat_corr_mat = \
                dataio.get_blacklist_filtered_and_flattened_adj_mat(
                    fname, cfg["blacklist_fname"]
                )
            bin_counts[i] += aux.get_bin_counts(flat_corr_mat, corr_bins)
        # normalize
        bin_counts[i] = bin_counts[i] / \
            (np.sum(bin_counts[i] * (corr_bins[1] - corr_bins[0])))
        ax.plot(corr_bin_centers,
                bin_counts[i],
                color=colors[i],
                label=labels[i])

    ax.set_xlabel(settings.get_prop_tex_name(settings.correlation_tag))
    ax.set_ylabel(r"Probability density P(c)")
    ax.legend(loc=0)
    fig.savefig(cfg['outdata_dir'] + "pooledCorrDists.pdf",
                format="pdf",
                bbox_inches='tight')
    return fig
예제 #2
0
파일: plots.py 프로젝트: rmkujala/brainnets
def plot_pooled_corr_t_val_dists(cfg):
    """
    Plot the tvalue distributions for movie and rest

    Parameters
    ----------
    config : dict
        The following keys are required::

            "group_1_mat_fnames"
            "group_2_mat_fnames"
            "group_1_color"
            "group_2_color"
            "group_1_label"
            "group_2_label"
            "outdata_dir"
            "paired"

    Returns
    -------
    fig : the matplotlib figure object
    """
    config.require(cfg, [
        "group_1_mat_fnames", "group_2_mat_fnames", "group_1_color",
        "group_2_color", "group_1_label", "group_2_label", "outdata_dir",
        "paired"
    ])
    # get tvals
    flat_mats = dataio.get_blacklist_filtered_and_flattened_adj_mats(
        cfg["all_fnames"], cfg["blacklist_fname"])
    if cfg["paired"]:
        t_vals = measures.paired_t_value(flat_mats,
                                         len(cfg['group_1_mat_fnames']))
    else:
        t_vals = measures.unpaired_t_value(flat_mats,
                                           len(cfg['group_1_mat_fnames']))

    minVal = np.min(t_vals)
    maxVal = np.max(t_vals)
    n_bins = 100
    bins, binCenters = aux.get_lin_bins(n_bins,
                                        minVal - (np.abs(minVal) * 0.1),
                                        maxVal + (np.abs(maxVal) * 0.1))
    bin_counts = aux.get_bin_counts(t_vals, bins)
    fig = plt.figure()
    ax = fig.add_subplot(111)
    # normalize
    bin_counts = bin_counts * 1. / (np.sum(bin_counts) * (bins[1] - bins[0]))
    labels = cfg['group_1_label'], cfg["group_2_label"]
    ax.plot(binCenters, bin_counts, label=r"" + labels[0] + "-" + labels[1])
    ax.set_xlabel(settings.get_prop_tex_name(settings.tval_tag))
    ax.set_ylabel(r"Probability density")
    ax.legend(loc=0)
    plt.savefig(cfg["outdata_dir"] + "tvalDist.pdf",
                format="pdf",
                bbox_inches='tight')
    return fig
예제 #3
0
파일: plots.py 프로젝트: rmkujala/brainnets
def plot_corr_dists_subjectwise(cfg):
    """
    Plotting the individual correlation profiles to see the variations.

    Parameters
    ----------
    cfg : dict
        the user-specified config dictionary.
        The following keys are required::

            "group_1_mat_fnames"
            "group_2_mat_fnames"
            "group_1_color"
            "group_2_color"
            "group_1_label"
            "group_2_label"
            "outdata_dir"

    Returns
    -------
    fig : the matplotlib figure object
    """
    fname_group_list = [cfg["group_1_mat_fnames"], cfg["group_2_mat_fnames"]]
    colors = [cfg["group_1_color"], cfg["group_2_color"]]
    labels = [cfg["group_1_label"], cfg["group_2_label"]]
    rc('legend', fontsize=8)
    fig = plt.figure()
    n_bins = 100
    n = len(fname_group_list[0])
    ax_x, ax_y = _get_subplot_x_y(n)
    for i, _ in enumerate(fname_group_list[0]):  # now n1 is n2)
        ax = fig.add_subplot(ax_y, ax_x, i + 1)
        for j, fname_group in enumerate(fname_group_list):
            corr_bins, corr_bin_centers = aux.get_lin_bins(n_bins, -1, 1.)
            flat_corr_mat = \
                dataio.get_blacklist_filtered_and_flattened_adj_mat(
                    fname_group[i], cfg["blacklist_fname"]
                )
            bin_counts = aux.get_bin_counts(flat_corr_mat, corr_bins)
            # normalize
            bin_counts = bin_counts / \
                (np.sum(bin_counts * (corr_bins[1] - corr_bins[0])))
            ax.plot(corr_bin_centers,
                    bin_counts,
                    color=colors[j],
                    label=labels[j] + "\_" + str(i))


#        ax.set_xlabel(settings.get_prop_tex_name("corr"))
#        ax.set_ylabel(r"Probability density P(c)")
        ax.legend(loc=0)
    plt.tight_layout()
    fig.savefig(cfg["outdata_dir"] + "individualCorrDistsSubjectwise.pdf",
                format="pdf",
                bbox_inches='tight')
    return fig
예제 #4
0
파일: plots.py 프로젝트: rmkujala/brainnets
def plot_individual_correlation_dists(cfg):
    """
    Plotting the individual correlation profiles to see the variations.

    Parameters
    ----------
    cfg : dict
        the user-specified config dictionary.
        The following keys are required::

            "group_1_mat_fnames"
            "group_2_mat_fnames"
            "group_1_color"
            "group_2_color"
            "group_1_label"
            "group_2_label"
            "outdata_dir"

    Returns
    -------
    fig : the matplotlib figure object
    """
    # CFGCHANGE?
    config.require(cfg, )
    fname_group_list = [cfg["group_1_mat_fnames"], cfg["group_2_mat_fnames"]]
    colors = [cfg["group_1_color"], cfg["group_2_color"]]
    labels = [cfg["group_1_label"], cfg["group_2_label"]]

    fig = plt.figure()
    ax = fig.add_subplot(111)
    n_bins = 100
    corr_bins, corr_bin_centers = aux.get_lin_bins(n_bins, -1, 1.)

    for i, fname_group in enumerate(fname_group_list):
        for fname in fname_group:
            flat_corr_mat = \
                dataio.get_blacklist_filtered_and_flattened_adj_mat(
                    fname, cfg['blacklist_fname']
                )
            bin_counts = aux.get_bin_counts(flat_corr_mat, corr_bins)
            # normalize
            bin_counts = bin_counts / \
                (np.sum(bin_counts * (corr_bins[1] - corr_bins[0])))
            ax.plot(corr_bin_centers,
                    bin_counts,
                    color=colors[i],
                    label=labels[i])

    ax.set_xlabel(settings.get_prop_tex_name("corr"))
    ax.set_ylabel(r"Probability density P(c)")
    ax.legend(loc=0)
    fig.savefig(cfg['outdata_dir'] + "individualCorrDists.pdf",
                format="pdf",
                bbox_inches='tight')
    return fig
예제 #5
0
def plot_lin_pdf(ax,
                 values,
                 n_bins=100,
                 color="r",
                 label=None,
                 normalize=True):
    """
    Plots a PDF with linear bins.

    Parameters
    ----------
    ax : matplotlib axes object
        the axes to plot to
    values : 1D numpy array
        the values of the pdf
    n_bins : int, optional
        the number of bins in the pdf
    color : any valid matplotlib color, optional
        the color which the pdf is plotted with
    label : str, optional
        the label of the pdf
    normalize : bool, optional
        if False, the counts are shown instead of the pdf
    """
    values = np.array(values)
    val_max = np.max(values)
    val_min = np.min(values)
    linbins, bin_centers = aux.get_lin_bins(n_bins,
                                            val_min - 0.1 * np.abs(val_min),
                                            val_max + 0.1 * np.abs(val_max))
    bin_counts = np.bincount(np.digitize(values, linbins),
                             minlength=n_bins + 1)[1:]
    # normalize
    if normalize:
        bin_counts = bin_counts * 1. / \
            (len(values) * (linbins[1] - linbins[0]))
    if label is not None:
        ax.plot(bin_centers, bin_counts, color=color, label=label)
    else:
        ax.plot(bin_centers, bin_counts, color=color)