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_big_matrix_LSQ(test_big_alpha, test_big_A, test_model_LSQ): ''' Testing the perfromance of model ''' start = time.time() error = hs.residual_vibration(test_big_alpha.value, test_model_LSQ, test_big_A) end = time.time() print(error.shape) print('Time elapsed = ', end - start) np.testing.assert_allclose(error, 0, atol=1e-5)
def test_performance(n): alpha = hs.Alpha() real = np.random.uniform(0, 10, [n, n]) imag = np.random.uniform(0, 10, [n, n]) alpha.add(real + imag * 1j) real = np.random.uniform(0, 10, [n, 1]) imag = np.random.uniform(0, 10, [n, 1]) A = real + imag * 1j start = time.time() w = hs.LeastSquares(A, alpha).solve() error = hs.residual_vibration(alpha.value, w, A) t = time.time() - start return round(t, 2)
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
import hsbalance as hs A = [['170@112'], ['53@78']] # --> Initial vibration conditions First Row in Table above. B = [ [ '235@94', '185@115' ], # --> Vibration at sensor 1 when trial masses were added at plane 1&2 (First column for both trial runs) ['58@68', '77@104'] ] # Vibration at sensor 2 when trial masses were added at plane 1&2 (Second column for both trial runs) U = ['1.15@0', '1.15@0'] # Trial masses 2.5 g at plane 1 and 2 consequently A = hs.convert_math_cart(A) B = hs.convert_math_cart(B) U = hs.convert_math_cart(U) alpha = hs.Alpha() # Instantiate Alpha class alpha.add(A=A, B=B, U=U) model_LeastSquares = hs.LeastSquares(A=A, alpha=alpha) w = model_LeastSquares.solve( ) # Solve the model and get the correction weights vector # Calculate Residual vibration vector residual_vibration = hs.residual_vibration(alpha.value, w, A) # Caculate Root mean square error for model RMSE = hs.rmse(residual_vibration) # Convert w back into mathmatical expression w = hs.convert_cart_math(w) # print results print(model_LeastSquares.info())