Question: question on differentiation and integration problems

Dear All,

 

I am not an expert in Mapple, also my calculus courses were quite long ago. I would like to compare different decision methods. The simpler ones worked with the code below (even if it was slow). but I have problems with the differentiation and the integration of two complex methods (i.e., dia and topsis).

All these methods can be described in general with the  following function:

f:= (X::Matrix,C::Vector)-> TerminalScores::Vector

In my comparison I fix C, and X to constant numeric values. The exception is  X[1,1] :=t parameter. Hence with the unapply(f(X,C),t) I can generate a single-parameter function for each method.

Fist, I would like to diffrentiate the methods (f1, f2, f3) based on t (the only variable) -> D(f1),D(f2),D(f3)

Secondly, I would like to calculate the pairwise distances defined as: distance1=abs(D(f2)-D(f1)) and distance2=abs(D(f3)-D(f1))

Thirdly, I would like to integrate these distances to get a kind of "distortion" metric compared to f1: int(distance1,t) and int(distance2,t).

The 'dia' method could not be differentiated due to Error in (convert), unable to convert

The topsis method could be differentiated, but the integration operation never ends.

I think that this is due to the  min and max functions in dia and topsis, and due to the abs(), but how to resolve this issue, and at least calculate a numerical integral? Should I make assumptions on t? 

BR,

Zoltán 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.2,0.8>|<0.8,0.8,0.8>|<0.2,0.8,0.8>>);

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(X[i],t);
        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,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

Error, (in Convert) unable to convert

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

distanceOfMethods:=abs(diffTermScores[3]-diffTermScores[1]):

Before integration I replace undefined values to 0

tmp:=unapply(subs(Float(undefined)=0,distanceOfMethods),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[4](int(tmp(t),t=0..1));

Warning,  computation interrupted

 

 

 



Download question_differentia.mw

Please Wait...