zfaigl

20 Reputation

6 Badges

10 years, 253 days

MaplePrimes Activity


These are replies submitted by zfaigl

Thank you, I learnt it now. I have another problem. I try to analyze the distortion of methods in different cases for the X input Matrix. For some X , the distance function (i.e., abs( D(f2)-D(f1) )) contains dirac deltas.

In the following example, I only modified X to a new Matrix (besides adding the previous recommended modification). With this X I experienced that the numerical integration returns quite soon, but only with symbolic value, and I think that it is caused by the "dirac delta" part of the function. 

In general, how should we deal with this problem? I would like to have some distortion value, but maybe skipping out in the integration those x values where the value of the function to integrate is "infinite".

Can we find these x points, and integrate the function skipping out these points? Or what is a good treatment of this problem?

BR,

Zoltan Faigl



with('LinearAlgebra'):Testzero:= proc(O) evalb(simplify(O)=0) end:

safeDivide:=(x,y)->limit(x/b,b=y):

sumNorm:=proc(X)
local k,l,xnorm,N,M,output;

if (typematch(X,Matrix)) then
        N,M:=Dimensions(X);
        for k to M do:
                for l to N do:
                        xnorm[l,k]:=safeDivide(X[l,k],add(X[i,k],i=1..N));
                od;
        od;
        output:=Matrix(N,M,xnorm)

elif (typematch(X,Vector)) then
        N:=Dimensions(X);
        for l to N do:
                xnorm[l]:=safeDivide(X[l],add(X[i],i=1..N));
        od;
        output:=Vector(N,xnorm)
end if;
output;
end proc:

Let's compare three score aggregation method. All are f:=(X::Matrix,C::Vector) -> TerminalScores::Vector

 

1st method: simple weighted sum

simpleWeightedSum:=proc(X::Matrix,C::Vector)
        local i,j,k,l,t,N,M;
        N,M:=Dimensions(X);

        # simple weighted sum
        for j from 1 to N do:
                t[j]:=add(C[i]*X[j,i],i=1..M);
        od;
        sumNorm(Vector(N,t));
end proc:

2nd method: distance to ideal alternative

dia:=proc(X::Matrix,C::Vector)
        local i,j,k,l,t,v,Dpos,Dneg,Dposmin,Dnegmax,N,M;
        N,M:=Dimensions(X);

        #DiA
        for i to M do:
                for j to N do:
                        v[j,i]:=C[i]*X[j,i];
                od;
        od;
        i,j:='i','j';
        for j to N do:
                Dpos[j]:=add(  abs(v[j,i] - max(seq(v[k,i],k=1..N)) ) ,i=1..M );
                Dneg[j]:=add(  abs(v[j,i] - min(seq(v[k,i],k=1..N)) ) ,i=1..M );
        od;
        j,k:='j','k';
        Dposmin:=min(seq(Dpos[j],j=1..N));
        Dnegmax:=max(seq(Dneg[j],j=1..N));
        j:='j';
        for j to N do:
                t[j]:=sqrt((Dpos[j]-Dposmin)^2+(Dneg[j]-Dnegmax)^2);                
        od;
        Vector(N,1)-sumNorm(Vector(N,t));
        #Vector(N,t);
end proc:

3rd method:topsis

topsis:=proc(X::Matrix,C::Vector)
        local i,j,t,v,Dpos,Dneg,N,M;
        N,M:=Dimensions(X);

        #TOPSIS
        for i to M do:
                for j to N do:
                        v[j,i]:=C[i]*X[j,i];
                od;
        od;
        i,j:='i','j';
        for j to N do:
                Dpos[j]:= sqrt(add( (v[j,i] - max( seq( v[j,i],j=1..N ) ))^2, i=1..M));
                Dneg[j]:= sqrt(add( (v[j,i] - min( seq( v[j,i],j=1..N ) ))^2, i=1..M));
        od;
        j:='j';
        for j to N do:
                t[j]:= safeDivide(Dneg[j],(Dneg[j]+Dpos[j]));
        od;
        #Vector(N,t);
        sumNorm(Vector(N,t));        
end proc:

Number of methods to compare

numOfMethods=3;

1st input parameter of methods

X:=Matrix(3,3,<<t,0.5,0.5>|<0.5,0.5,0.5>|<0.5,0.5,0.5>>);

