You are on page 1of 35

문제해결을 위한 공학 프로그래밍

4장. Matrix Structure


Outline
1. Matrix Overview
2. Matrix Operation
• Java Native Operation
• JAMA Package
3. Table Structure
4. AHP overview
• AHP overview
• Case study 1: AHP (Supplier Selection)
5. Markov Matrix
• Markov Matrix overview
• Case study 2: Markov matrix (Identifying key resource)

문제해결을 위한 공학 프로그래밍 2
Matrix Overview
 How is data saved in 2D array?

Matrix A
0 1 2 3 4

0 0.1 1.2 2.3 3.7 4.5 • What is dimension of Matrix A ?


• A[0][3] = 3.7
1 2.1 4.2 5.2 1.1 6.1
• A[2][1] = 7.9
2 4.1 7.9 3.3 3.2 3.4
• A[5][2] = ?
3
0.3 0.9 1.3 4.2 3.5
on
heats alien
l l I
4 3.3 2.9 2.2 7.9 8.9 is l l aipans again
I l
an Tain
l l I Tanis
l
了airy
aim
airports
l l

II
문제해결을 위한 공학 프로그래밍 3
Matrix Overview
 The layout of a two-dimensional Java arrays

Array elements that refers to


another array creates a
multidimensional array.

Image source : G. Gundersen & T. Steihaug, Data Structures in Java for Matrix Computation

문제해결을 위한 공학 프로그래밍 4
Matrix Overview
 Create a Matrix in Java

Creating a matrix (object of array 2D) Setting matrix value

아서 까지
Creating and directly initializing matrix value oomf번도는
알고리즘
크기의행렬
pact crooner tomin번
mxn개의 값들을모두
0으로 초기화

Accessing matrix value

문제해결을 위한 공학 프로그래밍 5
Matrix Operation
a n새행렬
 Matrix addition b n새행렬  Matrix Transpose
atb
t

 Matrix Multiplication
re
맒턺
at mxo

같아야
l it

n
oi 2
j2
aint 弘列as ban

문제해결을 위한 공학 프로그래밍 6
Matrix Operation
 Frobenius Norm example

Loop-order (i,j): Loop-order (j,i):

double s = 0; double s = 0;
double[] array = new double[m][n]; double[] array = new double[m][n];
for(int i = 0; i<m; i++){ for(int j = 0;j<n;j++){
for(int j = 0; j<n; j++){ for(int i = 0;i<m; i++){
s += array[i][j]; s+=array[i][j];
} }
} }

燕簽
爲 ㅃㅃ
What is the difference ?

i 에서작업하는게
鬱貞
문제해결을 위한 공학 프로그래밍 7
Matrix Operation

Basic observation:
Accessing the consecutive
elements in a row will be
faster then accessing
consecutive elements
in a column.

Image source : G. Gundersen & T. Steihaug, Data Structures in Java for Matrix Computation

문제해결을 위한 공학 프로그래밍 8
JAMA Packages
 A basic linear algebra package implemented in Java.
 It provides user-level classes for constructing and manipulating real dense ma
trices.
 It is intended to serve as the standard matrix class for Java.
 JAMA packages is already optimized.

문제해결을 위한 공학 프로그래밍 9
Table Structure
How to make table structure in Java
1. Matrix Representation (Array 2D)
2. Create your own table object
3. Using Java API, JTable

문제해결을 위한 공학 프로그래밍 10
(1) Create your own table object
 Read data from CSV File
country.csv

output

문제해결을 위한 공학 프로그래밍 11
(3) JTable
import javax.swing.JTable

Setting table header

Setting data table in a 2D array

Create table with data

Setting table display

문제해결을 위한 공학 프로그래밍 12
Analytic Hierarchy Process (AHP)

o Analytic Hierarchy Process (AHP), introduced


by Thomas Saaty (1980) is a method on
multi criteria decision making (MCDM).

o The AHP had been applied for Decision


Support System (DSS).

o This algorithm involves both subjective


human judgments and objective evaluation

o Important term in AHP: criteria or factors,


weight of important, alternatives or choice
and goal.
Image source : https://en.wikipedia.org/wiki/Analytic_hierarchy_process

