tomwalters@273
|
1 #!/usr/bin/env python
|
tomwalters@273
|
2 # encoding: utf-8
|
tomwalters@273
|
3 #
|
tomwalters@273
|
4 # AIM-C: A C++ implementation of the Auditory Image Model
|
tomwalters@273
|
5 # http://www.acousticscale.org/AIMC
|
tomwalters@273
|
6 #
|
tomwalters@318
|
7 # Licensed under the Apache License, Version 2.0 (the "License");
|
tomwalters@318
|
8 # you may not use this file except in compliance with the License.
|
tomwalters@318
|
9 # You may obtain a copy of the License at
|
tomwalters@273
|
10 #
|
tomwalters@318
|
11 # http://www.apache.org/licenses/LICENSE-2.0
|
tomwalters@273
|
12 #
|
tomwalters@318
|
13 # Unless required by applicable law or agreed to in writing, software
|
tomwalters@318
|
14 # distributed under the License is distributed on an "AS IS" BASIS,
|
tomwalters@318
|
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
tomwalters@318
|
16 # See the License for the specific language governing permissions and
|
tomwalters@318
|
17 # limitations under the License.
|
tomwalters@273
|
18 """
|
tomwalters@273
|
19 ModuleGaussians_test.py
|
tomwalters@273
|
20
|
tomwalters@273
|
21 Created by Thomas Walters on 2010-02-15.
|
tomwalters@273
|
22 Copyright 2010 Thomas Walters <tom@acousticscale.org>
|
tomwalters@273
|
23 Test for the Gaussians module. Runs a number of pre-computed SAI profiles
|
tomwalters@275
|
24 through the module, and tests them against the saved output from the
|
tomwalters@273
|
25 MATLAB rubber_GMM code.
|
tomwalters@273
|
26 """
|
tomwalters@273
|
27
|
tomwalters@273
|
28 import aimc
|
tomwalters@274
|
29 from scipy import io
|
tomwalters@273
|
30
|
tomwalters@273
|
31 def main():
|
tomwalters@273
|
32 data_file = "src/Modules/Features/testdata/aa153.0p108.1s100.0t+000itd.mat"
|
tomwalters@274
|
33 data = io.loadmat(data_file)
|
tomwalters@274
|
34
|
tomwalters@274
|
35 # The margin of error allowed between the returned values from AIM-C and
|
tomwalters@274
|
36 # the stored MATLAB values.
|
tomwalters@283
|
37 epsilon = 0.00001;
|
tomwalters@273
|
38
|
tomwalters@273
|
39 given_profiles = data["Templates"]
|
tomwalters@273
|
40 matlab_features = data["feature"]
|
tomwalters@273
|
41
|
tomwalters@274
|
42 (profile_count, channel_count) = given_profiles.shape
|
tomwalters@273
|
43
|
tomwalters@274
|
44 profile_sig = aimc.SignalBank()
|
tomwalters@274
|
45 profile_sig.Initialize(channel_count, 1, 44100)
|
tomwalters@274
|
46 parameters = aimc.Parameters()
|
tomwalters@274
|
47 mod_gauss = aimc.ModuleGaussians(parameters)
|
tomwalters@274
|
48 mod_gauss.Initialize(profile_sig)
|
tomwalters@273
|
49
|
tomwalters@274
|
50 correct_count = 0;
|
tomwalters@274
|
51 incorrect_count = 0;
|
tomwalters@274
|
52 for p in range(0, profile_count):
|
tomwalters@274
|
53 profile = given_profiles[p]
|
tomwalters@274
|
54 features = matlab_features[p]
|
tomwalters@274
|
55 for i in range(0, channel_count):
|
tomwalters@274
|
56 profile_sig.set_sample(i, 0, profile[i])
|
tomwalters@274
|
57 mod_gauss.Process(profile_sig)
|
tomwalters@274
|
58 out_sig = mod_gauss.GetOutputBank()
|
tomwalters@274
|
59 error = False;
|
tomwalters@274
|
60 for j in range(0, out_sig.channel_count()):
|
tomwalters@274
|
61 if (abs(out_sig.sample(j, 0) - features[j]) > epsilon):
|
tomwalters@274
|
62 error = True;
|
tomwalters@274
|
63 incorrect_count += 1;
|
tomwalters@274
|
64 else:
|
tomwalters@274
|
65 correct_count += 1;
|
tomwalters@274
|
66 if error:
|
tomwalters@274
|
67 print("Mismatch at profile %d" % (p))
|
tomwalters@274
|
68 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)))
|
tomwalters@274
|
69 print("MATLAB values: %f %f %f %f" % (features[0], features[1], features[2], features[3]))
|
tomwalters@274
|
70 print("")
|
tomwalters@274
|
71 percent_correct = 100 * correct_count / (correct_count + incorrect_count)
|
tomwalters@274
|
72 print("Total correct: %f percent" % (percent_correct))
|
tomwalters@274
|
73 if percent_correct == 100:
|
tomwalters@274
|
74 print("=== TEST PASSED ===")
|
tomwalters@274
|
75 else:
|
tomwalters@274
|
76 print("=== TEST FAILED! ===")
|
tomwalters@274
|
77
|
tomwalters@273
|
78 pass
|
tomwalters@273
|
79
|
tomwalters@273
|
80
|
tomwalters@273
|
81 if __name__ == '__main__':
|
tomwalters@273
|
82 main()
|