Lots of stuff. Syncing to home.
This commit is contained in:
@@ -3,6 +3,7 @@ import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from thunderhopper.modeltools import load_data, save_data
|
||||
from thunderhopper.filetools import crop_paths
|
||||
from thunderhopper.filtertools import find_kern_specs
|
||||
from thunderhopper.model import process_signal
|
||||
from IPython import embed
|
||||
|
||||
@@ -13,9 +14,20 @@ stages = ['raw', 'filt', 'env', 'log', 'inv', 'conv', 'bi', 'feat']
|
||||
save_path = '../data/inv/full/'
|
||||
|
||||
# ANALYSIS SETTINGS:
|
||||
example_scales = np.array([0, 0.5, 1, 5, 10])
|
||||
scales = np.geomspace(0.01, 10, 100)
|
||||
example_scales = np.array([0, 1, 10, 50])
|
||||
scales = np.geomspace(0.01, 100, 100)
|
||||
scales = np.unique(np.concatenate((scales, example_scales)))
|
||||
kernels = np.array([
|
||||
[1, 0.002],
|
||||
[-1, 0.002],
|
||||
[2, 0.004],
|
||||
[-2, 0.004],
|
||||
[3, 0.032],
|
||||
[-3, 0.032]
|
||||
])
|
||||
kernels = None
|
||||
types = None#np.array([-1])
|
||||
sigmas = None#np.array([0.001, 0.002, 0.004, 0.008, 0.016, 0.032])
|
||||
|
||||
# EXECUTION:
|
||||
for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
@@ -25,6 +37,13 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
data, config = load_data(data_path, files='raw')
|
||||
song, rate = data['raw'], config['rate']
|
||||
|
||||
# Reduce to kernel subset:
|
||||
kern_inds = find_kern_specs(config['k_specs'], kernels, types, sigmas)
|
||||
config['kernels'] = config['kernels'][:, kern_inds]
|
||||
config['k_specs'] = config['k_specs'][kern_inds, :]
|
||||
config['k_props'] = [config['k_props'][i] for i in kern_inds]
|
||||
config['feat_thresh'] = config['feat_thresh'][kern_inds]
|
||||
|
||||
# Get song segment to be analyzed:
|
||||
time = np.arange(song.shape[0]) / rate
|
||||
start, end = data['songs_0'].ravel()
|
||||
@@ -42,14 +61,14 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
shape_low = (song.shape[0], example_scales.size)
|
||||
shape_high = (song.shape[0], config['k_specs'].shape[0], example_scales.size)
|
||||
snippets = dict(
|
||||
raw=np.zeros(shape_low, dtype=float),
|
||||
filt=np.zeros(shape_low, dtype=float),
|
||||
env=np.zeros(shape_low, dtype=float),
|
||||
log=np.zeros(shape_low, dtype=float),
|
||||
inv=np.zeros(shape_low, dtype=float),
|
||||
conv=np.zeros(shape_high, dtype=float),
|
||||
bi=np.zeros(shape_high, dtype=float),
|
||||
feat=np.zeros(shape_high, dtype=float)
|
||||
snip_raw=np.zeros(shape_low, dtype=float),
|
||||
snip_filt=np.zeros(shape_low, dtype=float),
|
||||
snip_env=np.zeros(shape_low, dtype=float),
|
||||
snip_log=np.zeros(shape_low, dtype=float),
|
||||
snip_inv=np.zeros(shape_low, dtype=float),
|
||||
snip_conv=np.zeros(shape_high, dtype=float),
|
||||
snip_bi=np.zeros(shape_high, dtype=float),
|
||||
snip_feat=np.zeros(shape_high, dtype=float)
|
||||
)
|
||||
|
||||
# Prepare measure storage:
|
||||
@@ -82,13 +101,31 @@ for data_path, name in zip(data_paths, crop_paths(data_paths)):
|
||||
# Log snippet data:
|
||||
if scale in example_scales:
|
||||
scale_ind = np.nonzero(example_scales == scale)[0][0]
|
||||
snippets[stage][:, ..., scale_ind] = signals[stage]
|
||||
snippets[f'snip_{stage}'][:, ..., scale_ind] = signals[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)
|
||||
|
||||
# thresh_y = np.percentile(measures['measure_feat'], 99, axis=0)
|
||||
# kern_types = np.unique()
|
||||
# thresh_x = np.zeros(thresh_y.shape, dtype=float)
|
||||
# for i, thresh in enumerate(thresh_y):
|
||||
# if thresh < 0.1:
|
||||
# thresh_x[i] = scales[-1]
|
||||
# continue
|
||||
# mask = (measures['measure_feat'][:, i] < thresh)
|
||||
# thresh_x[i] = scales[np.nonzero(mask)[0][-1]]
|
||||
# inds = np.argsort(thresh_x)
|
||||
# print(config['k_specs'][inds, :])
|
||||
|
||||
# fig, axes = plt.subplots(1, 2)
|
||||
# axes[0].plot(snippets['snip_feat'][:, inds, -1])
|
||||
# axes[1].plot(scales, measures['measure_feat'][:, inds])
|
||||
# plt.show()
|
||||
# embed()
|
||||
|
||||
# Save analysis results:
|
||||
if save_path is not None:
|
||||
|
||||
Reference in New Issue
Block a user