문제해결을 위한 공학 프로그래밍 13
Some AHP Applications

문제해결을 위한 공학 프로그래밍 14
How AHP works
 It is a method to derive ratio scales from paired comparisons. The inp
ut can be obtained from actual measurement such as price, weight etc
., or from subjective opinion such as satisfaction feelings and preferen
ce.
 AHP allows some small inconsistency in judgment because human is
not always consistent.
 Pair-wise Comparison
E.g. John try to choose his the most favourite fruit

문제해결을 위한 공학 프로그래밍 15
How AHP works
 Pair-wise comparison
Now suppose you have three choices of fruits.
Then the pair wise comparison goes as the following

여러개를 비교할 때
한꺼번에 비교하면
어려워
보기
비교해
2개씩 일단

문제해결을 위한 공학 프로그래밍 16
How AHP works
 Making a Comparison Matrix

Because we have three comparisons, thus we have 3 by 3 matrix


 The diagonal elements of the matrix are always 1 and we only need to
fill up the upper triangular matrix.

문제해결을 위한 공학 프로그래밍 17
How the AHP works
 Making a Comparison Matrix
Because we have three comparisons, thus we have 3 by 3 matrix
 The diagonal elements of the matrix are always 1 and we only need to
fill up the upper triangular matrix.
 How to fill up the upper triangular matrix is using the following rules
1. If the judgment value is on the left side of 1, we put the actual judgment value

5
3 77

it

문제해결을 위한 공학 프로그래밍 18
How AHP works
 Making Comparison Matrix
Because we have three comparisons, thus we have 3 by 3 matrix
 The diagonal elements of the matrix are always 1 and we only need to
fill up the upper triangular matrix.
 How to fill up the upper triangular matrix is using the following rules
1. If the judgment value is on the left side of 1, we put the actual judgment value
2. If the judgment value is on the right side of 1, we put the reciprocal value

Reciprocal values,

문제해결을 위한 공학 프로그래밍 19
How AHP works
 How to compute Eigen Vector and Eigen Value
Computing Eigen Vector by using approximation

1. Suppose we have 3 by 3 reciprocal matrix from paired comparison


3. Then we divide each element of the matrix with
the sum of its column

2. We sum each column of the reciprocal matrix to get

r 4. The normalized principal Eigen vector can be obtained


by averaging across the rows

apple

Ja
or ve n banana 각과일을
정도
다 I이되게하기위해 좋아하는
carry
옧荷 훰 一
senile exbanana젤좋아함
terri 3
seen
문제해결을 위한 공학 프로그래밍 20
How AHP works
 Priority Vector

The priority vector shows relative weights among the things that we compare. In our example above,
Apple is 28.28%, Banana is 64.34% and Cherry is 7.38%. So, John most preferable fruit is Banana,
followed by Apple and Cheery

We know not only about ranking but also ratio, we can say that John likes banana 2.27 (=64.34/28.28)
times more than apple and he also like banana so much 8.72 (=64.34/7.38) times more than cheery.

 Principal Eigen Value


we can also check irritate 지속성과관련
the consistency.
Principal Eigen value is obtained from the summation of products between each element
of Eigen vector and the sum of columns of the reciprocal matrix

qooaToqoooqan.ir
정도
좋아하는정도 좋아하는 좋아하는정도

문제해결을 위한 공학 프로그래밍 21
How AHP works
 Consistency Index and Consistency Ratio
1. What is the meaning that our opinion is consistent?
2. How do we measure the consistency of subjective judgment?

 Let us look again on John’s judgment that we discussed in the previous section.
Is John judgment consistent or not?

First he prefers Banana to Apple. Thus we say that for John, Banana has greater value than Apple.
We write it as B > A .
Next, he prefers Apple to Cherry. For him, Apple has greater value than Cherry. We write it as A > C
Since B > A and A > C , logically, we hope that B > C or Banana must be preferable than Cherry.
This logic of preference is called transitive property. If John answers in the last comparison is transitive
(that he like Banana more than Cherry), then his judgment is consistent.
On the contrary, if John prefers Cherry to Banana then his answer is inconsistent.
Thus consistency is closely related to the transitive property
문제해결을 위한 공학 프로그래밍 22
How AHP works
 Then he gave a measure of consistency, called Consistency Index (CI)
