Reputation: 201
I want to generate 100 different 5 by 5
random matrices using matlab
in [0,1] with the following property: Assume that the required matrix is A=[a_{ij}]
having the condition a_{ih}+a_{hj}-a_{ij}-0.5=0
(Matrix A
is the so-called Fuzzy Preference matrix (i.e.a_{ji}=1-a_{ij} for all i,j
), and also consistent). But, I am stuck to write the matlab code. Could anyone help me? Thanks!
Example of such matrix, but not consistent:
A=[.5 .5 .5 .8155 .5 .3423;...
.5 .5 .6577 .8155 .5 .3423;...
.5 .3423 .5 .88662 .75 .3423;...
.1845 .8145 .1338 .5 .25 .25;...
.5 .5 .25 .75 .5 .25;...
.6577 .6577 .6577 .75 .75 .5]
Example of 3 by 3
consistent Fuzzy Preference matrix:
B=[.5 .2 .5;...
.8 .5 .8;...
.5 .2 .5]
Upvotes: 0
Views: 223
Reputation: 8459
To solve this question we need to find solutions to a system of linear equations. The unknowns are the matrix entries, so for an NxN matrix there will be N^2 unknowns. There are N^3 equations since there is an equation for each combination of i
, j
, and h
. This is an overdetermined system, but is consistent, it's easy to see that the constant matrix with all entries 0.5 is a solution.
The system of equations can be written in matrix form, with matrix M defined as follows:
N = 5; % size of resulting matrix
M = zeros(N^3,N^2); % ar = size of matrix A
t = 0;
for i = 1:N
for j = 1:N
for h = 1:N
t = t+1;
M(t,(i-1)*N+h) = M(t,(i-1)*N+h)+1;
M(t,(h-1)*N+j) = M(t,(h-1)*N+j)+1;
M(t,(i-1)*N+j) = M(t,(i-1)*N+j)-1;
end
end
end
The right hand side is a vector of N^3 0.5's. The rank of the matrix appears to be N^2-N+1 (I think this is because the main diagonal of the result must be filled with 0.5, so there are really only N^2-N unknowns). The rank of the augmented system is the same, so we do have an infinite number of solutions, spanning an N-1 dimensional space.
So we can find the solutions as the sum of the vector of 0.5's plus any element of the null space of the matrix.
a = 0.5*ones(N^2,1) % solution to non-homogenous equation
nullspace = null(M) % columns form a basis for the null space
So we can now generate as many solutions as we like by adding multiples of the basis vectors of the null space to a
,
s = a+sum(rand(1,N-1).*nullspace,2) % always a solution
The final problem is to sample uniformly from this null space while requiring the all the entries stay within [0,1]
.
I think it's hard even to say what uniform sampling over this space is, but at least I can generate random elements by the following:
% first check the size of the largest element
% we can't addd/subtract more than 0.5to the homogeneous solution
for p = 1:size(nullspace,2)
mn(p) = 0.5/max(abs(nullspace(:,p)));
end
c = 0;
mat = {};
while c<5 % generate 5 matrices
% a solution is the homogeneous part 0.5*ones(N) plus
% some element of the nullspace sum(rand(1,size(n,2)).*mn.* nullspace,2)
% reshaped to be a square matrix
newM = 0.5*ones(N)+reshape(sum((2*rand(1,size(nullspace,2))-1).*mn.* nullspace,2),N,N)
% make sure the entries are all in [0,1]
if all(newM(:)>=0) && all(newM(:)<=1)
c = c+1;
mat{c} = newM;
end
end
% mat is a cell array of 5 matrices satisfying the condition
I don't have much idea about the distribution of the resulting matrices.
Upvotes: 1