Changeset 7294 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/3.4.0/ALGLIB-3.4.0/linalg.cs
- Timestamp:
- 01/09/12 11:42:08 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/3.4.0
- Files:
-
- 1 edited
- 1 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/3.4.0/ALGLIB-3.4.0/linalg.cs
r4977 r7294 1328 1328 Array whose indexes range within [0..N-1, 0..N-1]. 1329 1329 N - size of matrix A. 1330 IsUpper - storage format.1331 1330 ZNeeded - flag controlling whether the eigenvectors are needed or not. 1332 1331 If ZNeeded is equal to: 1333 1332 * 0, the eigenvectors are not returned; 1334 1333 * 1, the eigenvectors are returned. 1334 IsUpper - storage format. 1335 1335 1336 1336 Output parameters: … … 10960 10960 Array whose indexes range within [0..N-1, 0..N-1]. 10961 10961 N - size of matrix A. 10962 IsUpper - storage format.10963 10962 ZNeeded - flag controlling whether the eigenvectors are needed or not. 10964 10963 If ZNeeded is equal to: 10965 10964 * 0, the eigenvectors are not returned; 10966 10965 * 1, the eigenvectors are returned. 10966 IsUpper - storage format. 10967 10967 10968 10968 Output parameters: … … 17368 17368 public class matgen 17369 17369 { 17370 /************************************************************************* 17371 Generation of a random uniformly distributed (Haar) orthogonal matrix 17372 17373 INPUT PARAMETERS: 17374 N - matrix size, N>=1 17375 17376 OUTPUT PARAMETERS: 17377 A - orthogonal NxN matrix, array[0..N-1,0..N-1] 17378 17379 -- ALGLIB routine -- 17380 04.12.2009 17381 Bochkanov Sergey 17382 *************************************************************************/ 17370 17383 public static void rmatrixrndorthogonal(int n, 17371 17384 ref double[,] a) … … 17396 17409 17397 17410 17411 /************************************************************************* 17412 Generation of random NxN matrix with given condition number and norm2(A)=1 17413 17414 INPUT PARAMETERS: 17415 N - matrix size 17416 C - condition number (in 2-norm) 17417 17418 OUTPUT PARAMETERS: 17419 A - random matrix with norm2(A)=1 and cond(A)=C 17420 17421 -- ALGLIB routine -- 17422 04.12.2009 17423 Bochkanov Sergey 17424 *************************************************************************/ 17398 17425 public static void rmatrixrndcond(int n, 17399 17426 double c, … … 17438 17465 17439 17466 17467 /************************************************************************* 17468 Generation of a random Haar distributed orthogonal complex matrix 17469 17470 INPUT PARAMETERS: 17471 N - matrix size, N>=1 17472 17473 OUTPUT PARAMETERS: 17474 A - orthogonal NxN matrix, array[0..N-1,0..N-1] 17475 17476 -- ALGLIB routine -- 17477 04.12.2009 17478 Bochkanov Sergey 17479 *************************************************************************/ 17440 17480 public static void cmatrixrndorthogonal(int n, 17441 17481 ref complex[,] a) … … 17466 17506 17467 17507 17508 /************************************************************************* 17509 Generation of random NxN complex matrix with given condition number C and 17510 norm2(A)=1 17511 17512 INPUT PARAMETERS: 17513 N - matrix size 17514 C - condition number (in 2-norm) 17515 17516 OUTPUT PARAMETERS: 17517 A - random matrix with norm2(A)=1 and cond(A)=C 17518 17519 -- ALGLIB routine -- 17520 04.12.2009 17521 Bochkanov Sergey 17522 *************************************************************************/ 17468 17523 public static void cmatrixrndcond(int n, 17469 17524 double c, … … 17512 17567 17513 17568 17569 /************************************************************************* 17570 Generation of random NxN symmetric matrix with given condition number and 17571 norm2(A)=1 17572 17573 INPUT PARAMETERS: 17574 N - matrix size 17575 C - condition number (in 2-norm) 17576 17577 OUTPUT PARAMETERS: 17578 A - random matrix with norm2(A)=1 and cond(A)=C 17579 17580 -- ALGLIB routine -- 17581 04.12.2009 17582 Bochkanov Sergey 17583 *************************************************************************/ 17514 17584 public static void smatrixrndcond(int n, 17515 17585 double c, … … 17561 17631 17562 17632 17633 /************************************************************************* 17634 Generation of random NxN symmetric positive definite matrix with given 17635 condition number and norm2(A)=1 17636 17637 INPUT PARAMETERS: 17638 N - matrix size 17639 C - condition number (in 2-norm) 17640 17641 OUTPUT PARAMETERS: 17642 A - random SPD matrix with norm2(A)=1 and cond(A)=C 17643 17644 -- ALGLIB routine -- 17645 04.12.2009 17646 Bochkanov Sergey 17647 *************************************************************************/ 17563 17648 public static void spdmatrixrndcond(int n, 17564 17649 double c, … … 17613 17698 17614 17699 17700 /************************************************************************* 17701 Generation of random NxN Hermitian matrix with given condition number and 17702 norm2(A)=1 17703 17704 INPUT PARAMETERS: 17705 N - matrix size 17706 C - condition number (in 2-norm) 17707 17708 OUTPUT PARAMETERS: 17709 A - random matrix with norm2(A)=1 and cond(A)=C 17710 17711 -- ALGLIB routine -- 17712 04.12.2009 17713 Bochkanov Sergey 17714 *************************************************************************/ 17615 17715 public static void hmatrixrndcond(int n, 17616 17716 double c, … … 17670 17770 17671 17771 17772 /************************************************************************* 17773 Generation of random NxN Hermitian positive definite matrix with given 17774 condition number and norm2(A)=1 17775 17776 INPUT PARAMETERS: 17777 N - matrix size 17778 C - condition number (in 2-norm) 17779 17780 OUTPUT PARAMETERS: 17781 A - random HPD matrix with norm2(A)=1 and cond(A)=C 17782 17783 -- ALGLIB routine -- 17784 04.12.2009 17785 Bochkanov Sergey 17786 *************************************************************************/ 17672 17787 public static void hpdmatrixrndcond(int n, 17673 17788 double c, … … 17730 17845 17731 17846 17847 /************************************************************************* 17848 Multiplication of MxN matrix by NxN random Haar distributed orthogonal matrix 17849 17850 INPUT PARAMETERS: 17851 A - matrix, array[0..M-1, 0..N-1] 17852 M, N- matrix size 17853 17854 OUTPUT PARAMETERS: 17855 A - A*Q, where Q is random NxN orthogonal matrix 17856 17857 -- ALGLIB routine -- 17858 04.12.2009 17859 Bochkanov Sergey 17860 *************************************************************************/ 17732 17861 public static void rmatrixrndorthogonalfromtheright(ref double[,] a, 17733 17862 int m, … … 17816 17945 17817 17946 17947 /************************************************************************* 17948 Multiplication of MxN matrix by MxM random Haar distributed orthogonal matrix 17949 17950 INPUT PARAMETERS: 17951 A - matrix, array[0..M-1, 0..N-1] 17952 M, N- matrix size 17953 17954 OUTPUT PARAMETERS: 17955 A - Q*A, where Q is random MxM orthogonal matrix 17956 17957 -- ALGLIB routine -- 17958 04.12.2009 17959 Bochkanov Sergey 17960 *************************************************************************/ 17818 17961 public static void rmatrixrndorthogonalfromtheleft(ref double[,] a, 17819 17962 int m, … … 17903 18046 17904 18047 18048 /************************************************************************* 18049 Multiplication of MxN complex matrix by NxN random Haar distributed 18050 complex orthogonal matrix 18051 18052 INPUT PARAMETERS: 18053 A - matrix, array[0..M-1, 0..N-1] 18054 M, N- matrix size 18055 18056 OUTPUT PARAMETERS: 18057 A - A*Q, where Q is random NxN orthogonal matrix 18058 18059 -- ALGLIB routine -- 18060 04.12.2009 18061 Bochkanov Sergey 18062 *************************************************************************/ 17905 18063 public static void cmatrixrndorthogonalfromtheright(ref complex[,] a, 17906 18064 int m, … … 17982 18140 17983 18141 18142 /************************************************************************* 18143 Multiplication of MxN complex matrix by MxM random Haar distributed 18144 complex orthogonal matrix 18145 18146 INPUT PARAMETERS: 18147 A - matrix, array[0..M-1, 0..N-1] 18148 M, N- matrix size 18149 18150 OUTPUT PARAMETERS: 18151 A - Q*A, where Q is random MxM orthogonal matrix 18152 18153 -- ALGLIB routine -- 18154 04.12.2009 18155 Bochkanov Sergey 18156 *************************************************************************/ 17984 18157 public static void cmatrixrndorthogonalfromtheleft(ref complex[,] a, 17985 18158 int m, … … 18062 18235 18063 18236 18237 /************************************************************************* 18238 Symmetric multiplication of NxN matrix by random Haar distributed 18239 orthogonal matrix 18240 18241 INPUT PARAMETERS: 18242 A - matrix, array[0..N-1, 0..N-1] 18243 N - matrix size 18244 18245 OUTPUT PARAMETERS: 18246 A - Q'*A*Q, where Q is random NxN orthogonal matrix 18247 18248 -- ALGLIB routine -- 18249 04.12.2009 18250 Bochkanov Sergey 18251 *************************************************************************/ 18064 18252 public static void smatrixrndmultiply(ref double[,] a, 18065 18253 int n) … … 18137 18325 18138 18326 18327 /************************************************************************* 18328 Hermitian multiplication of NxN matrix by random Haar distributed 18329 complex orthogonal matrix 18330 18331 INPUT PARAMETERS: 18332 A - matrix, array[0..N-1, 0..N-1] 18333 N - matrix size 18334 18335 OUTPUT PARAMETERS: 18336 A - Q^H*A*Q, where Q is random NxN orthogonal matrix 18337 18338 -- ALGLIB routine -- 18339 04.12.2009 18340 Bochkanov Sergey 18341 *************************************************************************/ 18139 18342 public static void hmatrixrndmultiply(ref complex[,] a, 18140 18343 int n) … … 24752 24955 public class bdsvd 24753 24956 { 24957 /************************************************************************* 24958 Singular value decomposition of a bidiagonal matrix (extended algorithm) 24959 24960 The algorithm performs the singular value decomposition of a bidiagonal 24961 matrix B (upper or lower) representing it as B = Q*S*P^T, where Q and P - 24962 orthogonal matrices, S - diagonal matrix with non-negative elements on the 24963 main diagonal, in descending order. 24964 24965 The algorithm finds singular values. In addition, the algorithm can 24966 calculate matrices Q and P (more precisely, not the matrices, but their 24967 product with given matrices U and VT - U*Q and (P^T)*VT)). Of course, 24968 matrices U and VT can be of any type, including identity. Furthermore, the 24969 algorithm can calculate Q'*C (this product is calculated more effectively 24970 than U*Q, because this calculation operates with rows instead of matrix 24971 columns). 24972 24973 The feature of the algorithm is its ability to find all singular values 24974 including those which are arbitrarily close to 0 with relative accuracy 24975 close to machine precision. If the parameter IsFractionalAccuracyRequired 24976 is set to True, all singular values will have high relative accuracy close 24977 to machine precision. If the parameter is set to False, only the biggest 24978 singular value will have relative accuracy close to machine precision. 24979 The absolute error of other singular values is equal to the absolute error 24980 of the biggest singular value. 24981 24982 Input parameters: 24983 D - main diagonal of matrix B. 24984 Array whose index ranges within [0..N-1]. 24985 E - superdiagonal (or subdiagonal) of matrix B. 24986 Array whose index ranges within [0..N-2]. 24987 N - size of matrix B. 24988 IsUpper - True, if the matrix is upper bidiagonal. 24989 IsFractionalAccuracyRequired - 24990 accuracy to search singular values with. 24991 U - matrix to be multiplied by Q. 24992 Array whose indexes range within [0..NRU-1, 0..N-1]. 24993 The matrix can be bigger, in that case only the submatrix 24994 [0..NRU-1, 0..N-1] will be multiplied by Q. 24995 NRU - number of rows in matrix U. 24996 C - matrix to be multiplied by Q'. 24997 Array whose indexes range within [0..N-1, 0..NCC-1]. 24998 The matrix can be bigger, in that case only the submatrix 24999 [0..N-1, 0..NCC-1] will be multiplied by Q'. 25000 NCC - number of columns in matrix C. 25001 VT - matrix to be multiplied by P^T. 25002 Array whose indexes range within [0..N-1, 0..NCVT-1]. 25003 The matrix can be bigger, in that case only the submatrix 25004 [0..N-1, 0..NCVT-1] will be multiplied by P^T. 25005 NCVT - number of columns in matrix VT. 25006 25007 Output parameters: 25008 D - singular values of matrix B in descending order. 25009 U - if NRU>0, contains matrix U*Q. 25010 VT - if NCVT>0, contains matrix (P^T)*VT. 25011 C - if NCC>0, contains matrix Q'*C. 25012 25013 Result: 25014 True, if the algorithm has converged. 25015 False, if the algorithm hasn't converged (rare case). 25016 25017 Additional information: 25018 The type of convergence is controlled by the internal parameter TOL. 25019 If the parameter is greater than 0, the singular values will have 25020 relative accuracy TOL. If TOL<0, the singular values will have 25021 absolute accuracy ABS(TOL)*norm(B). 25022 By default, |TOL| falls within the range of 10*Epsilon and 100*Epsilon, 25023 where Epsilon is the machine precision. It is not recommended to use 25024 TOL less than 10*Epsilon since this will considerably slow down the 25025 algorithm and may not lead to error decreasing. 25026 History: 25027 * 31 March, 2007. 25028 changed MAXITR from 6 to 12. 25029 25030 -- LAPACK routine (version 3.0) -- 25031 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 25032 Courant Institute, Argonne National Lab, and Rice University 25033 October 31, 1999. 25034 *************************************************************************/ 24754 25035 public static bool rmatrixbdsvd(ref double[] d, 24755 25036 double[] e, … … 24818 25099 24819 25100 25101 /************************************************************************* 25102 Internal working subroutine for bidiagonal decomposition 25103 *************************************************************************/ 24820 25104 private static bool bidiagonalsvddecompositioninternal(ref double[] d, 24821 25105 double[] e, … … 28066 28350 public class inverseupdate 28067 28351 { 28352 /************************************************************************* 28353 Inverse matrix update by the Sherman-Morrison formula 28354 28355 The algorithm updates matrix A^-1 when adding a number to an element 28356 of matrix A. 28357 28358 Input parameters: 28359 InvA - inverse of matrix A. 28360 Array whose indexes range within [0..N-1, 0..N-1]. 28361 N - size of matrix A. 28362 UpdRow - row where the element to be updated is stored. 28363 UpdColumn - column where the element to be updated is stored. 28364 UpdVal - a number to be added to the element. 28365 28366 28367 Output parameters: 28368 InvA - inverse of modified matrix A. 28369 28370 -- ALGLIB -- 28371 Copyright 2005 by Bochkanov Sergey 28372 *************************************************************************/ 28068 28373 public static void rmatrixinvupdatesimple(ref double[,] inva, 28069 28374 int n, … … 28120 28425 28121 28426 28427 /************************************************************************* 28428 Inverse matrix update by the Sherman-Morrison formula 28429 28430 The algorithm updates matrix A^-1 when adding a vector to a row 28431 of matrix A. 28432 28433 Input parameters: 28434 InvA - inverse of matrix A. 28435 Array whose indexes range within [0..N-1, 0..N-1]. 28436 N - size of matrix A. 28437 UpdRow - the row of A whose vector V was added. 28438 0 <= Row <= N-1 28439 V - the vector to be added to a row. 28440 Array whose index ranges within [0..N-1]. 28441 28442 Output parameters: 28443 InvA - inverse of modified matrix A. 28444 28445 -- ALGLIB -- 28446 Copyright 2005 by Bochkanov Sergey 28447 *************************************************************************/ 28122 28448 public static void rmatrixinvupdaterow(ref double[,] inva, 28123 28449 int n, … … 28173 28499 28174 28500 28501 /************************************************************************* 28502 Inverse matrix update by the Sherman-Morrison formula 28503 28504 The algorithm updates matrix A^-1 when adding a vector to a column 28505 of matrix A. 28506 28507 Input parameters: 28508 InvA - inverse of matrix A. 28509 Array whose indexes range within [0..N-1, 0..N-1]. 28510 N - size of matrix A. 28511 UpdColumn - the column of A whose vector U was added. 28512 0 <= UpdColumn <= N-1 28513 U - the vector to be added to a column. 28514 Array whose index ranges within [0..N-1]. 28515 28516 Output parameters: 28517 InvA - inverse of modified matrix A. 28518 28519 -- ALGLIB -- 28520 Copyright 2005 by Bochkanov Sergey 28521 *************************************************************************/ 28175 28522 public static void rmatrixinvupdatecolumn(ref double[,] inva, 28176 28523 int n, … … 28225 28572 28226 28573 28574 /************************************************************************* 28575 Inverse matrix update by the Sherman-Morrison formula 28576 28577 The algorithm computes the inverse of matrix A+u*v by using the given matrix 28578 A^-1 and the vectors u and v. 28579 28580 Input parameters: 28581 InvA - inverse of matrix A. 28582 Array whose indexes range within [0..N-1, 0..N-1]. 28583 N - size of matrix A. 28584 U - the vector modifying the matrix. 28585 Array whose index ranges within [0..N-1]. 28586 V - the vector modifying the matrix. 28587 Array whose index ranges within [0..N-1]. 28588 28589 Output parameters: 28590 InvA - inverse of matrix A + u*v'. 28591 28592 -- ALGLIB -- 28593 Copyright 2005 by Bochkanov Sergey 28594 *************************************************************************/ 28227 28595 public static void rmatrixinvupdateuv(ref double[,] inva, 28228 28596 int n, … … 28290 28658 public class schur 28291 28659 { 28660 /************************************************************************* 28661 Subroutine performing the Schur decomposition of a general matrix by using 28662 the QR algorithm with multiple shifts. 28663 28664 The source matrix A is represented as S'*A*S = T, where S is an orthogonal 28665 matrix (Schur vectors), T - upper quasi-triangular matrix (with blocks of 28666 sizes 1x1 and 2x2 on the main diagonal). 28667 28668 Input parameters: 28669 A - matrix to be decomposed. 28670 Array whose indexes range within [0..N-1, 0..N-1]. 28671 N - size of A, N>=0. 28672 28673 28674 Output parameters: 28675 A - contains matrix T. 28676 Array whose indexes range within [0..N-1, 0..N-1]. 28677 S - contains Schur vectors. 28678 Array whose indexes range within [0..N-1, 0..N-1]. 28679 28680 Note 1: 28681 The block structure of matrix T can be easily recognized: since all 28682 the elements below the blocks are zeros, the elements a[i+1,i] which 28683 are equal to 0 show the block border. 28684 28685 Note 2: 28686 The algorithm performance depends on the value of the internal parameter 28687 NS of the InternalSchurDecomposition subroutine which defines the number 28688 of shifts in the QR algorithm (similarly to the block width in block-matrix 28689 algorithms in linear algebra). If you require maximum performance on 28690 your machine, it is recommended to adjust this parameter manually. 28691 28692 Result: 28693 True, 28694 if the algorithm has converged and parameters A and S contain the result. 28695 False, 28696 if the algorithm has not converged. 28697 28698 Algorithm implemented on the basis of the DHSEQR subroutine (LAPACK 3.0 library). 28699 *************************************************************************/ 28292 28700 public static bool rmatrixschur(ref double[,] a, 28293 28701 int n,
Note: See TracChangeset
for help on using the changeset viewer.