Nearly finished 1st draft of species-specific Thresh-LP invariance figure (WIP).

This commit is contained in:
j-hartling
2026-03-13 17:15:03 +01:00
parent 4f5054c8fd
commit 1516fe6090
19 changed files with 735 additions and 239 deletions

View File

@@ -14,28 +14,30 @@ save_path = '../data/inv/full/'
# ANALYSIS SETTINGS:
example_scales = np.array([0, 0.5, 1, 5, 10])
scales = np.linspace(0, 10, 100)
scales = np.geomspace(0.01, 10, 100)
scales = np.unique(np.concatenate((scales, example_scales)))
# EXECUTION:
for data_path, name in zip(data_paths, crop_paths(data_paths)):
print(f'Processing {name}')
# Get normalized song recording:
# Get song recording:
data, config = load_data(data_path, files='raw')
song, rate = data['raw'], config['rate']
song /= song.std(axis=0)
# Get normalized noise:
rng = np.random.default_rng()
noise = rng.normal(size=song.shape[0])
noise /= noise.std()
# Get song segment to be analyzed:
time = np.arange(song.shape[0]) / rate
start, end = data['songs_0'].ravel()
segment = (time >= start) & (time <= end)
# Normalize song component:
song /= song[segment].std(axis=0)
# Get normalized noise:
rng = np.random.default_rng()
noise = rng.normal(size=song.shape[0])
noise /= noise[segment].std()
# Prepare snippet storage:
shape_low = (song.shape[0], example_scales.size)
shape_high = (song.shape[0], config['k_specs'].shape[0], example_scales.size)
@@ -82,25 +84,11 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
scale_ind = np.nonzero(example_scales == scale)[0][0]
snippets[stage][:, ..., scale_ind] = signals[stage]
# Log "intensity measure" per stage:
# Log intensity measure per stage (excluding binary):
if stage in ['raw', 'filt', 'env', 'log', 'inv', 'conv']:
measures[key][i] = signals[stage][segment, ...].std(axis=0)
elif stage == 'feat':
measures[key][i] = signals[stage][segment, :].mean(axis=0) / signals[stage][segment, :].std(axis=0)
# Relate to smallest scale:
base_ind = np.argmin(scales)
for stage in stages:
if stage == 'bi':
continue
key = f'measure_{stage}'
measures[key] /= measures[key][base_ind, ...]
if stage in ['conv', 'feat']:
spread = np.zeros((2, scales.size))
spread[0] = np.percentile(measures[key], 25, axis=1)
spread[1] = np.percentile(measures[key], 75, axis=1)
measures[f'spread_{stage}'] = spread
measures[key] = np.median(measures[key], axis=1)
measures[key][i] = signals[stage][segment, :].mean(axis=0)
# Save analysis results:
if save_path is not None: