Fixed spectral flux single frame problem. Changed imputer axis to correct one.
This commit is contained in:
@@ -72,7 +72,7 @@ class SpectralFluxAnalysis(Analysis):
|
||||
# magnitude.
|
||||
rolled_mags = np.roll(magnitudes, 1, axis=0)[1:]
|
||||
sum_of_squares = np.sum((magnitudes[1:]-rolled_mags)**2., axis=1)
|
||||
spectral_flux = np.sqrt(sum_of_squares) / (np.size(fft, axis=1)/2)
|
||||
spectral_flux = np.sqrt(sum_of_squares) / (np.size(fft, axis=1))
|
||||
|
||||
return spectral_flux
|
||||
|
||||
@@ -83,6 +83,8 @@ class SpectralFluxAnalysis(Analysis):
|
||||
|
||||
# Get number of frames for time and frequency
|
||||
timebins = spcflux_frames.shape[0]
|
||||
if not timebins:
|
||||
return np.array([])
|
||||
# Create array ranging from 0 to number of time frames
|
||||
scale = np.arange(timebins+1)
|
||||
# divide the number of samples by the total number of frames, then
|
||||
|
||||
@@ -48,8 +48,8 @@ matcher_weightings = {
|
||||
"centroid": 1.,
|
||||
"kurtosis": 1.,
|
||||
"skewness": 1.,
|
||||
"variance": 3.,
|
||||
"harm_ratio": 3.
|
||||
"variance": 1.,
|
||||
"harm_ratio": 1.
|
||||
}
|
||||
|
||||
# Specifies the method for averaging analysis frames to create a single value
|
||||
|
||||
@@ -426,9 +426,10 @@ class Matcher:
|
||||
all_target_analyses[i] = target_data
|
||||
|
||||
|
||||
imp = Imputer(axis=1)
|
||||
nan_columns = np.all(np.isnan(all_target_analyses), axis=1)
|
||||
all_target_analyses[nan_columns, :] = 0.
|
||||
pdb.set_trace()
|
||||
imp = Imputer(axis=0)
|
||||
nan_columns = np.all(np.isnan(all_target_analyses), axis=0)
|
||||
all_target_analyses[:, nan_columns] = 0.
|
||||
# Impute values for Nans
|
||||
all_target_analyses = imp.fit_transform(all_target_analyses)
|
||||
|
||||
@@ -450,8 +451,8 @@ class Matcher:
|
||||
|
||||
|
||||
# Impute values for Nans
|
||||
nan_columns = np.all(np.isnan(all_source_analyses), axis=1)
|
||||
all_source_analyses[nan_columns, :] = 0.
|
||||
nan_columns = np.all(np.isnan(all_source_analyses), axis=0)
|
||||
all_source_analyses[:, nan_columns] = 0.
|
||||
all_source_analyses = imp.fit_transform(all_source_analyses)
|
||||
|
||||
source_tree = spatial.cKDTree(all_source_analyses.T, leafsize=100)
|
||||
@@ -725,8 +726,11 @@ class Matcher:
|
||||
# Find indexes within the range of each source sample index.
|
||||
x = np.logical_and(
|
||||
np.vstack(x)>=source_sample_indexes[:,0],
|
||||
np.vstack(x)<source_sample_indexes[:,1]
|
||||
np.vstack(x)<=source_sample_indexes[:,1]
|
||||
)
|
||||
|
||||
if not np.all(np.any(x, axis=1)):
|
||||
raise ValueError("Not all match indexes have a corresponding sample index. This shouldn't happen...")
|
||||
x = x.reshape(mi_shape[0], mi_shape[1], x.shape[1])
|
||||
x = np.argmax(x, axis=2)
|
||||
|
||||
|
||||
@@ -600,9 +600,9 @@ class SpectralFluxAnalysisTests(globalTests):
|
||||
|
||||
def test_GenerateSpectralFlux(self):
|
||||
x = np.vstack((self.equal_mag, self.peak))
|
||||
output = analysis.SpectralFluxAnalysis.create_spcflux_analysis(x, 512)
|
||||
output = analysis.SpectralFluxAnalysis.create_spcflux_analysis(x)
|
||||
x = np.vstack((self.peak, self.peak))
|
||||
output1 = analysis.SpectralFluxAnalysis.create_spcflux_analysis(x, 512)
|
||||
output1 = analysis.SpectralFluxAnalysis.create_spcflux_analysis(x)
|
||||
self.assertTrue(output[0] > output1[0])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user