as deviation or degree of consistency using the following formula

訛哥

 Random Consistency Index (RI)


he 랜덤하게 골랐을때

A B
BK
410 1 작으면 engineer AHP적용 가능 A가
old
Thus, John’s subjective evaluation about his fruit preference is consistent
일관성
판별
는말이X
일관성X

문제해결을 위한 공학 프로그래밍 23
Examples

Paired comparison matrix level 1 with respect to the goal


A를 B 3만큼더중요하게
보다
생각함이
들로싼값을
각각의sum
sfs 더한 釧女
j ex揷 堀 墟瀏
i
를A보다덜중요하게생각t T7
D

1.59x57.39
4.34 29.13
Nitish 4consistant 하다
13.33x as
20.00x4.45
문제해결을 위한 공학 프로그래밍 24
Examples

Paired comparison matrix level 1 with respect to the goal

門斟 크기
차이가 때문에
개만
큰값두 가능 비교해도
consistent 평가

문제해결을 위한 공학 프로그래밍 25
Examples

0
Paired comparison matrix level 2 with respect to Factor A 관점에서

Paired comparison matrix level 2 with respect to Factor B 관점에서

We can do the same for paired comparison with respect to Factor C and D. However, the weight of
factor C and D are very small (look at Table 9 again, they are only about 9% and 5% respectively),
therefore we can assume the effect of leaving them out from further consideration is negligible.
We ignore these two weights as set them as zero.

문제해결을 위한 공학 프로그래밍 26
Examples

o
더 하면 I
son
A B

照鬱
Overall composite weight of the alternatives

ii

문제해결을 위한 공학 프로그래밍 27
Case Study 1
 Vendor Selection for Service Sector Industry
Choose the best supplier among the suppliers

Goal Supplier Selection

Criteria Cost P. Quality Delivery Reputation

Supplier A Supplier B Supplier C Supplier D Supplier E

Alternatives

문제해결을 위한 공학 프로그래밍 28
Markov Matrix
 A nxn matrix is called a Markov matrix if all entries are non-negative an
d the sum of each column vector is equal to 1.

e
 Markov matrices are also called stochastic matrices
 Java code to check whether it is Markov matrix or not

문제해결을 위한 공학 프로그래밍 29
Markov Matrix Example
항상 이전의 것에만 영향을 받는다
Currently, Pepsi owns 55% and Coke owns 45% of market share. Following are the conclusions drawn out by the market research co
mpany:
P(P->P) : Probability of a customer staying with the brand Pepsi over a month = 0.7
P(P->C) : Probability of a customer switching from Pepsi to Coke over a month = 0.3
P(C->C) : Probability of a customer staying with the brand Coke over a month = 0.9
P(C->P) : Probability of a customer switching from Coke to Pepsi over a month = 0.1

厚fi 펩시로갈아탈확률

The diagram simply shows the transitions and the current market share. Now, if we want to calculate the market share after a month,
we need to do following calculations :
Market share (t+1) of Pepsi = Current market Share of Pepsi * P(P->P) + Current market Share of Coke * P(C->P)
Market share (t+1) of Coke = Current market Share of Coke * P(C->C) + Current market Share of Pepsi * P(P->C)
These calculations can be simply done by looking at the following matrix multiplication :
Current State X Transition Matrix = Final State

unify nerve
As we can see clearly see that Pepsi, although has a higher market share now, will have a lower market share after one month. This s
imple calculation is called Markov chain. If the transition matrix does not change with time, we can predict the market share at any futu
re time point. Let’s make the same calculation for 2 months later.

현재
나중에어떻게될거냐
4 x h
as a
문제해결을 위한 공학 프로그래밍 30
Case Study 2
 Idea: Links as votes
다른 페이지들이 많이 Link참조 해농
 Page is more important if it has more links
4
시이트는 중요도
 Think of in-links as votes 중요도가 9인 페이지가
Link해놓은
 Are all in-links are equal? 9
사이트도 중요도

Links from important pages count more

