Skip to content

Commit 65c0764

Browse files
committed
psychometric reduce bins and log
1 parent d2bb8af commit 65c0764

File tree

4 files changed

+41
-86
lines changed

4 files changed

+41
-86
lines changed

To do.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ It might improve with a better prompt, but it looks like a good plan for now.
2222
and port where the animal comes from. Explore first the correlations of these regressors.
2323
For example, in correct trials, the three of them should be the same.√
2424

25-
- Psychometric for auditory. Test using log value of the evidence strength.
26-
Reduce a bit the number of bins to make it less noisy in the middle. Explore other
25+
- Psychometric for auditory. Test using log value of the evidence strength.√(The values are under 1, so their values will be changed after log)
26+
Reduce a bit the number of bins to make it less noisy in the middle. Explore other
2727
properties of the cloud of tones, and the impact they have on decisions. For instance,
2828
several tones can sound simultaneously in the same timebin. One question is:
2929
are mice affected more by the total number of tones, or by the total number of timebins

lecilab_behavior_analysis/df_transforms.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ def mean_and_cis_of_rt_and_tbt(group):
696696

697697

698698
def get_choice_before(df):
699-
df_copy = df.copy(deep=False)
699+
df_copy = df.copy(deep=True)
700700
utils.column_checker(df_copy, required_columns={"first_choice", "last_choice", "previous_port_before_stimulus", "correct"})
701701

702702
for mouse in df_copy['subject'].unique():
@@ -766,7 +766,7 @@ def parameters_for_fit(df):
766766
"""
767767
Get the parameters for the fit
768768
"""
769-
df_copy = df.copy(deep=False)
769+
df_copy = df.copy(deep=True)
770770
df_copy = add_mouse_first_choice(df_copy)
771771
df_copy = add_mouse_last_choice(df_copy)
772772
df_copy = add_port_where_animal_comes_from(df_copy)
@@ -816,7 +816,7 @@ def parameters_for_fit(df):
816816
return df_copy
817817

818818
def get_time_kernel_impact(df:pd.DataFrame, y: str, max_lag, tau):
819-
df_copy = df.copy(deep=False)
819+
df_copy = df.copy(deep=True)
820820
if y == 'first_choice_numeric':
821821
df_copy = add_mouse_first_choice(df_copy)
822822
df_copy['first_choice_numeric'] = df_copy['first_choice'].apply(

lecilab_behavior_analysis/plots.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,24 +342,25 @@ def psychometric_plot(df: pd.DataFrame, x, y, ax: plt.Axes = None,
342342
column_checker(df, required_columns={x, y})
343343
df_copy = df.copy(deep=True)
344344
if valueType == 'discrete':
345-
df_copy[x] = np.sign(df_copy[x]) * (np.log(abs(df_copy[x])).round(4))
345+
df_copy[x + "_fit"] = np.sign(df_copy[x]) * (np.log(abs(df_copy[x])).round(4))
346346
ax.set_xlabel('log_' + x)
347347
else:
348348
# bin the continuous values when valueType is not discrete
349-
df_copy[x + "_binned"] = pd.cut(df_copy[x], bins = 6, labels=False)
350-
x = x + "_binned"
349+
bins = pd.cut(df_copy[x], bins = 6)
350+
labels = df_copy[x].groupby(bins).mean()
351+
df_copy[x + "_fit"] = pd.cut(df_copy[x], bins = 6, labels = labels).astype(float)
352+
# df_copy[x + "_fit"] = np.sign(df_copy[x + "_fit"]) * (np.log(abs(df_copy[x + "_fit"])).round(4))
351353
ax.set_xlabel(x)
352354
sns.pointplot(
353-
x=x,
355+
x=x + "_fit",
354356
y=y,
355357
data=df_copy,
356358
estimator=lambda x: np.mean(x),
357359
ax=ax,
358360
**point_kwargs
359361
)
360-
361-
xs = np.linspace(df_copy[x].min(), df_copy[x].max(), 100).reshape(-1, 1)
362-
p_left, fitted_params = utils.fit_lapse_logistic_independent(df_copy[x], df_copy[y])
362+
xs = np.linspace(df_copy[x + "_fit"].min(), df_copy[x + "_fit"].max(), 100).reshape(-1, 1)
363+
p_left, fitted_params = utils.fit_lapse_logistic_independent(df_copy[x + "_fit"], df_copy[y])
363364
ax.plot(xs, p_left, **line_kwargs)
364365
ax.set_ylabel(y)
365366
ax.set_ylim(0, 1)

lecilab_behavior_analysis/task_hard_version_playground.ipynb

Lines changed: 28 additions & 74 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)