Skip to content

Commit

Permalink
fixed bug in feature pooling step
Browse files Browse the repository at this point in the history
  • Loading branch information
mkholghi committed Jul 12, 2018
1 parent db4d8d7 commit 4757dc9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
22 changes: 12 additions & 10 deletions src/AnalysisPrograms/MahnooshSandpit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ public void Execute(Arguments arguments)

// Black Rail call is between 1000 Hz and 3000 Hz, which is mapped to Mel value [1000, 1876]
// Hence, we only work with freq bins between [40, 76]
int minFreqBin = 1; //35; //40; //
int maxFreqBin = finalBinCount; //85; //80; //76;
int minFreqBin = 1; //24; //35; //40; //
int maxFreqBin = finalBinCount; //95; //85; //80; //76;
int numFreqBand = 1;
int patchWidth = (maxFreqBin - minFreqBin + 1) / numFreqBand; //finalBinCount / numFreqBand;
int patchHeight = 1; // 2; // 4; // 16; // 6; // Frame size
int numRandomPatches = 4; //8; //80; // 20; //2; //10; //100; // 40; // 30; // 500; //
int patchHeight = 1; // 2; // 4; // 16; // 6; // Frame size
int numRandomPatches = 4; //40; //8; //16; // 80; // 2; //10; //100; // 30; // 500; //20; //
// int fileCount = Directory.GetFiles(folderPath, "*.wav").Length;

// Define variable number of "randomPatch" lists based on "numFreqBand"
Expand Down Expand Up @@ -154,7 +154,7 @@ public void Execute(Arguments arguments)
}

// convert list of random patches matrices to one matrix
int numberOfClusters = 256; //500; //10; //16; //128; //20; // 500; // 128; // 64; // 32; // 50;
int numberOfClusters = 256; //8; //128; //500; //10; //16; //20; // 500; // 128; // 64; // 32; // 50;
List<double[][]> allBandsCentroids = new List<double[][]>();
List<KMeansClusterCollection> allClusteringOutput = new List<KMeansClusterCollection>();

Expand Down Expand Up @@ -248,7 +248,7 @@ public void Execute(Arguments arguments)
Dictionary<string, List<double[,]>> allFilesMeanFeatureVectors = new Dictionary<string, List<double[,]>>();
Dictionary<string, List<double[,]>> allFilesMaxFeatureVectors = new Dictionary<string, List<double[,]>>();
Dictionary<string, List<double[,]>> allFilesStdFeatureVectors = new Dictionary<string, List<double[,]>>();
Dictionary<string, List<double[,]>> allFilesSknewnessFeatureVectors = new Dictionary<string, List<double[,]>>();
Dictionary<string, List<double[,]>> allFilesSkewnessFeatureVectors = new Dictionary<string, List<double[,]>>();

foreach (string filePath in Directory.GetFiles(trainSetPath, "*.wav")) // testSetPath
{
Expand Down Expand Up @@ -373,9 +373,9 @@ public void Execute(Arguments arguments)
List<double[]> skewnessFeatureVectors = new List<double[]>();

int c = 0;
while (c + numFrames < freqBandFeature.GetLength(0))
while (c + numFrames <= freqBandFeature.GetLength(0))
{
// First, make a list of patches that would be equal to the needed resolution (1 scond, 60 second, etc.)
// First, make a list of patches that would be equal to the needed resolution (1 second, 60 second, etc.)
List<double[]> sequencesOfFramesList = new List<double[]>();
for (int i = c; i < c + numFrames; i++)
{
Expand Down Expand Up @@ -417,6 +417,8 @@ public void Execute(Arguments arguments)

// when (freqBandFeature.GetLength(0) % numFrames) != 0, it means at the end of the target recording (or the whole),
// there are a number of frames (< numFrames) left unprocessed.
// this would be problematic when an the resulotion to genearte the feature vector is 1 min,
// but the the length of the target recording is a bit less than one min.
if (freqBandFeature.GetLength(0) % numFrames != 0 && freqBandFeature.GetLength(0) % numFrames > 1)
{
// First, make a list of patches that would be less than the required resolution
Expand Down Expand Up @@ -476,7 +478,7 @@ public void Execute(Arguments arguments)
allFilesMeanFeatureVectors.Add(fileInfo.Name, allMeanFeatureVectors);
allFilesMaxFeatureVectors.Add(fileInfo.Name, allMaxFeatureVectors);
allFilesStdFeatureVectors.Add(fileInfo.Name, allStdFeatureVectors);
allFilesSknewnessFeatureVectors.Add(fileInfo.Name, allSkewnessFeatureVectors);
allFilesSkewnessFeatureVectors.Add(fileInfo.Name, allSkewnessFeatureVectors);

// +++++++++++++++++++++++++++++++++++Temporal Summarization

Expand Down Expand Up @@ -573,7 +575,7 @@ public void Execute(Arguments arguments)
var meanFeatures = allFilesMeanFeatureVectors.Values.ToArray();
var maxFeatures = allFilesMaxFeatureVectors.Values.ToArray();
var stdFeatures = allFilesStdFeatureVectors.Values.ToArray();
var skewnessFeatures = allFilesSknewnessFeatureVectors.Values.ToArray();
var skewnessFeatures = allFilesSkewnessFeatureVectors.Values.ToArray();

// The number of elements in the list shows the number of freq bands
// the size of each element in the list shows the number of files processed to generate feature for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public void TestKmeansClustering()
clusterImage.Save(outputClusteringImage);
}

//+++++++++++++++++++++++++++++++++++++++++++++++++++++Processing and generating features for the target spectrogram
//+++++++++++++++++++++++++++++++++++++++++++Reconstructing a target spectrogram from sequential patches and the cluster centroids
var recording2Path = PathHelper.ResolveAsset("Recordings", "BAC2_20071008-085040.wav");
var recording2 = new AudioRecording(recording2Path);
var sonogram2 = new SpectrogramStandard(sonoConfig, recording2.WavReader);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public void TestPcaWhitening()
var whitenedSpectrogram = PcaWhitening.Whitening(sequentialPatchMatrix);

// reconstructing the spectrogram from sequential patches and the projection matrix obtained from random patches
var projectionMatrix = whitenedSpectrogram.ProjectionMatrix;//whitenedSpectrogram.projectionMatrix;
var projectionMatrix = whitenedSpectrogram.ProjectionMatrix;
var eigenVectors = whitenedSpectrogram.EigenVectors;
var numComponents = whitenedSpectrogram.Components;
double[,] reconstructedSpec = PcaWhitening.ReconstructSpectrogram(projectionMatrix, sequentialPatchMatrix, eigenVectors, numComponents);
Expand Down

0 comments on commit 4757dc9

Please sign in to comment.