Tarmo,

Thanks!  I added macivf for a fixed version of maciv, with corresponding
cr and crf.

I also put in your errt and errt_auto verbs.  Now you can compare 

(%+/) power cpm            NB. and 
(%+/) power errt_auto cpm  NB. (not much difference)

It is mildly illuminating to run

errt errt_auto cpm

Here's the code (I really should have put it under revision control and
made it look nicer, but I hope it and its comments are readable)

Bill
......................................................................

NB. A program to apply Saaty's method in an interactive fashion.
NB. according to the link in http://actifeld.com/A%20Possible%20Method.doc

NB. 2006-03-03
NB. John Randall developed the basic algorithm on the J Programming Forum
NB. Raul Miller, Tarmo Veskioja, Devon McCormick, and Roger Hui contributed to 
the dialog
NB. Bill Harris put a few other pieces on.

NB. The steps:
NB. Define the Client Preference Matrix as described on p. 6 of that article
NB. Run (%+/)power on that matrix to find the principle eigenvector.
NB. Run cr to calculate the Consistency Ratio; if it is much in excess of
NB.   0.1, the judgments used to create the CPM are probably too random.
NB. Create preference matrices for each of the alternatives on each of 
NB.   the dimensions used in the CPM.  Calculate the principal eigenvectors
NB.   and consistency ratio for each.
NB. Create the Option Performance Matrix by assembling all the principal 
NB.   eigenvectors for the preference matrices.
NB. Multiply OPM time CVV to get the Value For Money vector.  

NB. Calculate principal eigenvectors of the matrix cpm by
NB.   (%+/) power cpm

NB. Calculate the principal eigenvalue of the matrix cpm by
NB.   ev cpm

NB. Calculate the relative consistency ratio of the matrix cpm by
NB.   cr cpm 

NB. The VFM shows in each position the relative preference the decision-maker
NB.   has shown for that alternative: OPM * CVV = VFM

NB. If the Option Performance Matrix is
NB. opm=: |:a,b,c,:d  
NB. where a, b, c, and d are the principal eigenvectors of each option matrix

NB. then 
NB. (%/+)opm mp cpm 
NB. is the Value For Money (VFM) matrix, giving the relative 
NB. values of each alternative

NB. The power method for calculating the principal eigenvector
mp=:+/ . *
normalize=:%(>./@:|)
iterate=:normalize@:mp
init=:[: ? # # 0:
power=:13 : 'y.&iterate^:_ init y.'


NB. Calculate the principal eigenvalue
NB. Postmultiply the current principal eigenvector by the matrix
NB. Divide that vector (unnormalized) by the principal eigenvector
NB. See p. 258 of Kincaid and Cheney's Numerical Analysis 3rd edition
cureigenvec =: (%+/) @: power
neweigenvec =: mp cureigenvec
ev=: [: {. neweigenvec % cureigenvec

NB. Calculate the absolute consistency index
ci =: (ev - #) % <: @: #

NB. .........................................................................
NB. Random Saaty matrices for testing
NB. st is Tarmo Veskioja's verb (e.g., st 4)
NB. st1 is Roger Hui's faster but more space-intensive equivalent
saaty_scale =: \:~ }. (,%)~ >:i.9
str =: 13 : '( =/~ i.#y.) + (y.*bd ) + |: (bd=. >/~ i.#y.) * %y.'
saaty_rand =: 13 : '(y. , y.) $ saaty_scale {~ ? (#saaty_scale) #~ *: y.'
st =: 13 : 'str saaty_rand y.'        NB. st 4
st1=: 3 : 0
 i=. 1+(,~y.) [EMAIL PROTECTED] #saaty_scale
 b=. >/~i.y.
 ((b*i) + |:b*i+#saaty_scale) { 1,(,%) saaty_scale
)

NB. Calculate the consistency ratio
NB. MACI is the mean absolute consistency index of random matrices
am=: +/%#
maci =: 13 : 'am ci"2 st1"0 (x. # y.)'
maci_precomputed =: 1000 maci"0 (3+i.8)   NB. Tarmo claims it's exactly 0.5245 
for 3

index =: <:^:3 & #
macivf =: 13 : '(index y.) { maci_precomputed' NB. Get the value of 
maciv =: 13 : '(index y.) { 1000 maci"0 (3 + i.8)'
crf=: ci % macivf  NB. fixed values for speed at runtime
cr=: ci % maciv

NB. Calculate error weights matrix from Tarmo Veskioja
NB. errt cpm gives the inconsistencies in the comparisons
NB. A value of 1 shows consistency.
errt =: 13 : '^ ((y * n) + ys +/ (- ys=. +/ y=. ^. y.)) % (2 - n=. #y.)'        
NB. Saaty matrix with comparison values corrected
NB. If people aren't available to correct the comparison matrix, then
NB. errt_auto cpm 
NB. will produce a new, consistent matrix.
NB. Try errt errt_auto cpm
errt_auto =: 13 : 'y. * ( (#y.) % _2 + #y.) %: errt y.'         NB. errt_auto 
table


NB. Test matrices from Geoff Coyle's paper referenced above:
NB. peigen s/b 0.232,0.402,0.061,0.305, cr of 0.055
cpm=: >(1,(%3),5, 1);(3,1,5,1);((%5),(%5),1,(%5));(1,1,5,1)

NB. peigen s/b 0.751,0.178,0.071 w/ cr of 0.072
exp=: >(1,5,9);((%5),1,3);((%9),(%3),1) NB. Expenses

NB. peigen s/b 0.480,0.406,0.114 w/ cr of 0.026
und=: >(1,1,5);(1,1,3);((%5),(%3),1) NB. "Understandability

NB. peigen s/b 0.077,0.231,0.692 w/ cr of 0
rod=: >(1,(%3),%9);(3,1,%3);9 3 1 NB. "Replication of detail", p. 7

NB. peigen s/b 0.066,0.615,0.319 w/ cr of 0
pod=: >(1,(%9),(%5));(9,1,2);(5,(%2),1) NB. Prediction of dynamics

......................................................................
-- 
Bill Harris                      http://facilitatedsystems.com/weblog/
Facilitated Systems                              Everett, WA 98208 USA
http://facilitatedsystems.com/                  phone: +1 425 337-5541

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to