2nd input parameter of methods

C:=Vector(3,1/3);

I want to analyze the difference between the methods, by calculating :

   distortion1:=int(abs(terminalScore[1]_dia - terminalScore[1]_simpleWeightedSum, t=0..1), and

   distortion2:=int(abs(terminalScore[1]_topsis - terminalScore[1]_simpleWeightedSum, t=0..1)

Here I create a vector of the three decision method functions

createFunctionVector:=proc(t)
        global X,C,numOfMethods;
        local f;
        f[1]:=unapply(simpleWeightedSum(X,C),t);
        f[2]:=unapply(dia(X,C),t);
        f[3]:=unapply(topsis(X,C),t);
        Vector(3,i->f[i](t)[1]);
end proc:

termScores is the Vector of decision method functions

termScores:=createFunctionVector(t):

Now I create a procedure to differentiate the decision method functions

fDiffx:=proc(X,methodList)  # differentiate functions based on t
        local i,tmp;
        for i in methodList do:
                tmp[i]:=diff(simplify(convert(X[i],rational)),t) assuming t>0, t<1;
        od;
        Vector(3,i->tmp[i]);
end proc:

call the procedure to differentiate decision method function 1 and 3, i.e., simpleWeightedSum and Topsis

diffTermScores:=fDiffx(termScores,[1,2,3]): # OK for 1:simpleWeightedSum and 3:topsis

ERROR happens when I try to differentiate the dia function --> How to solve this?

fDiffx(termScores,2): # not OK for 2: dia

Now I look the "distance" of method topsis from simpleWeightedSum

distanceOfMethods:=Vector(2,<abs(diffTermScores[2]-diffTermScores[1]),abs(diffTermScores[3]-diffTermScores[1])>):

Before integration I replace undefined values to 0

tmp[1]:=unapply(subs(undefined=0,distanceOfMethods[1]),t):

tmp[2]:=unapply(subs(undefined=0,distanceOfMethods[2]),t):

I try to integrate (at least numerically) the distance of two methods to get the distortion of Topsis compared to simple weighted sum

distortion:=evalf(Int(tmp[1],0.0..1,epsilon=1e-4,digits=10)); # integration did not work for tmp[1]

distortion:=evalf(Int(tmp[2],0.0..1,epsilon=1e-4,digits=10)); # integration worked for tmp[2]

tmp[1](t):

plot(tmp[1](t),t=0.0..1);

plot(tmp[2](t),t=0.0..1);

 

 

 

 

question_differentia.mw

Download question_differentia.mw

Thanks, 'satisfies' worked. In the last question, maybe the answer is that Matrix can not have RealRange property, just an element of the Matrix can have this property.  

Thanks, 'satisfies' worked. In the last question, maybe the answer is that Matrix can not have RealRange property, just an element of the Matrix can have this property.  

@zfaigl :

I realized that if I remove the abs() operations from the dia procedure, then Maple finds its derivate. But I need the absolute value. How to resolve this issue, and why abs() caused the problem?

Best regards,

Zoltán

@zfaigl :

I realized that if I remove the abs() operations from the dia procedure, then Maple finds its derivate. But I need the absolute value. How to resolve this issue, and why abs() caused the problem?

Best regards,

Zoltán

@zfaigl

In the previous comment , in topsis the safeDivide function was the following:

> safeDivide:=(x,y)->limit(x/b,b=y);

@zfaigl

In the previous comment , in topsis the safeDivide function was the following:

> safeDivide:=(x,y)->limit(x/b,b=y);

I would like to give some additional information. A similar algorithm to 'dia' called 'topsis' works fine. What is the difference between 'topsis' and 'dia' which result in succesful differentiation in the topsis case, while unsuccesful differentiation in the 'dia' case? 

> with('LinearAlgebra'):

> dia:=proc(X::Matrix,C::Vector)
local i,j,k,l,t,v,Dpos,Dneg,Dposmin,Dnegmax,N,M;
N,M:=Dimensions(X);

#DiA
for i to M do:
for j to N do:
v[j,i]:=C[i]*X[j,i];
od;
od;

for j to N do:
Dpos[j]:=add( abs( v[j,i] - max(seq(v[k,i],k=1..N)) ) ,i=1..M );
Dneg[j]:=add( abs( v[j,i] - min(seq(v[k,i],k=1..N)) ), i=1..M );
od;

Dposmin:=min(seq(Dpos[j],j=1..N));
Dnegmax:=max(seq(Dneg[j],j=1..N));

for j to N do:
t[j]:=sqrt((Dpos[j]-Dposmin)^2+(Dneg[j]-Dnegmax)^2);
od;

Vector(N,t);

end proc:

> topsis:=proc(X::Matrix,C::Vector)
local i,j,t,v,Dpos,Dneg,N,M;
N,M:=Dimensions(X);


#TOPSIS
for i to M do:
for j to N do:
v[j,i]:=C[i]*X[j,i];
od;
od;
#i,j:='i','j';
for j to N do:
Dpos[j]:= sqrt(add( (v[j,i] - max( seq( v[j,i],j=1..N ) ))^2, i=1..M));
Dneg[j]:= sqrt(add( (v[j,i] - min( seq( v[j,i],j=1..N ) ))^2, i=1..M));
od;
#j:='j';
for j to N do:
t[j]:= safeDivide(Dneg[j],Dneg[j]+Dpos[j]);
od;
Vector(N,t);
#sumNorm(Vector(N,t));
end proc:

> X:=Matrix(3,3,<<x,0.2,0.8>|<0.8,0.2,0.2>|<0.2,0.8,0.2>>);C:=Vector(3,1/3);

> diff(dia(X,C)[2],x);
Error, (in Convert) unable to convert

> diff(topsis(X,C)[2],x):

this is ok.

I would like to give some additional information. A similar algorithm to 'dia' called 'topsis' works fine. What is the difference between 'topsis' and 'dia' which result in succesful differentiation in the topsis case, while unsuccesful differentiation in the 'dia' case? 

> with('LinearAlgebra'):

> dia:=proc(X::Matrix,C::Vector)
local i,j,k,l,t,v,Dpos,Dneg,Dposmin,Dnegmax,N,M;
N,M:=Dimensions(X);

#DiA
for i to M do:
for j to N do:
v[j,i]:=C[i]*X[j,i];
od;
od;

for j to N do:
Dpos[j]:=add( abs( v[j,i] - max(seq(v[k,i],k=1..N)) ) ,i=1..M );
Dneg[j]:=add( abs( v[j,i] - min(seq(v[k,i],k=1..N)) ), i=1..M );
od;

Dposmin:=min(seq(Dpos[j],j=1..N));
Dnegmax:=max(seq(Dneg[j],j=1..N));

for j to N do:
t[j]:=sqrt((Dpos[j]-Dposmin)^2+(Dneg[j]-Dnegmax)^2);
od;

Vector(N,t);

end proc:

> topsis:=proc(X::Matrix,C::Vector)
local i,j,t,v,Dpos,Dneg,N,M;
N,M:=Dimensions(X);


#TOPSIS
for i to M do:
for j to N do:
v[j,i]:=C[i]*X[j,i];
od;
od;
#i,j:='i','j';
for j to N do:
Dpos[j]:= sqrt(add( (v[j,i] - max( seq( v[j,i],j=1..N ) ))^2, i=1..M));
Dneg[j]:= sqrt(add( (v[j,i] - min( seq( v[j,i],j=1..N ) ))^2, i=1..M));
od;
#j:='j';
for j to N do:
t[j]:= safeDivide(Dneg[j],Dneg[j]+Dpos[j]);
od;
Vector(N,t);
#sumNorm(Vector(N,t));
end proc:

> X:=Matrix(3,3,<<x,0.2,0.8>|<0.8,0.2,0.2>|<0.2,0.8,0.2>>);C:=Vector(3,1/3);

> diff(dia(X,C)[2],x);
Error, (in Convert) unable to convert

> diff(topsis(X,C)[2],x):

this is ok.

Hi,

 

Thank you for your answer. 

I forgot to say, that I use the LinearAlgebra  package. 
> with(LinearAlgebra):

Now it produces the first error on my side. I use Maple 9.03, because this is freely downloadable at our campus.

Best regards, Zoltan

Hi,

 

Thank you for your answer. 

I forgot to say, that I use the LinearAlgebra  package. 
> with(LinearAlgebra):

Now it produces the first error on my side. I use Maple 9.03, because this is freely downloadable at our campus.

Best regards, Zoltan

1 2 Page 2 of 2