Starting with a pairwise comparison matrix A=[aij] i,j=1…n, where aij>=0, aii = 1, and aij =1/aji, where some elements aij are missing, it has been suggested that optimal completion of the missing entries can be found by minimizing λmax(x) with respect to the missing entries x=(x1,x2,…,xk), where λmax is the largest eigenvalue of A(x). The solution is found by series of iterations minxr(λmax(xr)) where all missing entries are held at fixed values except for xr r=1…k, whithin each series. In the first series all missing variables are set to 1. The following code successfully finds the minimum λmax for each step and is illustrated for the missing entry x1 =A[2,3] after all other missing entries are replaced by 1 in A:
void eb(todo, p, lmax, g, H)
{
A=st_matrix("A")
A[2,3]=p[1] +ln(p[1])-ln(p[1])
A[3,2]=1/p[1]
ev=eigenvalues(A)
lmax=abs(ev[1,1])
}
S = optimize_init()
optimize_init_which(S,"min")
optimize_init_evaluator(S, &eb())
optimize_init_params(S, 1)
p = optimize(S)
However, I need to do this for all k missing entries in A, and then again in series until each of the x'es converge. This means I need to run a loop witin a loop. I don’t seem to get any loop working in Mata, and when I try to loop this in Stata where Mata is called to do the estimation, there are several challenges. One is how to let A[i,j] loop over all missing enties, considering that Mata does not use macros. Another is the fact that the do-file in Stata will end whenever there is a change from the Mata mode back to Stata mode, due to the command "end" in Mata which is read "exit" in the do-file. Also, I need to be able to update matrix A, and (ideally also) the initial parameter with each single estimation. Below I post an example matrix convenient for writing the code. Does anybody have a suggestion on how I should proceed?
void eb(todo, p, lmax, g, H)
{
A=st_matrix("A")
A[2,3]=p[1] +ln(p[1])-ln(p[1])
A[3,2]=1/p[1]
ev=eigenvalues(A)
lmax=abs(ev[1,1])
}
S = optimize_init()
optimize_init_which(S,"min")
optimize_init_evaluator(S, &eb())
optimize_init_params(S, 1)
p = optimize(S)
However, I need to do this for all k missing entries in A, and then again in series until each of the x'es converge. This means I need to run a loop witin a loop. I don’t seem to get any loop working in Mata, and when I try to loop this in Stata where Mata is called to do the estimation, there are several challenges. One is how to let A[i,j] loop over all missing enties, considering that Mata does not use macros. Another is the fact that the do-file in Stata will end whenever there is a change from the Mata mode back to Stata mode, due to the command "end" in Mata which is read "exit" in the do-file. Also, I need to be able to update matrix A, and (ideally also) the initial parameter with each single estimation. Below I post an example matrix convenient for writing the code. Does anybody have a suggestion on how I should proceed?
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input float(var1 var2 var3) byte(var4 var5) float(var6 var7 var8) 1 5 3 7 6 6 .33 .25 .2 1 . 5 . 3 . .14 .33 . 1 . 3 . 6 . .14 .2 . 1 . .25 . .13 .17 . .33 . 1 . .2 . .17 .33 . 4 . 1 . .17 3 . .17 . 5 . 1 . 4 7 . 8 . 6 . 1 end
Comment