Open helenhe96 opened 6 years ago
@gtng92 pointed out that the kernel distance can be called on trees x
and y
as k(x,y)
or k(y,x)
, and that if we define two regular expressions then these trees could potentially be processed differently. After discussion we decided to use just one regex for kernel distances.
Please write unit tests to check whether labeled kernel function is behaving properly before closing
On branch issue133
, we presently have this in treekernel.R
(dropping commented lines):
tree.kernel <- function(tree1, tree2,
lambda, # decay factor
sigma, # RBF variance parameter
rho=1.0, # SST control parameter; 0 = subtree kernel, 1 = subset tree kernel
normalize=0, # normalize kernel score by sqrt(k(t1,t1) * k(t2,t2))
regexPattern="", # arguments for labeled tree kernel
regexReplacement="",
gamma=0 # label factor
) {
# make labels
use.label <- if (any(is.na(label1)) || any(is.na(label2)) || is.null(label1) || is.null(label2)) {
FALSE
} else {
new_label1 <- gsub(regexPattern, regexReplacement, tree1$tip.label)
new_label2 <- gsub(regexPattern, regexReplacement, tree2$tip.label)
TRUE
}
nwk1 <- .to.newick(tree1)
nwk2 <- .to.newick(tree2)
res <- .Call("R_Kaphi_kernel",
nwk1, nwk2, lambda, sigma, as.double(rho), use.label, gamma, normalize,
PACKAGE="Kaphi")
return (res)
}
We want to make these changes:
regexReplacement
should be \\1
by default (capture a single group). There may be a situation where we want to concatenate two or more groups, so I guess we can let the user define a more complex label like "\1\2".
On branch issue133
, implementation changed so that the weight matrix is no longer necessary.
We want to refactor the kernel to encode labels in each node's production. Whereas before productions can only take one of four values (0 for terminal node, 1 for node with two non-terminal descendants, etc.), we now want to have each internal node have a tuple (pair) of integers for productions, and reserve the integer value -1
when the descendant is an internal node.
New labeled kernel is being prototyped in Python, see PoonLab/coevolution phyloK3.py
Need to port Python implementation into R