diff trunk/src/Modules/Features/ModuleGaussians_test.py @ 274:3640d25b65ab

- Fixed the gaussian fitting to use doubles internally (like MATLAB) - Fixed an irritating bug that was causing the Gaussian fitting to be incorrectly initialized, leading to small differences between the AIM-C and MATLAB code - Finalised the Gaussian fitting test
author tomwalters
date Tue, 16 Feb 2010 13:23:23 +0000
parents c26222c51fb7
children ce2bab04f155
line wrap: on
line diff
--- a/trunk/src/Modules/Features/ModuleGaussians_test.py	Mon Feb 15 20:37:26 2010 +0000
+++ b/trunk/src/Modules/Features/ModuleGaussians_test.py	Tue Feb 16 13:23:23 2010 +0000
@@ -29,17 +29,55 @@
 import aimc
 import matplotlib
 import pylab
-import scipy
+from scipy import io
 
 def main():
   data_file = "src/Modules/Features/testdata/aa153.0p108.1s100.0t+000itd.mat"
-  data = scipy.io.loadmat(data_file)
+  data = io.loadmat(data_file)
+  
+  # The margin of error allowed between the returned values from AIM-C and
+  # the stored MATLAB values.
+  epsilon = 0.000001;
   
   given_profiles = data["Templates"]
   matlab_features = data["feature"]
   
+  (profile_count, channel_count) = given_profiles.shape
   
+  profile_sig = aimc.SignalBank()
+  profile_sig.Initialize(channel_count, 1, 44100)
+  parameters = aimc.Parameters()
+  mod_gauss = aimc.ModuleGaussians(parameters)
+  mod_gauss.Initialize(profile_sig)
   
+  correct_count = 0;
+  incorrect_count  = 0;
+  for p in range(0, profile_count):
+    profile = given_profiles[p]
+    features = matlab_features[p]
+    for i in range(0, channel_count):
+      profile_sig.set_sample(i, 0, profile[i])
+    mod_gauss.Process(profile_sig)
+    out_sig = mod_gauss.GetOutputBank()
+    error = False;
+    for j in range(0, out_sig.channel_count()):
+      if (abs(out_sig.sample(j, 0) - features[j]) > epsilon):
+        error = True;
+        incorrect_count += 1;
+      else:
+        correct_count += 1;
+    if error:
+      print("Mismatch at profile %d" % (p))
+      print("AIM-C values: %f %f %f %f" % (out_sig.sample(0, 0), out_sig.sample(1, 0), out_sig.sample(2, 0), out_sig.sample(3, 0)))
+      print("MATLAB values: %f %f %f %f" % (features[0], features[1], features[2], features[3]))
+      print("")
+    percent_correct = 100 * correct_count / (correct_count + incorrect_count)
+  print("Total correct: %f percent" % (percent_correct))
+  if percent_correct == 100:
+    print("=== TEST PASSED ===")
+  else:
+    print("=== TEST FAILED! ===")
+
   pass