Given a graph with n nodes (n~3000 in our case) probably the simplest code is to loop directly. If A is the adjacency:

n<-dim(A)[1]

deg<-degrees(graph)

tdeg=sum(deg)

probs<-matrix(0,nrow=n,ncol=n)

# create the maximum likelihood implicit log-linear Bernoulli probabilities

# for edge i<->j

# for edge i<->j

for (i in 1:n){ for (j in 1:i){

const<-deg[i]*deg[j]/tdeg

p[i,j]<-const

p[j,i]<-const

}}

# modularize the sampling of the graph

sample.graph<-function(p){

n<-dim(p)[1]

adj.new<-matrix(0,nrow=n,ncol=n)

for (i in 1:n){ for (j in 1:i){

const<-p[i,j]

q<-sample(x=c(0,1),size=1,prob=c(const,1-const))

adj.new[i,j]<-q[1]

adj.new[j,i]<-q[1]

}}

graph.analysis<-function(g){

ddist<-degree.distribution(g)

ddist<-degree.distribution(g)

plot(ddist)

# create laplacian matrix

H<-graph.laplacian(g)

E<-eigen(H)

plot(E$value)

}

# test sampling

for (r in 1:100){

adj<-sample.graph(p)

adj<-sample.graph(p)

sampled.graph<-graph.adjacency(adj)

graph.analysis(sampled.graph)

}

Advertisements

on May 30, 2015 at 11:35 am |ReaderIt saddens me greatly to read your situation –

This time I won’t let you down.

Find the nearest Western Union and I’ll wire you as much as I can.

(Don’t worry about any other issue.)