참고 사이트

by 스폴 | 2009/12/27 06:58 | Computer Graphic | 트랙백 | 덧글(3)

[C++] using Vector

출처 : http://dklee.net/30

요즘 C# 그리고 Silverlight 에 빠지다 보니 예전에 공부했던 내용들이 가물 가물 하더라구요 그리하여 이번에 차근 차근 보기로 했습니다. 초등학교때 썼던 일기장을 보듯?ㅋ

뜬금없이 Vector 가 나왔습니다. 요것은 Standard Library 있는 자료 구조중 하나이며 여러 종류들중 제가 가장 좋아하는 것입니다.

 

우선 vector 를 사용하기 위해서는 아래와 같이 해주셔야 합니다.

이제 본격적으로 사용 예를 보겠습니다.

CD 관리 프로그램으로 설명을 드리겠습니다.

우선은 App , CD 두개의 Class 가 존재합니다.

다음은 Class App 내용입니다.

여기서 vector <CD*> *base; 를 선언하였습니다. < > 여기 사이에 자료형을 넣습니다(여기선 클래스) 이네요 . 그리고 포인터 변수를 선언하였습니다.

실행과 동시에 App 생성자로 들어오게 되며, 이곳에서는 vector 초기화 합니다. 그리고 Run(); 을 실행하여 매뉴를 선택할 수 있게 하였고 이곳에서는 삽입,삭제,찾기 등을 할 수 있는 기능을 하게 됩니다.

이제 vector의 중요한 기능들을 보겠습니다.

<삽입>

<전체 출력>

for 문을 순회 하게 되는데 maximum 은 base->size() 로 하였습니다. size()는 vector의 총 크기를 int 형으로 반환해줍니다. 그리고 base->begin()은 vector의 처음을 가르키는데 증가하면서 역참조하여 CD 를 반환해줍니다. 이렇게하여 출력이 간으하게 됩니다. 이런 순회구문을 이용하여 찾기도 가능합니다. strcmp 등을 이용하여 문장을 비교하여 출력해주면 됩니다.

<삭제>

 

전체 출력 결과에서 삭제할 번호를 선택하여 index 에 저장하고 삭제를 하는 과정입니다. index-1 해준 이유는 vector의 시작이 0 부터 시작하기 때문입니다. erase() 를통해 단순히 목록에서 삭제해주기전에 선택한 CD 실제로 메모리 해제를 하기위해 delete 를 사용하였습니다.

by 스폴 | 2009/11/19 01:51 | Programming | 트랙백 | 덧글(0)

Math Algorithm 관련 사이트

http://people.sc.fsu.edu/~burkardt/cpp_src/svd_demo/svd_demo.html
http://www.alglib.net

SVD 관련 자료 찾아서 Eigen Value구하는것 까지 했음...
지친다....;

by 스폴 | 2009/11/15 04:27 | 수학이론 | 트랙백 | 덧글(0)

Singular Value Decomposition 줄여서 SVD

Singular value decomposition


출처 : http://www.alglib.net/matrixops/general/svd.php

The singular value decomposition of MxN matrix A is its representation as A = U W V T, where U is an orthogonal MxM matrix, V - orthogonal NxN matrix. The diagonal elements of matrix W are non-negative numbers in descending order, all off-diagonal elements are zeros.

The matrix W consists mainly of zeros, so we only need the first min(M,N) columns (three, in the example above) of matrix U to obtain matrix A. Similarly, only the first min(M,N) rows of matrix V T affect the product. These columns and rows are called left and right singular vectors.

The singular value decomposition has many useful properties. For example, it can be used to: solve underdetermined and overdetermined systems of linear equations, matrix inversion and pseudoinversion, matrix condition number calculation, vector system orthogonalization and orthogonal complement calculation.

Review of existing algorithms

The Jacobi algorithm was one of the first to perform the singular value decomposition. It reduces a rectangular matrix to a diagonal matrix by using a sequence of elementary rotations. The method can find all the singular values with high precision, including very small ones. However its performance was rather low, thus the iterative QR algorithms became more popular.

