plotting
This commit is contained in:
parent
4159e44ae6
commit
acf981d339
@ -41,10 +41,13 @@ Won't do, this is trivial?!
|
||||
|
||||
### 3. Does the chirp increase the detectablility of another animal?
|
||||
|
||||
* Work out the difference between baseline activity and a foreign chirp response:
|
||||
* Work out the difference between baseline activity and a foreign chirp response: --> done
|
||||
* calculate the discriminability between the baseline (no-other fish present) and the another fish is present for each contrast
|
||||
* Work out the difference between the soliloquy and the response to self generated chirp in a communication context
|
||||
* Compare to the beat alone parts of the responses.
|
||||
* What kernels to use?
|
||||
* Duration of the chrip window?
|
||||
* sorting according to phase?
|
||||
|
||||
## Random thoughts
|
||||
|
||||
|
@ -285,7 +285,7 @@ def foreign_fish_detection_beat(block_map, df, all_contrasts, all_conditions, ke
|
||||
score = np.hstack((valid_distances_baseline, valid_distances_comparison))
|
||||
fpr, tpr, _ = roc_curve(group, score, pos_label=1)
|
||||
auc = roc_auc_score(group, score)
|
||||
detection_performances.append({"cell": cell_name, "detection_task": "beat", "contrast": contrast, "df": df, "kernel_width": kernel_width, "auc": auc, "true positives": tpr, "false positives": fpr})
|
||||
detection_performances.append({"cell": cell_name, "detection_task": "beat", "contrast": contrast, "df": df, "kernel_width": kernel_width, "auc": auc, "true_positives": tpr, "false_positives": fpr})
|
||||
print("\n")
|
||||
return detection_performances
|
||||
|
||||
@ -361,34 +361,75 @@ def foreign_fish_detection_chirp(block_map, df, all_contrasts, all_conditions, k
|
||||
score = np.hstack((valid_no_other_distances, valid_self_vs_alone_distances))
|
||||
fpr, tpr, _ = roc_curve(group, score, pos_label=1)
|
||||
auc = roc_auc_score(group, score)
|
||||
detection_performances.append({"cell": cell_name, "detection_task": "self vs soliloquy", "contrast": contrast, "df": df, "kernel_width": kernel_width, "auc": auc, "true positives": tpr, "false positives": fpr})
|
||||
detection_performances.append({"cell": cell_name, "detection_task": "self vs soliloquy", "contrast": contrast, "df": df, "kernel_width": kernel_width, "auc": auc, "true_positives": tpr, "false_positives": fpr})
|
||||
|
||||
group = np.hstack((baseline_temp, other_vs_baseline_temp))
|
||||
score = np.hstack((valid_baseline_distances, valid_other_vs_baseline_distances))
|
||||
fpr, tpr, _ = roc_curve(group, score, pos_label=1)
|
||||
auc = roc_auc_score(group, score)
|
||||
detection_performances.append({"cell": cell_name, "detection_task": "other vs quietness", "contrast": contrast, "df": df, "kernel_width": kernel_width, "auc": auc, "true positives": tpr, "false positives": fpr})
|
||||
detection_performances.append({"cell": cell_name, "detection_task": "other vs quietness", "contrast": contrast, "df": df, "kernel_width": kernel_width, "auc": auc, "true_positives": tpr, "false_positives": fpr})
|
||||
|
||||
print("\n")
|
||||
return detection_performances
|
||||
|
||||
|
||||
def plot_detection_results(detection_beat, detection_chirp):
|
||||
|
||||
pass
|
||||
def plot_detection_results(data_frame, df, kernel_width, cell):
|
||||
cell_results = data_frame[(data_frame.cell == cell) & (data_frame.df == df)]
|
||||
conditions = sorted(cell_results.detection_task.unique())
|
||||
kernels = sorted(cell_results.kernel_width.unique())
|
||||
|
||||
fig = plt.figure(figsize=(6.5, 5.5))
|
||||
fig_grid = (8, 7)
|
||||
for i, c in enumerate(conditions):
|
||||
condition_results = cell_results[cell_results.detection_task == c]
|
||||
|
||||
roc_ax = plt.subplot2grid(fig_grid, (i * 2 + i, 0), colspan=3, rowspan=2)
|
||||
auc_ax = plt.subplot2grid(fig_grid, (i * 2 + i, 4), colspan=3, rowspan=2)
|
||||
|
||||
def foreign_fish_detection(block_map, all_dfs, all_contrasts, all_conditions, current_df=None, kernel_width=0.0005, cell_name=""):
|
||||
roc_data = condition_results[condition_results.kernel_width == kernel_width]
|
||||
|
||||
contrasts = roc_data.contrast.unique()
|
||||
for c in contrasts:
|
||||
tpr = roc_data.true_positives[roc_data.contrast == c].values[0]
|
||||
fpr = roc_data.false_positives[roc_data.contrast == c].values[0]
|
||||
roc_ax.plot(fpr, tpr, label="%.3f" % c, zorder=2)
|
||||
roc_ax.legend(loc="best", fontsize=6, ncol=2, frameon=False)
|
||||
roc_ax.plot([0., 1.],[0., 1.], color="k", lw=0.5, ls="--", zorder=0)
|
||||
roc_ax.set_xlabel("false positive rate", fontsize=9)
|
||||
roc_ax.set_ylabel("true positive rate", fontsize=9)
|
||||
roc_ax.set_xticks(np.arange(0.0, 1.01, 0.5))
|
||||
roc_ax.set_xticks(np.arange(0.0, 1.01, 0.25), minor=True)
|
||||
roc_ax.set_xticklabels(np.arange(0.0, 1.01, 0.5), fontsize=8)
|
||||
roc_ax.set_yticks(np.arange(0.0, 1.01, 0.5))
|
||||
roc_ax.set_yticks(np.arange(0.0, 1.01, 0.25), minor=True)
|
||||
roc_ax.set_yticklabels(np.arange(0.0, 1.01, 0.5), fontsize=8)
|
||||
|
||||
for k in kernels:
|
||||
contrasts = np.asarray(condition_results.contrast[condition_results.kernel_width == k])
|
||||
aucs = np.asarray(condition_results.auc[condition_results.kernel_width == k])
|
||||
aucs_sorted = aucs[np.argsort(contrasts)]
|
||||
contrasts_sorted = np.sort(contrasts)
|
||||
auc_ax.plot(contrasts_sorted, aucs_sorted, marker=".", label=r"$\sigma$: %.4f" % k)
|
||||
|
||||
auc_ax.set_xlabel("contrast [%]")
|
||||
auc_ax.set_ylim([0.25, 1.0])
|
||||
auc_ax.set_ylabel("discriminability")
|
||||
auc_ax.legend(ncol=2, fontsize=6)
|
||||
auc_ax.plot([min(contrasts), max(contrasts)], [0.5, 0.5], lw=0.5, ls"--",)
|
||||
fig.savefig("discrimination.pdf")
|
||||
|
||||
|
||||
def foreign_fish_detection(block_map, all_dfs, all_contrasts, all_conditions, current_df=None, cell_name=""):
|
||||
dfs = [current_df] if current_df is not None else all_dfs
|
||||
kernels = [0.00025, 0.0005, 0.001, 0.0025, 0.005]
|
||||
result_dicts = []
|
||||
detection_performance_beat = {}
|
||||
detection_performance_chirp = {}
|
||||
for df in dfs:
|
||||
print("df: %i" % df)
|
||||
print("Foreign fish detection during beat:")
|
||||
result_dicts.extend(foreign_fish_detection_beat(block_map, df, all_contrasts, all_conditions, kernel_width, cell_name))
|
||||
print("Foreign fish detection during chirp:")
|
||||
result_dicts.extend(foreign_fish_detection_chirp(block_map, df, all_contrasts, all_conditions, kernel_width, cell_name))
|
||||
for kw in kernels:
|
||||
print("df: %i, kernel: %.4f" % (df, kw))
|
||||
print("Foreign fish detection during beat:")
|
||||
result_dicts.extend(foreign_fish_detection_beat(block_map, df, all_contrasts, all_conditions, kw, cell_name))
|
||||
print("Foreign fish detection during chirp:")
|
||||
result_dicts.extend(foreign_fish_detection_chirp(block_map, df, all_contrasts, all_conditions, kw, cell_name))
|
||||
|
||||
|
||||
break
|
||||
@ -409,7 +450,8 @@ def process_cell(filename, dfs=[], contrasts=[], conditions=[]):
|
||||
# create_response_plot(block_map, all_dfs, all_contrasts, all_conditions, 20, figure_name=fig_name)
|
||||
# fig_name = filename.split(os.path.sep)[-1].split(".nix")[0] + "_df_-100Hz.pdf"
|
||||
# create_response_plot(block_map, all_dfs, all_contrasts, all_conditions, -100, figure_name=fig_name)
|
||||
results = foreign_fish_detection(block_map, all_dfs, all_contrasts, all_conditions, current_df=20, cell_name=filename.split(os.path.sep)[-1].split(".nix")[0])
|
||||
results = foreign_fish_detection(block_map, all_dfs, all_contrasts, all_conditions, current_df=20,
|
||||
cell_name=filename.split(os.path.sep)[-1].split(".nix")[0])
|
||||
|
||||
|
||||
nf.close()
|
||||
|
Loading…
Reference in New Issue
Block a user