Closed gaborcsardi closed 10 years ago
@youngser : for weighted graphs, FUN
is ignored, is this intentional?
youngser:
Yes, instead "wstat" function is used (included in the code). It's basically "weighted degree" for scan0 and "weighted ecount" for else. Please fix/improve it if necessary.
I wrote it only because I couldn't find those functions in igraph. If you have already them (hopefully as fast as existing "degree" and "ecount", then please use them accordingly.
Hope it makes sense.
How about these defaults?
local.scan <- function(graph.us, graph.them=NULL, k=1, FUN=NULL,
weighted=FALSE, mode=c("out", "in", "all", "total"), ...) {
if (is.null(FUN)) {
if (k == 0 && weighted) {
FUN <- function(g) graph.strength(mode=mode, ...)
} else if (k == 0 && ! weighted) {
FUN <- function(g) degree(mode=mode, ...)
} else if (k > 0 && weighted) {
FUN <- function(g) sum(E(g)$weight)
} else { # k > 0 && ! weighted
FUN <- ecount
}
}
Then it is possible to supply an arbitrary function for each case, and we also have reasonable defaults.
youngser:
Looks good to me!
Btw. is the local.scan
name good, or scanstat
is better? I think local.scan
is more descriptive, but scanstat
sounds better.
youngser:
I prefer local.scan! To us, scanstat is a global thingy, after taking min or max of local.scan...
HEng Wang:
Hello Gabor,
For this function, i think local.scan is more accurate because the definition of scanstat is the maximum of local.scan(v) over all vertices v.
Best, Heng
Carey:
right. (from spatial statistics, eg) the (global) scan statistic is the max of (local) locality statistics.
OK, have some faster R code now, as a next step, before moving to C. Before that I'll set up a benchmarking environment, to make it easy to run benchmarks for two git trees against each other, see #6.
@youngser: your function gives me:
g <- graph.formula( a -+ b +-+ c, a -+c )
E(g)$weight <- 1:4
local.scan(g, k=1, weighted=TRUE)
Why divided by two? This is an error, right? I believe the right answer should be 10, 7, 7.
Thanks.
I believe so! Yes, it's an error! It should be the undirected case, that is,
if (mode!="in" & mode!="out") out <- out/2
right?
Thanks,
- Youngser
You also need to check that the graph is actually directed, because otherwise mode does not apply and is (should be) ignored.
Right!
I'll close this for now, as I understand everything that was needed, is done. Please open it if you need something else.
TODO list on top
US
THEM
Gabor, Regarding the enhancement of our "scanstat" code, please find the attached as our working R code that can handle any k (of scank) and more. Please note that when another graph "gp" is used (along with g) as an input, e.g,
it first finds k-neighbors of each vertex v from g, then apply FUN to its induced graph in gp. FYI, we call this case as "them" as opposed to "us" without gp.
In addition to these extension, it also can work on weighted graph.
The file also contains a function called "test.scan" for a sample run, benchmarking, and verification.
I hope you can easily modify your beautiful implementation of "scan1" to incorporate these additional functionalities. Just let us know if you think we need further discussion to clarify some of these points or for anything else.
Thank you for your help! Best,