The basis of the most popular modern singular value decomposition algorithms lies in the matrix reduction to a bidiagonal form by orthogonal transformation (this problem is sufficiently simple and requires a finite number of operations to solve it) and its diagonalization by using an iterative QR algorithm. Usually, algorithms differ only by their QR algorithm implementation. At first, the algorithm family based on the Golub-Kahan-Reinsch algorithm was the most wide spread. It is this very same method that was implemented in LINPACK/EISPACK. The advantages of the method are its simplicity and compactness (300 lines of code). Unfortunately, it has no other advantages. Although this algorithm is capable of solving the problems, its convergence and precision are somewhat poor.

There are two singular value decomposition algorithms in the LAPACK library which eliminate the defects of the LINPACK algorithm. The first algorithm (xBDSQR and xGESVD subroutines), which was a prototype for an algorithm described here, has better precision and convergence than its LINPACK analog, so it replaces its predecessor.

It should be noted that the new algorithm finds small singular values of a bidiagonal matrix with better precision. The LINPACK variant of the QR iteration finds all the singular values with the same absolute error. The biggest singular value is obtained with an accuracy close to machine precision. It is sufficient for problems where the absolute error of singular values is critical: when solving systems of linear equations, inverting matrices, etc. But sometimes smaller singular values are important, whose relative error appears to be too large. For instance, if the first singular value equals 1 and was found with absolute error 10 -15 (15 significant digits), the singular value which is equal to 10 -10 found with the same absolute error will have only 5 significant digits. The new algorithms find all the values with the same relative error, so that both singular values will have 15 significant digits.

Unfortunately, the errors of reducing a general matrix to bidiagonal form brings this advantage to nothing - they corrupt small singular values which can be found precisely by using the new algorithm. Therefore, if your matrix isn't bidiagonal, you will get the only advantage of a new algorithm - better convergence. However, some matrix types could be reduced to bidiagonal form without changing small singular values. Such algorithms are not presented on the site at the moment. If small singular values precision is critical, it is worth finding theoretical material and implementing it by yourself. There are few algorithms designed in this field (hopefully this will change for the better).

As stated above, there are two singular value decomposition algorithms in the LAPACK library. The second algorithm (which is the "divide-and-conquer" algorithm) divides a task of big bidiagonal matrix SVD decomposition into some smaller tasks which are solved by using the QR algorithm. This algorithm shows better performance than the QR algorithm when working with big matrices. For instance, the square matrix singular value decomposition by "divide-and-conquer" when N=100 is 2-4 times faster than by a simple QR algorithm (including the time required to reduce the matrix to bidiagonal form), and is 6-7 times faster when N=1000. However, this algorithm is technically too complex, so it is unlikely to be included in the ALGLIB library in the near future. If the performance of big matrices singular value decomposition is critical to your tasks, please refer to the LAPACK library.

Algorithm

As described above, the modern singular decomposition algorithms reduce the matrix to bidiagonal form and then diagonalize it using QR algorithm. This simple method is quite efficient, but we can speed up an algorithm significantly. The improved algorithm scheme described below was borrowed from the LAPACK library (xGESVD subroutine).

This algorithm works well for square and close to square matrices. If the source matrix is rectangular and has a prolate form, instead of reducing it to bidiagonal form, we can use the LQ or QR decomposition (depending on which matrix dimension is bigger) to represent it as the product of a rectangular orthogonal matrix Q and square (upper or lower triangular) matrix. After that, we will diagonalize the square matrix which is much smaller than the source matrix. Depending on the rows and columns ratio, we can get an algorithm which is 2-6 times faster than the generic algorithm.

The second (more technical) improvement is the optimization of the matrix U calculation. When calculating matrix U, column operations are performed. They are not effective (compared to processor cache usage) when working with ordinary ways of storing matrices by rows, which is typical of most programming languages. If additional memory is available, we can calculate the matrix U T by performing operations with matrix rows. This is more effective especially if the matrix U is large. After that, we can transpose matrix U T.

Both these improvements require additional memory. If it is impossible to allocate enough memory, the programmer can prohibit the use of additional memory, but this will slow down an algorithm by several times.

Subroutine description

