Are there any Pyomo examples for graph edit distance between graph1 and graph2?
Related
I am brand new to R and I am using library (grid), (graph), (Rgraphviz) and gRbase to try make a Undirected Graph for calculating marginal probability of each node and running the sum product algorithm on all the nodes.
This is my graph:
g1 <- ug(~1:2 + 1:3 + 2:4 + 2:5) and it looks pretty when I plot(g1). The problem is I have no idea how to input the node potentials and pairwise potentials onto the graph in R nor how to code up the sum-product algorithm in R. Any help or a reference to help would be appreciated. Thanks.
I try to plot a Voronoi diagram of three points:
library(tripack)
x<-c(1.7,-2.2,0.5)
y<-c(-0.6,-0.2,0.8)
v<-voronoi.mosaic(x,y)
plot(v)
However, it just shows an empty plot.
print(v)
gives:
voronoi mosaic:
nodes: (x,y): neighbours (<0: dummy node)
1: (-0.3238956,-1.120482): -1 -2 -3
dummy nodes: (x,y)
1: (-0.3238956,-1.120482)
2: (-0.3238956,-1.120482)
3: (-0.3238956,-1.120482)
Is this a bug? Does this makes sense? In my understanding it should be perfectly fine to build a Voronoi diagram from three points.
Yes, that could be considered a bug, since the definition of Voronoi regions makes good sense for sets with as few as two generator points.
The deldir package (which also implements Delauney triangulation and Dirichlet (Voronoi) tesselation) does correctly handle sets with three (and for that matter as few as two) generator points.
library(deldir)
x <- c(1.7,-2.2,0.5)
y <- c(-0.6,-0.2,0.8)
par(mfcol=c(1,2))
plot(deldir(x, y), asp=1)
plot(deldir(x[1:2], y[1:2]), asp=1)
I want to create a graph plot with each community of nodes been covered by some background color, similar to the graph by the following code
karate <- graph.famous("Zachary")
wc <- walktrap.community(karate)
modularity(wc)
membership(wc)
plot(wc, karate)
But different from this approach, I want to: (1) group the nodes by myself, instead of resulting from community detection algorithm. I achieved this by wc$membership <- some_vector; (2) plot such graph possibly with overlap between communities, then how can I assign one node to multiple communities?
Plot the graph itself instead of the community structure, and use an appropriately constructed mark.groups argument to plot() to tell igraph which groups should be enclosed by the same group. The following quote is from the manual page of plot.igraph:
mark.groups: A list of vertex id vectors. It is interpreted as a set of vertex groups. Each vertex group is highlighted, by plotting a colored smoothed polygon around and "under" it.
How can we plot a 3D plot for the in-out degree distribution.
I found the the plot here: http://en.wikipedia.org/wiki/Degree_distribution really interesting but I do not know if we can draw it using r ?
any ideas ?
update:
the data that I am using is the degree distribution of the in-degree and out-degree:
> head(dDistribution_in)
[1] 0.30117450 0.19379195 0.10654362 0.06291946 0.03775168 0.03313758
> head(dDistribution_out)
[1] 0.36115772 0.17072148 0.09228188 0.05369128 0.04572148 0.02055369
You can do this with perspective plots, here's an example that should help:
require(MASS)
set.seed(42)
persp(kde2d(rnorm(100), rnorm(100)), col="grey90", shade=1, theta=120, xlab="X")
If you're asking specifically about replicating this degree distribution, you can use the same idea on your data. Also, while 3D styled plots can look good, a clearer representation of that data may be something like a hexagonally-binned 2d histogram.
Update
Using the small sample of your data works fine:
d_in <- c(0.30117450, 0.19379195, 0.10654362, 0.06291946, 0.03775168, 0.03313758)
d_out <- c(0.36115772, 0.17072148, 0.09228188, 0.05369128, 0.04572148, 0.02055369)
persp(kde2d(d_in, d_out), col="grey90", shade=1, theta=120, xlab="X")
Not sure what you're doing wrong, but see this post on how to make a reproducible example.
I'm trying to draw a graph where the distance between vertices correspond to the edge weights* and I've founde that in graphviz there is a way to draw such graph. Is there a way to do this in R with the igraph package (specfically with graph.adkacency)?
Thanks,
Noam
(as once have been asked: draw a graph where the distance between vertices correspond to the edge weights)
This is not possible as you need triangle equality for every triangle to be able to plot such an object. So you can only approximate it. For this you can use "force embedded" algorithms. There are a few in igraph. The one I often use is the Fruchterman-Reingold algorithm.
See for details:
library("igraph")
?layout.fruchterman.reingold
Edit:
Note that the distance between nodes will correspond somewhat with the inverse of the absolute edge weight.
Like Sacha Epskamp mentioned, unless your data is perfect, you cannot draw a graph that would not violate some triangular inequalities. However, there are techniques named Multidimensional scaling (MDS) targeted at minimizing such violations.
One implementation in R is cmdscale from the stats package. I'd recommend the example at the bottom of ?cmdscale:
> require(graphics)
>
> loc <- cmdscale(eurodist)
> x <- loc[,1]
> y <- -loc[,2]
> plot(x, y, type="n", xlab="", ylab="", main="cmdscale(eurodist)")
> text(x, y, rownames(loc), cex=0.8)
Of course, you can plot x and y using any graphics packages (you were inquiring about igraph specifically).
Finally, I'm sure you'll find plenty of other implementations if you search for "multidimensional scaling" or "MDS". Good luck.