Wrote results for pipeline_full, pipeline_short, and feat_cross_species.
This commit is contained in:
@@ -2,7 +2,7 @@ import plotstyle_plt
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from itertools import product
|
||||
from scipy.stats import ttest_ind
|
||||
from scipy.stats import ttest_ind, mannwhitneyu
|
||||
from thunderhopper.modeltools import load_data
|
||||
from thunderhopper.filetools import search_files
|
||||
from thunderhopper.filtertools import find_kern_specs
|
||||
@@ -15,7 +15,7 @@ from IPython import embed
|
||||
# GENERAL SETTINGS:
|
||||
cross_species = [
|
||||
'Chorthippus_biguttulus',
|
||||
# 'Chorthippus_mollis',
|
||||
'Chorthippus_mollis',
|
||||
'Chrysochraon_dispar',
|
||||
# 'Euchorthippus_declivus',
|
||||
'Gomphocerippus_rufus',
|
||||
@@ -410,11 +410,17 @@ for x, y in product(range(n_song), range(n_song)):
|
||||
# print('\nAxis position: ', (y, x))
|
||||
# print(f'Song {song_labels[x]} (x) vs. Song {song_labels[y]} (y)')
|
||||
|
||||
print('\nMedian correlation coefficients:')
|
||||
print(f'Intraspecies: {np.median(song_regs)}')
|
||||
print(f'Interspecies: {np.median(spec_regs)}')
|
||||
|
||||
if test_regression:
|
||||
song_regs, spec_regs = np.array(song_regs), np.array(spec_regs)
|
||||
|
||||
# Add test result subplot:
|
||||
test_ax = fig.add_subplot(test_ax_bounds)
|
||||
test_ax.set_xlim(-0.6, 1.6)
|
||||
test_ax.set_ylim(0, 1)
|
||||
test_ax.set_ylim(-0.15, 1)
|
||||
test_ax.yaxis.set_major_locator(plt.MultipleLocator(yloc_test))
|
||||
ylabel(test_ax, ylab_test, **ylab_test_kwargs)
|
||||
|
||||
@@ -425,15 +431,22 @@ if test_regression:
|
||||
test_ax.plot(np.zeros(len(spec_regs)), spec_regs, **boxplot_dot_kwargs)
|
||||
test_ax.plot(np.ones(len(song_regs)), song_regs, **boxplot_dot_kwargs)
|
||||
|
||||
# CAREFUL - PSEUDO-REPLICATION:
|
||||
|
||||
# Perform t-test:
|
||||
test = ttest_ind(spec_regs, song_regs, equal_var=False)
|
||||
t, p = test.pvalue, test.statistic
|
||||
p, t = test.pvalue, test.statistic
|
||||
print(f'\nT-test result: t={t}, p={p}')
|
||||
|
||||
# Perform Wilcoxon rank-sum test:
|
||||
test = mannwhitneyu(spec_regs, song_regs, alternative='two-sided')
|
||||
p, u = test.pvalue, test.statistic
|
||||
print(f'\nMWU rank test result: U={u}, p={p}')
|
||||
|
||||
if save_path is not None:
|
||||
fig.savefig(save_path)
|
||||
plt.show()
|
||||
|
||||
embed()
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -149,7 +149,7 @@ lw = dict(
|
||||
)
|
||||
xlabels = dict(
|
||||
alpha='scale $\\alpha$',
|
||||
sigma='$\\sigma_{\\text{adapt}}$',
|
||||
sigma='$\\sigma_{\\text{adapt}}[\\text{dB}]$',
|
||||
)
|
||||
ylabels = dict(
|
||||
inv='$x_{\\text{adapt}}$\n$[\\text{dB}]$',
|
||||
|
||||
@@ -13,12 +13,12 @@ from IPython import embed
|
||||
target_species = [
|
||||
'Chorthippus_biguttulus',
|
||||
'Chorthippus_mollis',
|
||||
# 'Chrysochraon_dispar',
|
||||
# 'Euchorthippus_declivus',
|
||||
# 'Gomphocerippus_rufus',
|
||||
# 'Omocestus_rufipes',
|
||||
# 'Pseudochorthippus_parallelus',
|
||||
][1]
|
||||
'Chrysochraon_dispar',
|
||||
'Euchorthippus_declivus',
|
||||
'Gomphocerippus_rufus',
|
||||
'Omocestus_rufipes',
|
||||
'Pseudochorthippus_parallelus',
|
||||
][0]
|
||||
example_file = {
|
||||
'Chorthippus_biguttulus': 'Chorthippus_biguttulus_GBC_94-17s73.1ms-19s977ms',
|
||||
'Chorthippus_mollis': 'Chorthippus_mollis_DJN_41_T28C-46s4.58ms-1m15s697ms',
|
||||
@@ -28,7 +28,7 @@ example_file = {
|
||||
'Omocestus_rufipes': 'Omocestus_rufipes_DJN_32-40s724ms-48s779ms',
|
||||
'Pseudochorthippus_parallelus': 'Pseudochorthippus_parallelus_GBC_88-6s678ms-9s32.3ms'
|
||||
}[target_species]
|
||||
data_paths = search_files(target_species, incl='GBC', dir='../data/processed/')
|
||||
data_paths = search_files(target_species, incl='DJN', dir='../data/processed/')
|
||||
noise_path = '../data/processed/white_noise_sd-1.npz'
|
||||
thresh_path = '../data/inv/full/thresholds.npz'
|
||||
stages = ['filt', 'env', 'log', 'inv', 'conv', 'feat']
|
||||
@@ -43,25 +43,22 @@ thresh_rel = np.array([0, 0.5, 1, 1.5, 2, 2.5, 3])
|
||||
|
||||
# SUBSET SETTINGS:
|
||||
kernels = None
|
||||
types = None
|
||||
sigmas = None
|
||||
types = None#np.array([1, -1, 2, -2, 3, -3, 4, -4])
|
||||
sigmas = None#np.array([0.001, 0.002, 0.004, 0.008, 0.016])
|
||||
|
||||
# PREPARATION:
|
||||
pure_noise = np.load(noise_path)['raw']
|
||||
thresh_data = dict(np.load(thresh_path))
|
||||
thresh_abs = thresh_rel[:, None] * thresh_data['sds'][None, :]
|
||||
thresh_data = np.load(thresh_path)['sds']
|
||||
thresh_abs = thresh_rel[:, None] * thresh_data[None, :]
|
||||
|
||||
# EXECUTION:
|
||||
for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
save_detailed = example_file in name
|
||||
print(f'Processing {name}')
|
||||
if 'BM04' in name:
|
||||
continue
|
||||
|
||||
# Get song recording (prior to anything):
|
||||
data, config = load_data(data_path, files='raw')
|
||||
song, rate = data['raw'], config['rate']
|
||||
print(song.shape, song.size)
|
||||
song, rate = copy.deepcopy(data['raw']), config['rate']
|
||||
|
||||
# Reduce to kernel subset:
|
||||
if any(var is not None for var in [kernels, types, sigmas]):
|
||||
@@ -73,15 +70,19 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
|
||||
# Get song segment to be analyzed:
|
||||
time = np.arange(song.shape[0]) / rate
|
||||
start, end = data['songs_0'].ravel()
|
||||
start, end = copy.deepcopy(data['songs_0'].ravel())
|
||||
segment = (time >= start) & (time <= end)
|
||||
del data, time
|
||||
gc.collect()
|
||||
|
||||
# Normalize song component:
|
||||
song /= song[segment].std(axis=0)
|
||||
|
||||
# Get normalized noise component:
|
||||
noise = draw_noise_segment(pure_noise, song.shape[0])
|
||||
noise = copy.deepcopy(draw_noise_segment(pure_noise, song.shape[0]))
|
||||
noise /= noise[segment].std()
|
||||
del pure_noise
|
||||
gc.collect()
|
||||
|
||||
# Prepare storage:
|
||||
shape_low = (scales.size,)
|
||||
@@ -128,6 +129,8 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
snippets[f'snip_{stage}'][:, ..., scale_ind] = copy.deepcopy(signals[stage])
|
||||
|
||||
conv = copy.deepcopy(signals['conv'])
|
||||
for stage in pre_stages:
|
||||
del signals[stage]
|
||||
del scaled, signals
|
||||
gc.collect()
|
||||
|
||||
@@ -161,7 +164,7 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
archive.update(snippets)
|
||||
save_data(save_path + name, archive, config, overwrite=True)
|
||||
del archive
|
||||
del measures, data, config, conv
|
||||
del measures, config, conv
|
||||
if save_detailed:
|
||||
del snippets
|
||||
gc.collect()
|
||||
|
||||
@@ -10,14 +10,14 @@ from IPython import embed
|
||||
|
||||
# GENERAL SETTINGS:
|
||||
target_species = [
|
||||
'Chorthippus_biguttulus',
|
||||
# 'Chorthippus_biguttulus',
|
||||
'Chorthippus_mollis',
|
||||
'Chrysochraon_dispar',
|
||||
'Euchorthippus_declivus',
|
||||
'Gomphocerippus_rufus',
|
||||
'Omocestus_rufipes',
|
||||
'Pseudochorthippus_parallelus',
|
||||
][6]
|
||||
# 'Omocestus_rufipes',
|
||||
# 'Pseudochorthippus_parallelus',
|
||||
][1]
|
||||
example_file = {
|
||||
'Chorthippus_biguttulus': 'Chorthippus_biguttulus_GBC_94-17s73.1ms-19s977ms',
|
||||
'Chorthippus_mollis': 'Chorthippus_mollis_DJN_41_T28C-46s4.58ms-1m15s697ms',
|
||||
|
||||
Reference in New Issue
Block a user