def test_compare_outputs(): """Compare the python output with the matlab output. They should be identical.""" channel_mat = 'matlab/codes/channel/channel.mat' mat_dict = scipy.io.loadmat(channel_mat) UstarX1 = mat_dict['UstarX1'] S = mat_dict['S'] V = mat_dict['V'] # Sparsity-promoting parameter gamma # Lower and upper bounds relevant for this flow type gamma_grd = 20 gammaval = np.logspace(np.log10(0.15), np.log10(160), gamma_grd) Fdmd, Edmd, Ydmd, xdmd, py_answer = sparse_dmd.run_dmdsp(UstarX1, S, V, gammaval) # convert class attributes to dict py_answer = py_answer.__dict__ ## matlab output created by running matlab: ## [Fdmd, Edmd, Ydmd, xdmd, answer] = run_dmdsp; ## output = struct('Fdmd', Fdmd, 'Edmd', Edmd, 'Ydmd', Ydmd, 'xdmd', xdmd); ## save('tests/answer.mat', '-struct', 'answer') ## save('tests/output.mat', '-struct', 'output') ## using channel=1 and 20 gridpoints for gamma # using two different .mat because scipy doesn't seem to like # nested structs mat_answer = scipy.io.loadmat('tests/answer.mat') mat_output = scipy.io.loadmat('tests/output.mat') for k in py_answer: nt.assert_array_almost_equal(py_answer[k].squeeze(), mat_answer[k].squeeze(), decimal=5) py_output = {'Fdmd': Fdmd, 'Edmd': Edmd, 'Ydmd': Ydmd, 'xdmd': xdmd} for k in py_output: nt.assert_array_almost_equal(py_output[k].squeeze(), mat_output[k].squeeze(), decimal=5)
def test_compare_outputs(): """Compare the python output with the matlab output. They should be identical.""" channel_mat = 'matlab/codes/channel/channel.mat' mat_dict = scipy.io.loadmat(channel_mat) UstarX1 = mat_dict['UstarX1'] S = mat_dict['S'] V = mat_dict['V'] # Sparsity-promoting parameter gamma # Lower and upper bounds relevant for this flow type gamma_grd = 20 gammaval = np.logspace(np.log10(0.15), np.log10(160), gamma_grd) Fdmd, Edmd, Ydmd, xdmd, py_answer = sparse_dmd.run_dmdsp( UstarX1, S, V, gammaval) # convert class attributes to dict py_answer = py_answer.__dict__ ## matlab output created by running matlab: ## [Fdmd, Edmd, Ydmd, xdmd, answer] = run_dmdsp; ## output = struct('Fdmd', Fdmd, 'Edmd', Edmd, 'Ydmd', Ydmd, 'xdmd', xdmd); ## save('tests/answer.mat', '-struct', 'answer') ## save('tests/output.mat', '-struct', 'output') ## using channel=1 and 20 gridpoints for gamma # using two different .mat because scipy doesn't seem to like # nested structs mat_answer = scipy.io.loadmat('tests/answer.mat') mat_output = scipy.io.loadmat('tests/output.mat') for k in py_answer: nt.assert_array_almost_equal(py_answer[k].squeeze(), mat_answer[k].squeeze(), decimal=5) py_output = {'Fdmd': Fdmd, 'Edmd': Edmd, 'Ydmd': Ydmd, 'xdmd': xdmd} for k in py_output: nt.assert_array_almost_equal(py_output[k].squeeze(), mat_output[k].squeeze(), decimal=5)
def create_answer(n=200): answer = sparse_dmd.run_dmdsp(gamma_grd=n) scipy.io.savemat('tests/answer.mat', answer)
import time import numpy as np import scipy.io from sparse_dmd import run_dmdsp channel_mat = 'matlab/codes/channel/channel.mat' mat_dict = scipy.io.loadmat(channel_mat) UstarX1 = mat_dict['UstarX1'] S = mat_dict['S'] V = mat_dict['V'] # Sparsity-promoting parameter gamma # Lower and upper bounds relevant for this flow type gamma_grd = 200 gammaval = np.logspace(np.log10(0.15), np.log10(160), gamma_grd) tic = time.time() Fdmd, Edmd, Ydmd, xdmd, py_answer = run_dmdsp(UstarX1, S, V, gammaval) toc = time.time() print "time elapsed: ", toc - tic