igraph-help
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [igraph] Help!!!!!!!!! how to get the laplacian of undirected weight


From: lan gao
Subject: Re: [igraph] Help!!!!!!!!! how to get the laplacian of undirected weighted graph?
Date: Thu, 25 Sep 2008 09:00:00 -0500

Thanks for your reply. The laplacian of a weighted graph is defined as :
L= D-W   where D is the degree matrix  and W is a weight matrix
 
what I did is this
 
 n=length(V(g))
 A=get.adjacency(g, attr="weight")
 D=matrix(0,n,n)
 for(i in 1:n)
 {diag(D)[i]=sum(A[i,])}
 L=D-A 
 
it is similar to your code. The graph has no loops. it seems the code works.
Thank you very much. I will let you know if I find something else.


 
On Thu, Sep 25, 2008 at 2:55 AM, Gabor Csardi <address@hidden> wrote:
I've never seen the definition of the Laplacian of a weighted graph,
but if it is the obvious generalization, then it should be something
like:

weighted.laplacian <- function(g) {
 adj <- get.adjacency(g, attr="weight")
 deg <- apply(adj, 1, sum)
 diag(deg) - adj
}

# Some quick test

g <- ba.game(10, directed=FALSE)
E(g)$weight <- sample(1:3, ecount(g), replace=TRUE)
weighted.laplacian(g)

It does not handle loop edges and I am not sure what it does
if you have multiple edges, but if you have a simple graph, then
it should be OK. The graph must have an edge attribute called 'weight'.

Is this what you want? If not, then could you point me to the
definition of the Laplacian of a weighted graph?

Gabor

On Wed, Sep 24, 2008 at 09:57:42AM -0500, lan gao wrote:
> Hello, guys,
>          Does anyone know how to get the laplacian matrix of an undirected
> and weighted graph?
>          I know for a simple undirected graph , we can use
> graph.laplacian(g) to get it, but I need to add weight to each edge, then
> how to get the laolacian of a weighted graph?
>           Can I add weight to the attribute of edge like E(g)$ weight<- wt ,
> then
> get adjacency matrix first....I am lost...
>         Can anyone give me a clue?
> Many thanks.

> _______________________________________________
> igraph-help mailing list
> address@hidden
> http://lists.nongnu.org/mailman/listinfo/igraph-help



_______________________________________________
igraph-help mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/igraph-help


reply via email to

[Prev in Thread] Current Thread [Next in Thread]