comparison 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
comparison
equal deleted inserted replaced
273:c26222c51fb7 274:3640d25b65ab
27 """ 27 """
28 28
29 import aimc 29 import aimc
30 import matplotlib 30 import matplotlib
31 import pylab 31 import pylab
32 import scipy 32 from scipy import io
33 33
34 def main(): 34 def main():
35 data_file = "src/Modules/Features/testdata/aa153.0p108.1s100.0t+000itd.mat" 35 data_file = "src/Modules/Features/testdata/aa153.0p108.1s100.0t+000itd.mat"
36 data = scipy.io.loadmat(data_file) 36 data = io.loadmat(data_file)
37
38 # The margin of error allowed between the returned values from AIM-C and
39 # the stored MATLAB values.
40 epsilon = 0.000001;
37 41
38 given_profiles = data["Templates"] 42 given_profiles = data["Templates"]
39 matlab_features = data["feature"] 43 matlab_features = data["feature"]
40 44
45 (profile_count, channel_count) = given_profiles.shape
41 46
47 profile_sig = aimc.SignalBank()
48 profile_sig.Initialize(channel_count, 1, 44100)
49 parameters = aimc.Parameters()
50 mod_gauss = aimc.ModuleGaussians(parameters)
51 mod_gauss.Initialize(profile_sig)
42 52
53 correct_count = 0;
54 incorrect_count = 0;
55 for p in range(0, profile_count):
56 profile = given_profiles[p]
57 features = matlab_features[p]
58 for i in range(0, channel_count):
59 profile_sig.set_sample(i, 0, profile[i])
60 mod_gauss.Process(profile_sig)
61 out_sig = mod_gauss.GetOutputBank()
62 error = False;
63 for j in range(0, out_sig.channel_count()):
64 if (abs(out_sig.sample(j, 0) - features[j]) > epsilon):
65 error = True;
66 incorrect_count += 1;
67 else:
68 correct_count += 1;
69 if error:
70 print("Mismatch at profile %d" % (p))
71 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)))
72 print("MATLAB values: %f %f %f %f" % (features[0], features[1], features[2], features[3]))
73 print("")
74 percent_correct = 100 * correct_count / (correct_count + incorrect_count)
75 print("Total correct: %f percent" % (percent_correct))
76 if percent_correct == 100:
77 print("=== TEST PASSED ===")
78 else:
79 print("=== TEST FAILED! ===")
80
43 pass 81 pass
44 82
45 83
46 if __name__ == '__main__': 84 if __name__ == '__main__':
47 main() 85 main()