The RMatrixSVD subroutine performs the SVD decomposition of a rectangular MxN matrix. It returns singular values array in descending order and, if needed, matrices U and V T. In that case, it can return either only left or only right singular vectors and complete MxM or NxN matrices (depending on the values of the parameters UNeeded and VTNeeded). Note that VT contains the matrix V T.

The subroutine parameters are described in more detail in the program comments.

by 스폴 | 2009/11/15 04:26 | 수학이론 | 트랙백 | 덧글(0)

수학 기호 정리

출처 : http://falcon162.tistory.com/48

* 그리스 문자 발음
Α/α(알파) Β/β(베타) Γ/γ(감마) Δ/δ(델타) Ε/ε(엡실론) Ζ/ζ(제타) Η/η(에타) Θ/θ(쎄타) Ι/ι(요타) Κ/κ(카파) Λ/λ(람다) Μ/μ(뮤) Ν/ν(뉴) Ξ/ξ(크시) Ο/ο(오미크론) Π/π(피) Ρ/ρ(로우) Σ/σ(씨그마) Τ/τ(타우) Υ/υ(윕실론) Φ/φ(휘) Χ/χ(키 또는 카이) Ψ/ψ(프시) Ω/ω(오메가)


* 수학기호

σ : 소문자 시그마는 표준편차를 나타내는 기호
Σ : 대문자 시그마는 아래첨자와 위첨자를 기입하여 합에 관한 기호로 사용
i : 아이. 허수단위. 제곱해서 -1이 되는 수입니다.
cosΘ : 코사인쎄타인듯 보입니다. cosθ를 쓴거 맞는지요?
(하이퍼블릭코사인-쌍곡삼각함수중 하나로 수학에서는 거의 cosh를 사용합니다)
√ - 제곱근 또는 루트라고 읽습니다.
ㅠ - 파이 : 정확한 모양을 모르겠는데, 소문자 파이는 원주율을 나타내는 기호로 3.141592... 값을 가지며, 대문자 파이는 확률에서 중복순열을 나타내거나 위첨자 아래첨자와 함께 쓰는 경우 곱에 관한 기호가 됩니다.
∫ - 인테그랄 : 적분기호
∬ - 중적분 기호로, 적분을 두번 하라는 것입니다.
V。 - ? 뭡니까 이건? 혹시 V만 쓴 것이라면 분산을 나타내는 것이긴 한데... 이건 잘 모르겠군요
± - 플러스마이너스 : 플러스 또는 마이너스 라는 뜻
× - 곱하기
÷ - 나누기
∏ - 대문자 파이군요.. 위에서 설명드렸고..
≠ - 같지앉다
∴ - 따라서 또는 그러므로
∵ - 왜냐하면
≒ - 약: 근사값을 쓸때 또는 양쪽 값이 거의 비슷할때 사용
≤ - (왼쪽이 오른쪽보다) 작거나 같다
≥ - (왼쪽이 오른쪽보다) 크거나 같다
< - (왼쪽이 오른쪽보다) 작다
> - (왼쪽이 오른쪽보다) 크다
dθ - 디쎄타 - 미분에서 사용되는 기호입니다.
≡ - 합동 또는 모듈로(mod)를 나타내는 기호인데... 아마 질문하신 님이 알파, 베타를 읽을 줄 모르신다면,, 나이가 어리신듯 한데, 만약 십대시라면, 그냥 도형의 합동 기호라고 알아두는게 좋을 듯 합니다.
∈ - (왼쪽이 오른쪽의) 원소이다.
∋ - (오른쪽이 왼쪽의) 원소이다.
⊂ - (왼쪽이 오른쪽의) 부분집합이다. (오른쪽 집합이 왼쪽 집합을) 포함한다.
⊃ - (오른쪽이 왼쪽의) 부분집합이다. (오른쪽 집합이 왼쪽 집합을) 포함한다.
∪ - 합집합
∩ - 교집합
∀ - 임의의
∃ - 존재한다. exist.

by 스폴 | 2009/11/14 23:53 | 수학이론 | 트랙백 | 덧글(0)

◀ 이전 페이지          다음 페이지 ▶