■ Linear Discriminant Analysis(LDA) - C-Classes
이전 글을 두개의 클래스를 판별하는 LDA에 대해서 알아 봤다. 그럼 여러개(C개)의 클래스를 어떻게 판별할 수 있을까? 접근은 2개의 클래스 판별 LDA 방법과 유사하다.
n-feature vectors를 가졌다면 다음과 같이 표현할 수 있다.
여기서 Y는 출력벡터, X는 입력벡터, W는 변환행렬이다.
- 즉 mxn입력 백터에 C개의 클래스를 LDA 분석을 하면 출력벡터는 c-1 by n개의 배열이 된다. 이에 중요한점은 각 클래스 마다 최적의 변환행렬을 계산해야 한다.
C개의 클래스를 가지는 입력 벡터를 LDA 분석하기 위한 단계는 다음과 같다.
1. 원래 데이터 차원에서 통계 계산
step 1: 클래스 내 분산 구하기
step 2: 클래스 간 분산 구하기
2. 투영된 데이터 차원에서 통계 계산
step 1: 평균 벡터 구하기
step 2: 클래스 내 분산 구하기
step 3: 클래스 간 분산 구하기
3. 목적행렬을 통한 최적 변환 행렬 찾기
는 최적 변환 행렬임
- 최적 변환 행렬은 일반적인 고유값 문제 해결로 얻을 수 있는 최고 고유값에 해당하는 고유벡터가 됨
- C개의 클래스는 C-1개의 변환행렬을 가짐
4. 차원 축소
추가적으로 LDA 접근은 두 가지 방법으로 나뉘어짐
- 클래스 종속: 각 클래스 마다 변환행렬 생성
- 클래스 독립: 하나의 변환행렬 생성
5. 예제
LDA에 쓸 3개의 클래스 샘플 생성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | %clear clear %dataset Generation %let the center of all classes be Mu = [5;5]; %%for the first class Mu1=[Mu(1)-3; Mu(2)+7]; CovM1 = [5 -1; -3 3]; %%for the second class Mu2=[Mu(1)-2.5; Mu(2)-3.5]; CovM2 = [4 0; 0 4]; %%for the third class Mu3=[Mu(1)+7; Mu(2)+5]; CovM3 = [3.5 1; 3 2.5]; %generating feature vectors using Box-Muller approach %Generate a random variable following uniform(0,1) having two features and %1000 feature vectors U=rand(2,1000); %Extracting from the generated uniform random variable two independent %uniform random variables; u1 = U(:,1:2:end); u2 = U(:,2:2:end); %Using u1 and u2, we will use Box-Muller method to generate the feature %vectors to follow standard normal X=sqrt((-2).*log(u1)).*(cos(2*pi.*u2)); clear u1 u2 U; %now ... Manipulating the generated features N(0,1) to following certain %mean and covariance orher than the standard normal %First we will change its variance then we will change its mean %Getting the eigen vectors and values of the covariance matrix [V,D] = eig(CovM1); % D is the eigen values matrix and V is the eigen vectors matrix newX=X; for j=1:size(X,2) newX(:,j)=V*sqrt(D)*X(:,j); end %changing its mean newX=newX+repmat(Mu1, 1, size(newX,2)); %now our dataset for the first class matrix will be X1 = newX; %each column is a feature vector, each row is a single feature %...do the same for the other two classes with difference means and covariance matrices [V,D] = eig(CovM2); newX=X; for j=1:size(X,2) newX(:,j)=V*sqrt(D)*X(:,j); end newX=newX+repmat(Mu2, 1, size(newX,2)); X2 = newX; [V,D] = eig(CovM3); newX=X; for j=1:size(X,2) newX(:,j)=V*sqrt(D)*X(:,j); end newX=newX+repmat(Mu3, 1, size(newX,2)); X3 = newX; %draw 2d scatter plot figure; hold on; plot(X1(1,:), X1(2,:), 'ro', 'markersize',10, 'linewidth', 3); plot(X2(1,:), X2(2,:), 'go', 'markersize',10, 'linewidth', 3); plot(X3(1,:), X3(2,:), 'bo', 'markersize',10, 'linewidth', 3); |
위 코드 수행시 아래와 같이 출력됨
LDA matlab 코드는 다음과 같다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | %% computing the LDA % class means Mu1= mean(X1')'; Mu3= mean(X2')'; Mu2= mean(X3')'; %overall mean Mu = (Mu1+Mu2+Mu3)./3; %class covariance matrices S1=cov(X1'); S2=cov(X2'); S3=cov(X3'); %within-class scatter matrix Sw=S1+S2+S3; %number of samples of each class N1=size(X1, 2); N2=size(X2, 2); N3=size(X3, 2); %between-class scatter matrix SB1=N1.*(Mu1-Mu)*(Mu1-Mu)'; SB2=N2.*(Mu2-Mu)*(Mu2-Mu)'; SB3=N3.*(Mu3-Mu)*(Mu3-Mu)'; SB=SB1+SB2+SB3; %computing the LDA projection invSw=inv(Sw); invSw_by_SB = invSw*SB; %getting the projection vectors %[V,D]=EIG(X) produces a diagonal matrix D of eigenvalues and a %full matrix V whose columns are the corresponding eigenvectors [V,D]=eig(invSw_by_SB); %the projcetion vectors - we will have at most C-1 projection vectors, %from which we can choose the most important ones ranked by their %corresponding eigen values ... lets investigate the two projection vectors W1=V(:,1); W2=V(:,2); %%lets visualize them... % we will plot the scatter plot to better visualize the features hfig=figure; axes1=axes('Parent',hfig,'FontWeight','bold','FontSize',12); hold('all'); %Create xLabel xlabel('X_1 - the first feature', 'FontWeight', 'bold', 'FontSize',12,'FontName', 'Garamond'); %Create yLabel ylabel('X_2 - the second feature', 'FontWeight', 'bold', 'FontSize',12,'FontName', 'Garamond'); %the fist class scatter(X1(1,:), X1(2,:),'r','LineWidth',2,'Parent',axes1); hold on %the second class scatter(X2(1,:), X2(2,:),'g','LineWidth',2,'Parent',axes1); hold on %the third class scatter(X3(1,:), X3(2,:),'b','LineWidth',2,'Parent',axes1); hold on %drawing the projection vectors %the first vector t=-10:25; line_x1 = t.*W1(1); line_y1 = t.*W1(1); %the second vector t=-5:20; line_x2 = t.*W2(1); line_y2 = t.*W2(2); plot(line_x1, line_y1, 'k-', 'LineWidth',3); hold on plot(line_x2, line_y2, 'm-', 'LineWidth',3); hold on %projection data samples along the projections axes %the first projection vector y1_w1 = W1'*X1; y2_w1 = W1'*X2; y3_w1 = W1'*X3; %projection limits minY=min([min(y1_w1), min(y2_w1), min(y3_w1)]); maxY=max([max(y1_w1), max(y2_w1), max(y3_w1)]); y_w1=minY:0.05:maxY; %for visualization lets compute the probability %density function of the classes after projection %the first class y1_w1_Mu = mean(y1_w1); y1_w1_sigma = std(y1_w1); y1_w1_pdf = mvnpdf(y1_w1',y1_w1_Mu,y1_w1_sigma); %the second class y2_w1_Mu = mean(y2_w1); y2_w1_sigma = std(y2_w1); y2_w1_pdf = mvnpdf(y1_w1',y2_w1_Mu,y2_w1_sigma); %the third class y3_w1_Mu = mean(y3_w1); y3_w1_sigma = std(y3_w1); y3_w1_pdf = mvnpdf(y1_w1',y3_w1_Mu,y3_w1_sigma); |
검은색이 고유값이 큰 고유벡터 값으로 판별되는 LD1 축이 되고, 다음 고유값에 따른 LD2 축이 보라색 선이 된다. 코드안에 차원축소를 한 데이터에 대해 PDF 분석 코드가 있다. 화면에 찍어야 하는데 그건 잘 모르겠다.
우선 LDA에 대해서 어떻게 접근해야 하는지 이제 좀 감이 잡힌다. 다시 LDA 전체 matlab 소스 코드를 첨부한다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | %clear clear %dataset Generation %let the center of all classes be Mu = [5;5]; %%for the first class Mu1=[Mu(1)-3; Mu(2)+7]; CovM1 = [5 -1; -3 3]; %%for the second class Mu2=[Mu(1)-2.5; Mu(2)-3.5]; CovM2 = [4 0; 0 4]; %%for the third class Mu3=[Mu(1)+7; Mu(2)+5]; CovM3 = [3.5 1; 3 2.5]; %generating feature vectors using Box-Muller approach %Generate a random variable following uniform(0,1) having two features and %1000 feature vectors U=rand(2,1000); %Extracting from the generated uniform random variable two independent %uniform random variables; u1 = U(:,1:2:end); u2 = U(:,2:2:end); %Using u1 and u2, we will use Box-Muller method to generate the feature %vectors to follow standard normal X=sqrt((-2).*log(u1)).*(cos(2*pi.*u2)); clear u1 u2 U; %now ... Manipulating the generated features N(0,1) to following certain %mean and covariance orher than the standard normal %First we will change its variance then we will change its mean %Getting the eigen vectors and values of the covariance matrix [V,D] = eig(CovM1); % D is the eigen values matrix and V is the eigen vectors matrix newX=X; for j=1:size(X,2) newX(:,j)=V*sqrt(D)*X(:,j); end %changing its mean newX=newX+repmat(Mu1, 1, size(newX,2)); %now our dataset for the first class matrix will be X1 = newX; %each column is a feature vector, each row is a single feature %...do the same for the other two classes with difference means and covariance matrices [V,D] = eig(CovM2); newX=X; for j=1:size(X,2) newX(:,j)=V*sqrt(D)*X(:,j); end newX=newX+repmat(Mu2, 1, size(newX,2)); X2 = newX; [V,D] = eig(CovM3); newX=X; for j=1:size(X,2) newX(:,j)=V*sqrt(D)*X(:,j); end newX=newX+repmat(Mu3, 1, size(newX,2)); X3 = newX; %draw 2d scatter plot figure; hold on; plot(X1(1,:), X1(2,:), 'ro', 'markersize',10, 'linewidth', 3); plot(X2(1,:), X2(2,:), 'go', 'markersize',10, 'linewidth', 3); plot(X3(1,:), X3(2,:), 'bo', 'markersize',10, 'linewidth', 3); %% computing the LDA % class means Mu1= mean(X1')'; Mu3= mean(X2')'; Mu2= mean(X3')'; %overall mean Mu = (Mu1+Mu2+Mu3)./3; %class covariance matrices S1=cov(X1'); S2=cov(X2'); S3=cov(X3'); %within-class scatter matrix Sw=S1+S2+S3; %number of samples of each class N1=size(X1, 2); N2=size(X2, 2); N3=size(X3, 2); %between-class scatter matrix SB1=N1.*(Mu1-Mu)*(Mu1-Mu)'; SB2=N2.*(Mu2-Mu)*(Mu2-Mu)'; SB3=N3.*(Mu3-Mu)*(Mu3-Mu)'; SB=SB1+SB2+SB3; %computing the LDA projection invSw=inv(Sw); invSw_by_SB = invSw*SB; %getting the projection vectors %[V,D]=EIG(X) produces a diagonal matrix D of eigenvalues and a %full matrix V whose columns are the corresponding eigenvectors [V,D]=eig(invSw_by_SB); %the projcetion vectors - we will have at most C-1 projection vectors, %from which we can choose the most important ones ranked by their %corresponding eigen values ... lets investigate the two projection vectors W1=V(:,1); W2=V(:,2); %%lets visualize them... % we will plot the scatter plot to better visualize the features hfig=figure; axes1=axes('Parent',hfig,'FontWeight','bold','FontSize',12); hold('all'); %Create xLabel xlabel('X_1 - the first feature', 'FontWeight', 'bold', 'FontSize',12,'FontName', 'Garamond'); %Create yLabel ylabel('X_2 - the second feature', 'FontWeight', 'bold', 'FontSize',12,'FontName', 'Garamond'); %the fist class scatter(X1(1,:), X1(2,:),'r','LineWidth',2,'Parent',axes1); hold on %the second class scatter(X2(1,:), X2(2,:),'g','LineWidth',2,'Parent',axes1); hold on %the third class scatter(X3(1,:), X3(2,:),'b','LineWidth',2,'Parent',axes1); hold on %drawing the projection vectors %the first vector t=-10:25; line_x1 = t.*W1(1); line_y1 = t.*W1(1); %the second vector t=-5:20; line_x2 = t.*W2(1); line_y2 = t.*W2(2); plot(line_x1, line_y1, 'k-', 'LineWidth',3); hold on plot(line_x2, line_y2, 'm-', 'LineWidth',3); hold on %projection data samples along the projections axes %the first projection vector y1_w1 = W1'*X1; y2_w1 = W1'*X2; y3_w1 = W1'*X3; %projection limits minY=min([min(y1_w1), min(y2_w1), min(y3_w1)]); maxY=max([max(y1_w1), max(y2_w1), max(y3_w1)]); y_w1=minY:0.05:maxY; %for visualization lets compute the probability %density function of the classes after projection %the first class y1_w1_Mu = mean(y1_w1); y1_w1_sigma = std(y1_w1); y1_w1_pdf = mvnpdf(y1_w1',y1_w1_Mu,y1_w1_sigma); %the second class y2_w1_Mu = mean(y2_w1); y2_w1_sigma = std(y2_w1); y2_w1_pdf = mvnpdf(y1_w1',y2_w1_Mu,y2_w1_sigma); %the third class y3_w1_Mu = mean(y3_w1); y3_w1_sigma = std(y3_w1); y3_w1_pdf = mvnpdf(y1_w1',y3_w1_Mu,y3_w1_sigma); |
[1] http://www.di.univr.it/documenti/OccorrenzaIns/matdid/matdid437773.pdf
[2] http://www.bytefish.de/blog/pca_lda_with_gnu_octave/
'PatternRecognition' 카테고리의 다른 글
Wilk's Lambda (2) | 2014.12.15 |
---|---|
Linear Discriminant Analysis(LDA) - 2 classes (0) | 2014.05.30 |
Neural Networks: Data normalization (0) | 2014.04.25 |
The Basic Artificial Neuron: Bias neuron(Backpropagation) (3) | 2014.04.23 |
기초 통계(Statistic) (0) | 2014.04.14 |
■ Linear Discriminant Analysis(LDA) - 2 classes
선형판별분석
1. 개념
- 클래스간 분산(between-class scatter)과 클래스내 분산(within-class scatter)의 비율을 최대화 하는 방식으로 특징벡터의 차원을 축소하는 기법
- 즉, 한 클래스 내에 분산을 좁게 그리고 여러 클래스간 분산은 크게 해서 그 비율을 크게 만들어 패턴을 축소하게 되면 잘 분류할 수 있겠구나!!
- LDA 판별에 있어서 아래 두 그림은 좋은 그리고 나쁜 클래스 분류에 대해 묘사하고 있다.
rate 값이 클수록 판별하기 좋은데 위 그림 중 왼쪽은 rate값이 크고 오른쪽 그림은 작다.
즉, rate 값이 클수록 판별하기 좋고, rate값이 작으면 판별하기 어렵다.
이렇게 rate값을 크게 만들기 위해 기준선을 잘 잡는게 중요하다. 다음 그림을 보며 이해하자.
위 그림에 보면 BAD 축을을 기준으로 1차원 매핑을 하게 되면 각 클래스를 판별하기 어렵다. 위에 rate 구하는 공식에 클래스간 분산과 클래스내 분산 비율이 작아진것이다. 반대로 GOOD 1차원 축을 보면 rate가 큰것을 예상할 수 있으며, 고로 판별하기 쉬울것이라는 생각이 든다.
====(2개의 클래스 LDA 분석)
2. LDA에서 차원 축소에 판별척도(잘 분류된 정도) 계산방법
LDA에서 좋은 판별 기준을 결정하기 위해 목적함수를 사용한다.(평가함수로도 불린다.)
- objective function = criterion function = 평가함수 / 목적함수
- 이러한 함수의 결과는 LDA 분류의 척도로써 사용된다.
두 가지 목적함수가 있다.
가. 일반적인 목적함수
은 축소된(projected space:사영된 공간) 차원 데이터 y의 평균벡터
은 축소되지 않은(original space: 본래 공간) 차원 데이터 x의 평균벡터
변환 행렬의 전치행렬임
위 척도 J(W)는 클래스간 분산을 고려하지 않고 평균만을 고려했기에 좋은 척도가 아니라고 한다.
이에 Fisher이라는 사람이 다음과 같은 함수를 만듬
나. Fisher's criterion function
여기서 는 클래스내 분산(Within-Class scatter matrix) 임
는 클래스간 분산(Between-Class scatter matrix) 임
은 축소된(projected space:사영된 공간) 차원 데이터의 해당 클래스내 분산
변환 행렬의 전치행렬임
그림과 같이 글래스간 분산도 고려하여 평균차이에 대한 비율로 척도를 계산함
- 이 값이 크면 클수록 좋음
3. 최적 분류를 위한 변환행렬 찾기
그럼 최고 좋은 값을 가지는 즉, 분류를 가장 잘 할수 있는 변환행렬은 어떻게 구할까? 이에 Fisher 선생님이 다음과 같은 공식을 만들었다.
3.1 Fisher’s Linear Discriminant(1936)
최적의 변환 행렬 을 계산하기 위한 수식은 다음과 같다.
- 최적의 변환 행렬을 만들기 위해 Fisher's criterion function 을 미분하여 0의 값을 가지게 수식을 수정한 결과이다. 미분값이 0 이면 기울기가 0라는것이다. 즉 최고점(global maximum point)이라는 점!!
- 여기에 일반화된 고유값 문제 해결을 통해 최적의 변환행렬을 계산해냄
참고
argmax(p(x)) : p(x)를 최대가 되게하는 x 값
max(p(x)) p(x) 중 최대값
argmin(p(x)) : p(x)를 최소가 되게하는 x 값
min(p(x)) : p(x) 중 최소값
4. 2개의 클래스를 LDA 분석하기 - Matlab
step 2: 각 클래스 내 분산 계산
step 3: 클래스 간 분산 계산
step 4: 고유값 및 고유벡터 계산
- 최고의 고유값을 가지는 고유벡터와 원행렬을 곱하면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | X = [4 2;2 4;2 3;3 6;4 4;9 10;6 8;9 5;8 7;10 8]; %입력 데이터 c = [ 1; 1; 1; 1; 1; 2; 2; 2; 2; 2;]; %입력 데이터 그룹 분류 c1 = X(find(c==1),:) %클래스 1에 해당하는 입력 데이터 매핑 c2 = X(find(c==2),:) %클래스 2에 해당하는 입력 데이터 매핑 figure; %그림 그리자 hold on; %잡고 있으려므나~~ p1 = plot(c1(:,1), c1(:,2), 'ro', 'markersize',10, 'linewidth', 3); %클래스 1 좌표 찍으렴 p2 = plot(c2(:,1), c2(:,2), 'go', 'markersize',10, 'linewidth', 3) %클래스 2 좌표 찍으렴 xlim([0 11]) %그래프 x의 좌표를 범위를 0-11까지 늘리자 ylim([0 11]) %그래프 y의 좌표를 범위를 0-11까지 늘리자 classes = max(c) %클래스가 몇개인지 보자구웃 mu_total = mean(X) %전체 평균 계산 mu = [ mean(c1); mean(c2) ] %각 클래스 평균 계산 Sw = (X - mu(c,:))'*(X - mu(c,:)) %클래스 내 분산 계산 Sb = (ones(classes,1) * mu_total - mu)' * (ones(classes,1) * mu_total - mu) %클래스간 분산 계산 [V, D] = eig(Sw\Sb) %고유값(V) 및 고유벡터(D) % sort eigenvectors desc [D, i] = sort(diag(D), 'descend'); %고유값 정렬 V = V(:,i); % draw LD lines scale = 5 pc1 = line([mu_total(1) - scale * V(1,1) mu_total(1) + scale * V(1,1)], [mu_total(2) - scale * V(2,1) mu_total(2) + scale * V(2,1)]); set(pc1, 'color', [1 0 0], 'linestyle', '--')%가장 큰 고유값을 가지는 선형판별 축 그리자 scale = 5 pc2 = line([mu_total(1) - scale * V(1,2) mu_total(1) + scale * V(1,2)], [mu_total(2) - scale * V(2,2) mu_total(2) + scale * V(2,2)]); set(pc2, 'color', [0 1 0], 'linestyle', '--')%두번째 고유값을 가지는 선형판별 축 그리자 |
보면 빨강색 선이 가장 좋은 LD 축이 되고 녹색이 나쁜 LD 축이 된다.
그럼 가장 좋은 LD1축으로 투영을 시켜 보자 . 위 코드 상태에서 바로 아래와 같이 명령어를 입력하면 된다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | %First shift the data to the new center Xm = bsxfun(@minus, X, mu_total) %원래 데이터 평균 빼기 %then calculate the projection and reconstruction: z = Xm*V(:,1) %차원 축소 % and reconstruct it p = z*V(:,1)' %LD 축에 데이터 맞추기 위해 재구성 p = bsxfun(@plus, p, mu_total) %재구성된 데이터 평균더하기 %plotting it: % delete old plots delete(p1);delete(p2); % 이전 그려진 plot 데이터 삭제 y1 = p(find(c==1),:) %클래스 1 데이터 y1에 입력 y2 = p(find(c==2),:)%클래스 2 데이터 y2에 입력 p1 = plot(y1(:,1),y1(:,2),'ro', 'markersize', 10, 'linewidth', 3); p2 = plot(y2(:,1), y2(:,2),'go', 'markersize', 10, 'linewidth', 3); %찍어라 얍얍 %result - 원래 1차원으로 축소한 결과 result0 = X*V(:,1); % PDF그리기 위해 ... result1 = X*V(:,2); |
위 예제는 2개의 클래스를 가지고 LDA 분석하는 방법들이다.
[1] http://www.di.univr.it/documenti/OccorrenzaIns/matdid/matdid437773.pdf
[2] http://www.bytefish.de/blog/pca_lda_with_gnu_octave/
'PatternRecognition' 카테고리의 다른 글
Wilk's Lambda (2) | 2014.12.15 |
---|---|
Linear Discriminant Analysis(LDA) - C-Classes (0) | 2014.06.02 |
Neural Networks: Data normalization (0) | 2014.04.25 |
The Basic Artificial Neuron: Bias neuron(Backpropagation) (3) | 2014.04.23 |
기초 통계(Statistic) (0) | 2014.04.14 |
■ XML: A fundamental concept
XML(eXtensible Markup Language): 확장 가능한 마크업 언어(Markup Language)라고 한다.
Markup Language: 문서의 논리적 구조와 배치 양식에 대한 정보를 표현하는 언어라고 한다.
- 이러한 정보들은 Meta Language로 구성되어진다.
Meta Language: 메타 데이터(Meta Data)로 구성된 언어라고 볼 수 있음
- Meta Data: 속성 정보라고도 함 (일정한 규칙 따름)
- 규칙을 알면 해당 데이터에 효율적으로 접근할 수 있음
XML - Markup Language - Meta Language
즉 속성 정보를 논리적 구조로 배치한 언어를 Markup Language라고 하며, 이것을 확장가능하도록 한 언어를 XML이라고 정의할 수 있다.
XML을 사용해야 하는 이유는 다음 사이트에 잘 나와 있다.
http://office.microsoft.com/ko-kr/training/RZ001130477.aspx?section=2
현재 우리는 HTML(Hypertext Markup Language)로 짜여진 문서를 웹브라우저를 통해 보고 있다. 현재 보고 있는 글도 HTML로 짜여져서 각종 웹브라우저에서 볼 수 있는 것이다. 즉 하나의 표준으로 다른 기기간 동일한 화면을 표현하는 것이다.
표준은 다른 기기 다른 프로그램에서 동일한 입력과 출력을 가지는 것을 목표로 한다. 즉 XML 또한 표준이다. 오늘날 기업에서는 다양한 프로그램, 데이터베이스에서 수 많은 데이터를 받고 처리 한다. 이 과정에서 시스템간 기기간 다른 데이터 형식으로 인해 데이터의 관리가 어려워 졌다. 이러한 점은 XML이 등장하게 된 배경 중 하나이다.
즉 우리는 데이터의 입출력을 하나의 표준을 사용함으로써 다른 프로그램과 시스템간 동일한 자료 구조를 공유할 수 있다. 이와 같은 특징은 효과적인 데이터 관리를 할 수 있는 장점을 가지게 된다.
XML의 원래 용도
- World Wide Web를 통해 데이터를 전송하기 위해(www)
XML의 기본구성
- XML 데이터 파일, XML 스키마 및 XML 변환