# /home/bill/Qnial/NEUNET-D-12_00454 qnial Li, Wang - Consistent stabilizability.ndf # Neural Networks journal, paper review due 05Feb2013 - qnial routines # NEUNET-D-12_00454 qnial Li, Wang - Consistent stabilizability of Switched Boolean networks.ndf # Matlab toolbox http://lsc.amss.ac.cn/~dcheng/stp/STP.zip # Other references Dai-zhan Cheng "Chapter 2 2.2 Semi-tensor Product of Matrices" http://www.google.ca/url?sa=t&rct=j&q=semi-tensor%20product%20of%20matrices%20and%20its%20applications&source=web&cd=1&cad=rja&ved=0CDEQFjAA&url=http%3A%2F%2Fwww.intlpress.com%2FMAA%2Fp%2F2003%2F10_4%2FMAA-10-4-565-588.pdf&ei=mMsPUYKVIs3ryAHz5IGABA&usg=AFQjCNE2DeFnPiDXnLSnBsPStg-UAESSAg&bvm=bv.41867550,d.aWc ... Daizhan Cheng, Yali Dong 0312dd “Semi-Tensor product of matrices and some applications to physics” Methods and Applications of Analysis, Vol. 10, No. 4, pp. 565–588, December 2003 http://www.google.ca/url?sa=t&rct=j&q=semi-tensor%20product%20of%20matrices%20and%20its%20applications&source=web&cd=3&cad=rja&ved=0CEMQFjAC&url=http%3A%2F%2Fwww.springer.com%2Fcda%2Fcontent%2Fdocument%2Fcda_downloaddocument%2F9780857290960-c2.pdf%3FSGWID%3D0-0-45-1028139-p174033909&ei=mMsPUYKVIs3ryAHz5IGABA&usg=AFQjCNFX5Caqm1SNadUf-dbnL6HUD3zRdQ&bvm=bv.41867550,d.aWc Cheng, Dong 0312dd - Semi-Tensor product of matrices and some applications to physics.pdf ... Daizhan Cheng 110114 "Semi-tensor Product of Matrices and Its Applications" Institute of Systems Science, Academy of Mathematics and Systems Science, Chinese Academy of Sciences http://www.iss.ac.cn/iss/iss_talk/iss2011chendaizhan.pdf #******************************************* # Setup - only have to get "semi-tensor product.ndf", which grabs related routines # Reminder of debug setup... # IF flag_break = l THEN Break ; ENDIF # Defined in Qnial/profile.ndf # Qnial_root := '/home/bill/Qnial/' ; # Qnial_mine := '/home/bill/Qnial/MY_NDFS/' ; ld IS loaddefs link Qnial_mine 'semi-tensor product - examples and checks.ndf' IF not in "SEMI_TENSOR_PROD (EACH first symbols 0) THEN loaddefs link Qnial_mine 'semi-tensor product.ndf' 0 ; ENDIF; IF not in "EQUAL_APPROX (EACH first symbols 0) THEN loaddefs link Qnial_mine 'MY_NDFS/equal_approx.ndf' 0 ; ENDIF; # equal_approx IS OP A B tolerance - allows for approximately equal comparisons (eg round-off errors etc) #************************************************** # Kronecker product (circle with "X" in it) # this is a tensor product of vectors v1 & v2 # it is NOT matrix multiplication! # Examples - from Wikipedia http://en.wikipedia.org/wiki/Kronecker_product A := 2 2 reshape 1 2 3 4 ; B := 2 2 reshape 0 5 6 7 ; A_lab := array_indexLabelled 'A' (2 2) ; B_lab := array_indexLabelled 'B' (2 2) ; C_lab := array_indexLabelled 'C' (2 5) ; D_lab := array_indexLabelled 'D' (3 4) ; A1 B1 := EACH array_of_strings A B ; KP_1_symbols := Kronecker_prod_symbolic A B ; KP_1_numeric_from_symbols := EACH execute KP_1_symbols ; KP_1 := Kronecker_prod A B ; # Kronecker_prod A B = KP_1_reference := 4 4 reshape 0 5 0 10 6 7 12 14 0 15 0 20 18 21 24 28 ; Compliance_KP_1_from_symbols := KP_1_numeric_from_symbols = KP_1 ; Compliance_KP_1 := KP_1 = KP_1_reference ; #***************************************** # Cheng's semi-tensor product # Examples - from Cheng, Chapter 2 (date?) : page 32 http://www.google.ca/url?sa=t&rct=j&q=semi-tensor%20product%20of%20matrices%20and%20its%20applications&source=web&cd=1&cad=rja&ved=0CDEQFjAA&url=http%3A%2F%2Fwww.intlpress.com%2FMAA%2Fp%2F2003%2F10_4%2FMAA-10-4-565-588.pdf&ei=mMsPUYKVIs3ryAHz5IGABA&usg=AFQjCNE2DeFnPiDXnLSnBsPStg-UAESSAg&bvm=bv.41867550,d.aWc #----- # Example 1 X1 := vector_from_list (2 -1 1 2) 'row' ; Y1 := vector_from_list (-2 1) 'col' ; # an intermediate is: Z1_reference = [2 −1] × (−2) + [1 2] = [-3 4] Z1 := Semi_tensor_prod X1 Y1 ; Z1_reference := 1 2 reshape -3 4 ; Compliance_Z1 := Z1 = Z1_reference ; #----- # Example 2 X2 := 3 4 reshape 2 1 -1 3 0 1 2 -1 2 -1 1 1 ; Y2 := 2 2 reshape -1 2 3 2 ; # an interediate is : Z2 = Semi_tensor_prod X2 Y2 = (the following is WRONG from his book?... see also Z2_reference below!) (21) × (−1) + (−13) × 3 (21) × 2 + (−13) × 2 (01) × (−1) + (2 − 1) × 3 (01) × 2 + (2 − 1) × 2 (2 − 1) × (−1) + (11) × 3 (2 − 1) × 2 + (11) × 2 Z2 := Semi_tensor_prod X2 Y2 ; Z2_reference := 3 4 reshape -5 8 2 8 6 -4 4 0 1 4 6 0 ; Compliance_Z2 := Z2 = Z2_reference ; # Examples from Cheng's Matlab toolbox - example01.m # This example is to show how to perform semi-tensor product # Code has been "morphed" for QNial, and my name for operators x3 := vector_from_list (1 2 3 -1) 'row' ; y3 := vector_from_list (2 1) 'col' ; r3 := semi_tensor_prod x3 y3 ; r3_reference := vector_from_list (5 3) 'row' ; Compliance_R3 := r3 = r3_reference ; # x4 := vector_from_list (2 1) 'row' ; y4 := vector_from_list (1 2 3 -1) 'col' ; r4 := sp(x,y) r4_reference := vector_from_list (5 3) 'row' ; Compliance_r4 := r4 = r4_reference ; x5 := 3 4 reshape 1 2 1 1 2 3 1 2 3 2 1 0 ; y5 := 2 2 reshape 1 -2 2 -1 ; r5 := semi_tensor_prod x5 y5 ; %r5_1 := sp1(x,y) ; r5_reference := 3 4 reshape 3 4 -3 -5 4 7 -5 -8 5 2 -7 -4 ; %r5_1_reference := [3,4,-3,-5 4,7,-5,-8 5,2,-7,-4] ; Compliance_r5 := r5 = r5_reference ; # r5 := sp(sp(x,y),y) r6 := spn(x,y,y) r5_reference r6_reference EACHLEFT := [-3,-6,-3,-3;-6,-9,-3,-6;-9,-6,-3,0] #***************************************** # array_to_row_stack IS OP A - Row stacking form of an array # - my own unvalidated example # use KP_1_reference A2RS := array_to_row_stack KP_1_reference ; A2RS_reference := 0 5 0 10 6 7 12 14 0 15 0 20 18 21 24 28 ; A2RS_reference := 1 (gage shape A2RS_reference) reshape A2RS_reference ; Compliance_A2RS := A2RS = A2RS_reference ; # regeneration of an Array : P(x,y) = x^TAy :: P(x,y) = Vr(A) semi_tensor_prod x semi_tensor_prod y # I don't actually have a numerical example yet, but I should be able to show symbolically #***************************************** # Swap matrix - from Cheng's presentation W1 := swap_matrix_make 2 3 ; W1_reference := 6 6 reshape 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 ; Compliance_W1 := W1 = W1_reference ; #**************************************** # Theoretical tests use data from : # X2 Y2, X5 Y5 from : /home/bill/Qnial/NEUNET-D-12_00454 qnial Li, Wang - Consistent stabilizability.ndf # A B from : /home/bill/Qnial/MY_NDFS/matrix_multiply - examples and validation.ndf #***************************************** # Distributive rule - using A := 3 5 reshape tell 20 ; B := 5 4 reshape (+ 20 (tell 23)) ; C := 5 4 reshape (+ 100 (tell 23)) ; % C MUST be the same shape as B in order to add them! ; alpha := 3 ; beta := 2 ; D_ABC_left := A semi_tensor_prod ((alpha * B) + (beta * C)) ; D_ABC_right := ((alpha * A) semi_tensor_prod B) + ((beta * A) semi_tensor_prod C) ; Compliance_D_ABC := D_ABC_left = D_ABC_right ; D_BCA_left := ((alpha * B) + (beta * C)) semi_tensor_prod A ; D_BCA_right := ((alpha * B) semi_tensor_prod A) + ((beta * C) semi_tensor_prod A) ; Compliance_D_BCA := D_BCA_left = D_BCA_right ; #***************************************** # Associative rule - using A_ABC_left := A semi_tensor_prod (B semi_tensor_prod C) ; A_ABC_right := (A semi_tensor_prod B) semi_tensor_prod C ; Compliance_A_ABC := A_ABC_left = A_ABC_right ; #***************************************** # Distributive rule with respect to Transpose, with order change DT_AB_left := transpose (A semi_tensor_prod B) ; DT_AB_right := (transpose B) semi_tensor_prod (transpose A) ; Compliance_DT_AB := DT_AB_left = DT_AB_right ; #***************************************** # Distributive rule with respect to inversion, with order change # To get inverse - must be square matrices!!! AI := 5 5 reshape (* 10 (random 5 5)) ; BI := 5 5 reshape (* 5 (random 5 5)) ; DI_AB_left := inverse (AI semi_tensor_prod BI) ; DI_AB_right := (inverse BI) semi_tensor_prod (inverse AI) ; Compliance_DI_AB := equal_approx DI_AB_left DI_AB_right 0.001 ; #**************************************** # Pseudo-Commutativity for [row vector] Array [column vector] # uses X5 (array), X3 (row vector) # stp = semi_tensro_prod # kp = Kronecker_prod # 'Pseudo-Comutativity A stp V_row = V_row stp (I_t Kp A)' Compliance_PC1 A_PC := X5 ; Z_PC := X3 ; t_PC1 := semi_tensor_LCM A_PC Z_PC ; PC1_left := semi_tensor_prod_allSteps ('A' A_PC) ('Z' Z_PC) ; Kron_I_A := Kronecker_prod_symbolic (Identity_array t_PC1) A_PC ; PC1_right := semi_tensor_prod_allSteps ('Z' Z_PC) ('Kron_I_A' Kron_I_A) ; Compliance_PC1 := = PC1_left PC1_right ; y_PC := 'y_PC' transpose X3 ; t_PC2 := semi_tensor_LCM y_PC X5 ; # PC2_left := semi_tensor_prod_allSteps y_PC A_PC ; PC2_right := semi_tensor_prod_allSteps y_PC (Kronecker_prod_symbolic (Identity_array t_PC2) A_PC) ; Compliance_PC2 := = PC2_left PC2_right ; #***************************************** #***************************************** #-------------------------------- # Check on standard results Compliances := 'KP_1_symbols := Kronecker_prod A B' 'No equivalent' 'KP_1_numeric_from_symbols = KP_1' Compliance_KP_1_from_symbols 'KP_1 := EACH execute KP_1_symbols' Compliance_KP_1 'Z1 := Semi_tensor_prod X1 Y1' Compliance_Z1 'Z2 := Semi_tensor_prod X2 Y2' Compliance_Z2 'r3 := Semi_tensor_prod X3 Y3' Compliance_r3 'r4 := Semi_tensor_prod X4 Y4' 'Compliance_r4 - not yet' 'r5 := Semi_tensor_prod X5 Y5' Compliance_r5 'A2RS := array_to_row_stack KP_1_reference' Compliance_A2RS 'W1 := swap_matrix_make 2 3' Compliance_W1 'Distributive rule with A B C, alpha, beta' Compliance_D_ABC 'Distributive rule with B C A, alpha, beta' Compliance_D_BCA 'Associative rule with A B C' Compliance_A_ABC 'Distributive wrt transpose with A B, swap' Compliance_DT_AB 'Distributive wrt inversion with A B, swap' Compliance_DI_AB 'Pseudo-Comutativity A stp V_row = V_row stp (I_t Kp A)' Compliance_PC1 ; comp_rows := floor (gage shape compliances / 2 ) ; Compliances := comp_rows 2 reshape Compliances ; # enddoc