문제해결을 위한 공학 프로그래밍 31
Case Study
 Google PageRank

𝑟𝑖
𝑟𝑗 = σ𝑖→𝑗
𝑑𝑖 I 4
𝑟𝑖 = importance score of page i
𝑑𝑖 = number of out-links rj = ri /3+rk /4
i에서 J로 가는 링크가 있을때 crossover
페이지의 중요도는 현재의점수에
j
링크건페이지 i들의
if 의합
재지닌점수와 링크전페이지들로인해 더해지는점수에
각각 얼마만큼의 가중치를 둘것인가
재의점수가 더중요 p감소
컷 더해지는점수가더 중요 p증가𝑟 1
𝑟𝑗 = 𝛽 ∙ σ𝑖→𝑗 𝑑𝑖 + 1 − 𝛽 ∙ 𝑛 0 ≤ β ≤ 1, in practice the best value of β = 0.8 – 0.9
𝑖 없지원에
urn 현남 E점F에 𝑛 𝑖𝑠 𝑛𝑢𝑚𝑏𝑒𝑟 𝑜𝑓 𝑛𝑜𝑑𝑒
얼마만큼의 가중치를

ㄴcf
둘거냐
지닌점수 현재의것이 얼마나중요한지에 따라 p값조정
여기서
에 더해서계산

문제해결을 위한 공학 프로그래밍 32
in适

t=1 현재B값
E

前지닌값
t=2
PR(C) = 0.18*9.1 + 0.82*31 = 27.058
區啖 T의 변한값
1B의
연결관계를 Matrix로 나타내기 1mi

문제해결을 위한 공학 프로그래밍 33
Case Study
페빼주이주 가능
 Identifying key resource in business process using f-PageRank
2
Finding important resource (machine or human) in business process
case
case activity
activity Performer
performer

case
case11 activity
activityAA John
John John Sue
case
case12 activity
activityBA Mike
John
case
case13 activity
activityCA John
Sue
case
case13 activity
activityDB Pete
Carol
case
case21 activity
activityAB John
Mike
case
case21 activity
activityCC Mike
John
case
case22 activity
activityBC John
Mike
case
case24 activity
activityDA Pete
Sue Mike
case
case32 activity
activityAB Sue
John
case
case32 activity
activityBD Carol
Pete
case
case35 activity
activityCA Sue
Sue Clare
case
case34 activity
activityDC Pete
Carol
case
case41 activity
activityAD Sue
Pete
case
case43 activity
activityCC Carol
Sue
case
case43 activity
activityBD Sue
Pete
case
case44 activity
activityDB Pete
Sue
Pete Carol
case
case55 activity
activityAE Sue
Clare Fig. 1. Sociogram based on transfer of work
case
case55 activity
activityED Clare
Clare
case
case54 activity
activityDD Clare
Pete

문제해결을 위한 공학 프로그래밍 34
Case Study
 F-PageRank Example Markov matrix

y a m [1/N]NxN A
y
y 2/3 4/7 0 1/3 1/3 1/3 y 0.60 0.52 0.07
중복가능케야
0.8 a 1/3 0 0 + 0.2 1/3 1/3 1/3 = a 0.33 0.07 0.07
0 3/7 1 1/3 1/3 1/3 m 0.07 0.41 0.87
m
a m 𝑟 (𝑡+1) = 𝐴 ∙ 𝑟 𝑡 CAN곱해지는 매트릭스
𝑟0 𝑟1 𝑟2 𝑟3 𝑟𝑛 no ag.in중
y 1/3 0.39 0.34 0.33 0.31 뭐가젤 중요한지
rt A a = ... 알수 있음
1/3 0.15 0.17 0.16 0.15
m A계속 곱하는이유

渗了 Aire 1/3
ch
0.45
Ll
0.47
een
0.51
th
0.53
i페이지를 한
번 검색
것에서 멈추지 않고
0.39 51.060 5'0.52
tf 0,07 XA XA XA XA 계속 시행되기 때문에
心 作 0.390.33 0,150.07 0,450.07 A를 곱해야
최종중요도를알수있음

문제해결을 위한 공학 프로그래밍 35

You might also like