コード例 #1
0
def plot(ax, data, control_condition, color, dot_size=50, show_ylabel=True):
    """
    Produce the control sigmoid figures
    """

    x_label = "$EV_{right} - EV_{left}$"
    y_label = "p(choose right)"

    cd = control_condition

    d = data[cd]

    scatter_and_sigmoid(x=d['x'],
                        y=d['y'],
                        x_fit=d['fit']['x'],
                        y_fit=d['fit']['y'],
                        ax=ax,
                        color=color,
                        dot_size=dot_size)

    # title = LABELS_CONTROL[cd]
    # ax.set_title(title, fontsize=axis_label_font_size*1.2)

    ax.axhline(0.5,
               alpha=0.5,
               linewidth=1,
               color='black',
               linestyle='--',
               zorder=-10)
    ax.axvline(0.0,
               alpha=0.5,
               linewidth=1,
               color='black',
               linestyle='--',
               zorder=-10)

    ax.set_ylim(0.0, 1.0)
    ax.set_yticks((0, 0.5, 1))

    # Axis labels
    ax.set_xlabel(x_label)
    if show_ylabel:
        ax.set_ylabel(y_label)

    # Remove top and right borders
    ax.spines['right'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.spines['top'].set_color('none')

    txt = "$k=" + f"{data[cd]['fit'][SIG_STEEP]:.2f}" + "$" + "\n" \
        + "$x_0=" + f"{data[cd]['fit'][SIG_MID]:.2f}" + "$"

    # txt = \
    #     r"$F(x) = \dfrac{1}{1 + \exp(-k (x - x_0))}$" + "\n\n" \
    #     + "$k=" + f"{data[cd]['fit'][SIG_STEEP]:.2f}" + "$" + "\n" \
    #     + "$x_0=" + f"{data[cd]['fit'][SIG_MID]:.2f}" + "$" + "\n"
    add_text(ax, txt)
コード例 #2
0
def plot(ax, data, color='C0', show_ylabel=True, dot_size=50):
    """
    Produce the figure which presents at which extent
    the risky option was chosen according to the difference
    between expected values,
    i.e. the certainty-risk trade-off figure
    """

    scatter_and_sigmoid(x=data['x'],
                        y=data['y'],
                        x_fit=data['fit']['x'],
                        y_fit=data['fit']['y'],
                        color=color,
                        ax=ax,
                        dot_size=dot_size)

    ax.axhline(0.5,
               alpha=0.5,
               linewidth=1,
               color='black',
               linestyle='--',
               zorder=-10)
    ax.axvline(0,
               alpha=0.5,
               linewidth=1,
               color='black',
               linestyle='--',
               zorder=-10)

    ax.set_ylim(0.0, 1.0)
    ax.set_yticks((0, 0.5, 1))

    # Axis labels
    ax.set_xlabel(r"$EV_{riskiest} - EV_{safest}$")

    if show_ylabel:
        ax.set_ylabel("p(choose riskiest)")

    # Remove top and right borders
    ax.spines['right'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.spines['top'].set_color('none')

    txt = "$k=" + f"{data['fit'][SIG_STEEP]:.2f}" + "$" + "\n"\
        + "$x_0=" + f"{data['fit'][SIG_MID]:.2f}" + "$" \

    # txt = \
    #     r"$F(x) = \dfrac{1}{1 + \exp(-k (x - x_0))}$" + "\n\n" \
    #     + "$k=" + f"{data['fit'][SIG_STEEP]:.2f}" + "$" + "\n"\
    #     + "$x_0=" + f"{data['fit'][SIG_MID]:.2f}" + "$" + "\n" \

    add_text(ax, txt)
コード例 #3
0
def plot(ax, data, linestyles=None, color='C0'):
    """
    Produce the probability distortion figure
    """

    fit_distortion = data["distortion"]
    class_model = data["class_model"]

    if linestyles is None:
        linestyles = ['-' for _ in range(len(fit_distortion))]

    for j in range(len(fit_distortion)):

        _line(class_model=class_model,
              param=fit_distortion[j],
              color=color,
              alpha=0.5,
              linewidth=1,
              linestyle=linestyles[j],
              ax=ax)

    v_mean = np.mean(fit_distortion)
    v_std = np.std(fit_distortion)
    _line(class_model=class_model,
          param=v_mean,
          linewidth=3,
          color=color,
          ax=ax)
    add_text(ax, r'$\alpha=' + f'{v_mean:.2f}\pm{v_std:.2f}' + '$')

    ax.set_xlabel('$p$')
    ax.set_ylabel('$w(p)$')

    ax.set_ylim(0, 1)
    ax.set_xlim(-0.01, 1.01)
    ax.set_aspect('equal')

    ax.spines['right'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.spines['top'].set_color('none')

    ax.plot((0, 1), (0, 1),
            alpha=0.5,
            linewidth=1,
            color='black',
            linestyle='--',
            zorder=-10)

    ax.set_xticks((0, 0.5, 1))
    ax.set_yticks((0, 0.5, 1))

    ax.tick_params(axis='both', which='major')
コード例 #4
0
ファイル: utility.py プロジェクト: rougier/EvoProspect-1
def plot(ax, data, linestyles=None, color='C0', alpha_chunk=0.5):
    """
    Produce the utility function figure
    """

    pr = data['risk_aversion']
    class_model = data['class_model']
    cond = data['cond']

    if linestyles is None:
        linestyles = ['-' for _ in range(len(pr))]

    if cond == GAIN:
        x = np.linspace(0, 1, 1000)
        ax.set_xlim(0, 1)
        ax.set_ylim(0, 1)

        ax.set_xticks([0, 1])
        ax.set_yticks([0, 1])

        ax.plot((0, 1), (0, 1),
                alpha=0.5,
                linewidth=1,
                color='black',
                linestyle='--',
                zorder=-10)
    elif cond == LOSS:
        x = np.linspace(-1, 0, 1000)
        ax.set_xlim(-1, 0)
        ax.set_ylim(-1, 0)

        ax.set_xticks([-1, 0])
        ax.set_yticks([-1, 0])

        ax.plot((-1, 0), (-1, 0),
                alpha=0.5,
                linewidth=1,
                color='black',
                linestyle='--',
                zorder=-10)
    else:
        raise ValueError

    for j in range(len(pr)):
        _line(x=x,
              class_model=class_model,
              risk_aversion=pr[j],
              color=color,
              ax=ax,
              linewidth=1,
              alpha=alpha_chunk,
              linestyle=linestyles[j])

    v_mean = np.mean(pr)
    v_std = np.std(pr)
    _line(x=x,
          risk_aversion=v_mean,
          class_model=class_model,
          ax=ax,
          color=color)

    add_text(ax, r'$\beta=' + f'{v_mean:.2f}\pm{v_std:.2f}' + '$')

    ax.spines['right'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.spines['top'].set_color('none')

    ax.set_xlabel("$x$")
    ax.set_ylabel("$u(x)$")

    ax.set_aspect(1)
コード例 #5
0
def plot(ax, data, linestyles=None, color='C0'):
    """
    Produce the precision figure
    """

    n_points = 1000

    v_mean = np.mean(data['precision'])
    v_std = np.std(data['precision'])

    n_chunk = len(data['precision'])

    class_model = data['class_model']

    if class_model.__name__ == "DMSciReports":

        p0 = 0.5
        p1, x1 = 1., 0.25

        x0_equal_ev = x1 * (1 / p0)

        x0_list = np.linspace(x1 + 0.01, 1.00, n_points)

        x = x0_list / x1

        pairs = []

        for i, x0 in enumerate(x0_list):
            pairs.append({"p0": p0, "x0": x0, "p1": p1, "x1": x1})

        y = np.zeros((n_chunk, len(x)))

        for i_c in range(n_chunk):

            dm = class_model([data[k][i_c] for k in class_model.param_labels])

            for i_p, p in enumerate(pairs):
                y[i_c, i_p] = dm.p_choice(c=0, **p)

        dm = class_model([np.mean(data[k]) for k in class_model.param_labels])
        y_mean = np.zeros(len(x))
        for i_p, p in enumerate(pairs):
            y_mean[i_p] = dm.p_choice(c=0, **p)

        ax.axvline(x0_equal_ev / x1,
                   alpha=0.5,
                   linewidth=1,
                   color='black',
                   linestyle='--',
                   zorder=-10)

        x_label = r"$\frac{x_{risky}}{x_{safe}}$"
        y_label = "P(Choose risky option)"
        text = r'$\lambda=' + f'{v_mean:.2f}\pm{v_std:.2f}' + '$'

    elif class_model.__name__ == "AgentSoftmax":

        fit_precision = data['precision']

        x = np.linspace(-1, 1, n_points)
        y = np.zeros((n_chunk, len(x)))
        for i_c in range(n_chunk):
            v = fit_precision[i_c]
            y[i_c] = class_model.softmax(x, v)

        y_mean = np.zeros(len(x))
        y_mean[:] = class_model.softmax(x, v_mean)

        ax.axvline(0,
                   alpha=0.5,
                   linewidth=1,
                   color='black',
                   linestyle='--',
                   zorder=-10)

        x_label = r"$SEU(L_{1}) - SEU(L_{2})$"
        y_label = "$P(Choose L_{1})$"
        text = r'$\lambda=' + f'{v_mean:.2f}\pm{v_std:.2f}' + '$'

    elif class_model.__name__ == "AgentSideAdditive":

        fit_precision = data['precision']
        fit_side_bias = data['side_bias']

        x = np.linspace(-1, 1, n_points)
        y = np.zeros((n_chunk, len(x)))
        for i_c in range(n_chunk):
            v = fit_precision[i_c]
            x_biased = x + fit_side_bias[i_c]
            y[i_c] = class_model.softmax(x_biased, v)

        y_mean = np.zeros(len(x))
        mean_side_bias = np.mean(fit_side_bias)
        std_side_bias = np.std(fit_side_bias)
        x_biased = x + mean_side_bias
        y_mean[:] = class_model.softmax(x_biased, v_mean)

        ax.axvline(0,
                   alpha=0.5,
                   linewidth=1,
                   color='black',
                   linestyle='--',
                   zorder=-10)

        x_label = r"$SEU(L_{right}) - SEU(L_{left})$"
        y_label = "$P(Choose\,L_{right})$"
        text = r'$\lambda=' + f'{v_mean:.2f}\pm{v_std:.2f}' + '$\n' \
            + r'$\gamma=' + f'{mean_side_bias:.2f}\pm{std_side_bias:.2f}' + '$\n'

    elif class_model.__name__ == "AgentSide":

        fit_precision = data['precision']
        # fit_side_bias = data['side_bias']

        x = np.linspace(-1, 1, n_points)
        y = np.zeros((n_chunk, len(x)))
        for i_c in range(n_chunk):
            v = fit_precision[i_c]
            y[i_c] = class_model.softmax(x, v)

        y_mean = np.zeros(len(x))
        y_mean[:] = class_model.softmax(x, v_mean)

        ax.axvline(0,
                   alpha=0.5,
                   linewidth=1,
                   color='black',
                   linestyle='--',
                   zorder=-10)

        x_label = r"$SEU(L_{right}) - SEU(L_{left})$"
        y_label = "$p(choose L_{right})$"
        text = r'$\lambda=' + f'{v_mean:.2f}\pm{v_std:.2f}' + '$'

    else:
        raise ValueError

    if linestyles is None:
        linestyles = ['-' for _ in range(len(data['precision']))]

    for i_c in range(n_chunk):
        ax.plot(x,
                y[i_c],
                color=color,
                linewidth=1,
                alpha=0.5,
                linestyle=linestyles[i_c])

    # show_average
    ax.plot(x, y_mean, color=color, linewidth=3, alpha=1)

    add_text(ax, text)

    # ax.set_xticks([0, 1, 2])
    ax.set_yticks([0, 0.5, 1])

    # ax.set_xlim(0.0, 2.01)
    ax.set_ylim(-0.01, 1.01)

    ax.spines['right'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.spines['top'].set_color('none')

    ax.axhline(0.5,
               alpha=0.5,
               linewidth=1,
               color='black',
               linestyle='--',
               zorder=-10)

    ax.set_xlabel(x_label)
    ax.set_ylabel(y_label)