matlab - Generating a linear system for popularity calculation -
this half mathematical half computer science question. working on matlab on mathematical problem. want generate linear system calculation of popularity of people (a vector x
) in generic social network, given simple matrix of friendship f
. if user 1 , user 2 friends, f(1,2)=1
f(2,1)=1
(the friendship bidirectional). transform problem in linear system need popularity value of person (x(i)
) , popularity of friends (∀x(j) | f(i,j)=1 , j≠i
) linearly dependent. wrote simple formula
x(j) = sum(x(i) x n(i) x f(i,j)) ∀i≠j
where n(i)
number of friends of i.
for size(x)=3
system this
-x(1) + f(1,2) n(2) x(2) + f(1,3) n(3) = 0 f(2,1) n(1) x(1) - x(2) + f(1,3) n(3) x(3) = 0 f(3,1) n(1) x(1) + f(1,2) n(2) x(2) - x(3) = 0
with specific formula there 2 problems:
- with no constant term, solution found
x(i)=0 ∀i
- i need positive values of popularity, approach gave negative (and correct!) results.
so need formula doesn't have 2 problems. formula can chosen arbitrarily because problem totally defined me. must take account of friendship relations , number of friends in linear combination (necessary linear system), positive. here code of generation , resolution of system
n=10; f=triu(randi([0,1],n)); f=f-diag(diag(f)); f=f+f'; n=(sum(f))'; a=ones(n); i=1:n a(:,i)=diag(n)*f(:,i); end a=a-eye(n); b=zeros(n,1); x=a\b
Comments
Post a Comment