annotate src/Modules/Features/ModuleGaussians_test.py @ 13:88fe02836a6b

-Updated the SWIG wrapper to include all the modules. Now employing a lazier strategy for the SWIG interface file.
author tomwalters
date Fri, 19 Feb 2010 14:17:42 +0000
parents bd370910aa05
children c5f5e9569863
rev   line source
tomwalters@1 1 #!/usr/bin/env python
tomwalters@1 2 # encoding: utf-8
tomwalters@1 3 #
tomwalters@1 4 # AIM-C: A C++ implementation of the Auditory Image Model
tomwalters@1 5 # http://www.acousticscale.org/AIMC
tomwalters@1 6 #
tomwalters@1 7 # This program is free software: you can redistribute it and/or modify
tomwalters@1 8 # it under the terms of the GNU General Public License as published by
tomwalters@1 9 # the Free Software Foundation, either version 3 of the License, or
tomwalters@1 10 # (at your option) any later version.
tomwalters@1 11 #
tomwalters@1 12 # This program is distributed in the hope that it will be useful,
tomwalters@1 13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
tomwalters@1 14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
tomwalters@1 15 # GNU General Public License for more details.
tomwalters@1 16 #
tomwalters@1 17 # You should have received a copy of the GNU General Public License
tomwalters@1 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
tomwalters@1 19 """
tomwalters@1 20 ModuleGaussians_test.py
tomwalters@1 21
tomwalters@1 22 Created by Thomas Walters on 2010-02-15.
tomwalters@1 23 Copyright 2010 Thomas Walters <tom@acousticscale.org>
tomwalters@1 24 Test for the Gaussians module. Runs a number of pre-computed SAI profiles
tomwalters@3 25 through the module, and tests them against the saved output from the
tomwalters@1 26 MATLAB rubber_GMM code.
tomwalters@1 27 """
tomwalters@1 28
tomwalters@1 29 import aimc
tomwalters@2 30 from scipy import io
tomwalters@1 31
tomwalters@1 32 def main():
tomwalters@1 33 data_file = "src/Modules/Features/testdata/aa153.0p108.1s100.0t+000itd.mat"
tomwalters@2 34 data = io.loadmat(data_file)
tomwalters@2 35
tomwalters@2 36 # The margin of error allowed between the returned values from AIM-C and
tomwalters@2 37 # the stored MATLAB values.
tomwalters@11 38 epsilon = 0.00001;
tomwalters@1 39
tomwalters@1 40 given_profiles = data["Templates"]
tomwalters@1 41 matlab_features = data["feature"]
tomwalters@1 42
tomwalters@2 43 (profile_count, channel_count) = given_profiles.shape
tomwalters@1 44
tomwalters@2 45 profile_sig = aimc.SignalBank()
tomwalters@2 46 profile_sig.Initialize(channel_count, 1, 44100)
tomwalters@2 47 parameters = aimc.Parameters()
tomwalters@2 48 mod_gauss = aimc.ModuleGaussians(parameters)
tomwalters@2 49 mod_gauss.Initialize(profile_sig)
tomwalters@1 50
tomwalters@2 51 correct_count = 0;
tomwalters@2 52 incorrect_count = 0;
tomwalters@2 53 for p in range(0, profile_count):
tomwalters@2 54 profile = given_profiles[p]
tomwalters@2 55 features = matlab_features[p]
tomwalters@2 56 for i in range(0, channel_count):
tomwalters@2 57 profile_sig.set_sample(i, 0, profile[i])
tomwalters@2 58 mod_gauss.Process(profile_sig)
tomwalters@2 59 out_sig = mod_gauss.GetOutputBank()
tomwalters@2 60 error = False;
tomwalters@2 61 for j in range(0, out_sig.channel_count()):
tomwalters@2 62 if (abs(out_sig.sample(j, 0) - features[j]) > epsilon):
tomwalters@2 63 error = True;
tomwalters@2 64 incorrect_count += 1;
tomwalters@2 65 else:
tomwalters@2 66 correct_count += 1;
tomwalters@2 67 if error:
tomwalters@2 68 print("Mismatch at profile %d" % (p))
tomwalters@2 69 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@2 70 print("MATLAB values: %f %f %f %f" % (features[0], features[1], features[2], features[3]))
tomwalters@2 71 print("")
tomwalters@2 72 percent_correct = 100 * correct_count / (correct_count + incorrect_count)
tomwalters@2 73 print("Total correct: %f percent" % (percent_correct))
tomwalters@2 74 if percent_correct == 100:
tomwalters@2 75 print("=== TEST PASSED ===")
tomwalters@2 76 else:
tomwalters@2 77 print("=== TEST FAILED! ===")
tomwalters@2 78
tomwalters@1 79 pass
tomwalters@1 80
tomwalters@1 81
tomwalters@1 82 if __name__ == '__main__':
tomwalters@1 83 main()