Home > matgraph > @graph > thresh.m

thresh

PURPOSE ^

thresh(g,x) -- create a threshold graph

SYNOPSIS ^

function thresh(g,x)

DESCRIPTION ^

 thresh(g,x) -- create a threshold graph
 g is the graph to be created
 x is a vector of values in [0,1]
 we have an edge between i and j in g iff x(i) + x(j) >= 1

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function thresh(g,x)
0002 % thresh(g,x) -- create a threshold graph
0003 % g is the graph to be created
0004 % x is a vector of values in [0,1]
0005 % we have an edge between i and j in g iff x(i) + x(j) >= 1
0006 
0007 % make sure x is a row-vector
0008 x = x(:)';
0009 
0010 n = length(x);
0011 
0012 % Here is a MATLAB trick. We want a matrix whose ij entry is x(i)+x(j).
0013 % To do this, we exponentiate x, multiple x'*x, and then logarithm.
0014 
0015 ex = exp(x);
0016 M = log(ex'*ex);
0017 
0018 A = M >= 1;
0019 for k=1:n
0020     A(k,k) = 0;
0021 end
0022 
0023 set_matrix(g,A);

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003