def test_ALPHA_from_matrices(param, expected): ''' Function to test instantiating Alpha class from matrices param, expected : from config.yaml file ''' for key, value in param[0].items(): globals()[key] = value my_ALPHA = hs.Alpha() my_A = hs.convert_matrix_to_cart(A) my_B = hs.convert_matrix_to_cart(B) my_U = hs.convert_matrix_to_cart(U) print(A, B, U, keep_trial) my_ALPHA.add(A=my_A, B=my_B, U=my_U, keep_trial=keep_trial) expected = hs.convert_matrix_to_cart(expected) np.testing.assert_allclose(my_ALPHA.value, expected, rtol=0.05) # allowance 5% error
def test_Min_max(param, expected): ''' Testing instantiate Min_Max model and test it against test cases ''' my_ALPHA = hs.Alpha() A = hs.convert_matrix_to_cart(param[0]['A']) weight_const = param[0]['weight_const'] A0 = [0] # It is acceptable to enter either direct_matrix or A,B,U matrices try: direct_matrix = hs.convert_matrix_to_cart(param[0]['ALPHA']) my_ALPHA.add(direct_matrix=direct_matrix) except KeyError: B = hs.convert_matrix_to_cart(param[0]['B']) U = hs.convert_matrix_to_cart(param[0]['U']) my_ALPHA.add(A=A, B=B, U=U) try: A0 = hs.convert_matrix_to_cart(param[0]['A0']) except KeyError: pass expected_W = hs.convert_matrix_to_cart(expected) my_model = hs.Min_max(A, my_ALPHA, weight_const=weight_const,name='Min_max') # Setting the model almost with no constraints W = my_model.solve() print((expected)) print('Residual Vibration rmse calculated = ', my_model.rmse()) print('Residual Vibration rmse from test_case = ', hs.rmse(hs.residual_vibration(my_ALPHA.value, expected_W, A))) print('expected_residual_vibration', hs.convert_matrix_to_math(my_model.expected_residual_vibration())) print('Correction weights', hs.convert_cart_math(W)) # Constraint Minmax algorithm was slightly inefficient in CVXPY # The rmse was marginally more than the author solution np.testing.assert_allclose(W, expected_W, rtol=0.09) # allowance 9% error
def test_WLS(param, expected): ''' Testing instantiate LMI model and test it against test cases ''' my_ALPHA = hs.Alpha() A = hs.convert_matrix_to_cart(param[0]['A']) A0 = [0] # It is acceptable to enter either direct_matrix or A,B,U matrices try: direct_matrix = hs.convert_matrix_to_cart(param[0]['ALPHA']) my_ALPHA.add(direct_matrix=direct_matrix) except KeyError: B = hs.convert_matrix_to_cart(param[0]['B']) U = hs.convert_matrix_to_cart(param[0]['U']) my_ALPHA.add(A=A, B=B, U=U) try: A0 = hs.convert_matrix_to_cart(param[0]['A0']) except KeyError: pass expected_W = hs.convert_matrix_to_cart(expected) my_model = hs.LeastSquares(A - A0, my_ALPHA, name='simple_least_square') W = my_model.solve(solver='WLS') print('Residual Vibration rmse calculated = ', my_model.rmse()) print('Residual Vibration rmse from test_case = ', hs.rmse(hs.residual_vibration(my_ALPHA.value, expected_W, A))) print('expected_residual_vibration', hs.convert_matrix_to_math(my_model.expected_residual_vibration())) np.testing.assert_allclose(W, expected_W, rtol=0.05) # allowance 5% error
def test_ALPHA_direct(param, expected): ''' Pytest function to test instantiate Alpha from direct_matrix Inputs: param, expected : from config.yaml file ''' # Instantiate Alpha class my_ALPHA = hs.Alpha() # Add direct matrix to the instance my_ALPHA.add(direct_matrix=hs.convert_matrix_to_cart(param)) expected = list(list(complex(x) for x in item) for item in expected) np.testing.assert_allclose(my_ALPHA.value, expected, rtol=0.05) # allowance 5% error
def test_LMI(param, expected): ''' Testing insantiate Least square model and test it against test cases ''' my_ALPHA = hs.Alpha() A = hs.convert_matrix_to_cart(param[0]['A']) weight_const = param[0]['weight_const'] A0 = [0] # It is acceptable to enter either direct_matrix or A,B,U matrices try: direct_matrix = hs.convert_matrix_to_cart(param[0]['ALPHA']) my_ALPHA.add(direct_matrix=direct_matrix) except KeyError: B = hs.convert_matrix_to_cart(param[0]['B']) U = hs.convert_matrix_to_cart(param[0]['U']) my_ALPHA.add(A=A, B=B, U=U) try: A0 = hs.convert_matrix_to_cart(param[0]['A0']) except KeyError: pass expected_W = hs.convert_matrix_to_cart(expected) my_model = hs.LMI(A, my_ALPHA, weight_const=weight_const, V_max=76, critical_planes={1, 9}, name='LMI') W = my_model.solve() print('Residual Vibration rmse calculated = ', my_model.rmse()) print('Residual Vibration rmse from test_case = ', hs.rmse(hs.residual_vibration(my_ALPHA.value, expected_W, A))) print('expected_residual_vibration', hs.convert_matrix_to_math(my_model.expected_residual_vibration())) print('Correction weights', hs.convert_cart_math(W)) np.testing.assert_allclose(W, expected_W, rtol=0.05) # allowance 5% error