# Question:differentiation results oscillations

## Question:differentiation results oscillations

Maple

Hi,

I would like to compare different decision methods. 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).

After some help (from pagan, thank you again), this almost works, but I experienced the following problem:

The differentiation of the second method f2 (called dia, see termScores[2], and diffTermScore[2]) results in oscillated function, even if the plot of f2 seems to be nice . I show this in the example below on a small region, t=0.39..0.3900003

So, do you know what is the cause of this oscillation? BR, Zoltán Faigl

 >
 >
 > 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]:=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]:=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]:= Dneg[j]/(Dneg[j]+Dpos[j]);         od;         #Vector(N,t);         sumNorm(Vector(N,t));         end proc:

Number of methods to compare

 > numOfMethods=3;
 (1)

1st input parameter of methods

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

2nd input parameter of methods

 > C:=Vector(3,1/3);
 (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]):

 >

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

 > distanceOfMethods:=Vector(2,):

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] (DIA-WS)
 (4)
 > distortion:=evalf(Int(tmp[2](t),t=0.0..1,epsilon=1e-4,digits=10)); # integration worked for tmp[2]
 (5)