Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix obs.mat feature of fitcn #71

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions R/apps.R
Original file line number Diff line number Diff line change
Expand Up @@ -2287,13 +2287,13 @@ fitcn = function (gw, cn.field = "cn", trim = TRUE, weight = NULL, obs.mat = NUL
Zero = sparseMatrix(1, 1, x = 0, dims = c(2 * w * p,
2 * w * p))
A0 = Zero[rep(1, nrow(A)), 1:(2 * p)]
Ap = cbind(Zero[rep(1, p), 1:w], sign(obs.mat), diag(rep(-1,
p)), Zero[rep(1, p), 1:p])
Mpub = cbind(Zero[rep(1, p), 1:(2 * w)], diag(rep(1,
p)), diag(rep(-1e+07, p)))
Mplb = cbind(Zero[rep(1, p), 1:(2 * w)], diag(rep(1,
p)), diag(rep(-0.1, p)))
Amp = rbind(cbind(A, A0), Ap, Mpub, Mplb)
Ap = cbind2(cbind2(Zero[rep(1, p), 1:w], sign(obs.mat)),
cbind2(diag(rep(-1, p)), Zero[rep(1, p), 1:p]))
Mpub = cbind2(cbind2(Zero[rep(1, p), 1:(2 * w)]),
cbind2(diag(rep(1, p)), diag(rep(-1e+07, p))))
Mplb = cbind2(cbind2(Zero[rep(1, p), 1:(2 * w)], diag(rep(1, p))),
diag(rep(-0.1, p)))
Amp = rbind2(rbind2(cbind2(A, A0), Ap), rbind2(Mpub, Mplb))
b = c(b, rep(0, 3 * p))
cvec = c(cvec, rep(0, p), -1 * rowMax(obs.mat))
sense = c(sense, rep("E", p), rep("L", p), rep("G", p))
Expand Down Expand Up @@ -2409,6 +2409,7 @@ fitcn = function (gw, cn.field = "cn", trim = TRUE, weight = NULL, obs.mat = NUL
}
else {
if (trim) {
# trimming the graph to only include nodes and edges that are included in the walks
e = as.matrix(
gw$graph$edges[sedge.id %in% abs(unlist(gw$sedge.id))]$dt[, cn.field, with = FALSE])
e2 = as.matrix(
Expand Down Expand Up @@ -2544,16 +2545,15 @@ fitcn = function (gw, cn.field = "cn", trim = TRUE, weight = NULL, obs.mat = NUL
}
}
}
## return(sol)
## for (cnm in cn.field){
## gw$set(eval(paste0("cn.", i)) = xmat[, cnm])
## }
## if (length(sol) > 1) {

if (return.gw){
for (i in seq_along(sol)){
this.sol = sol[[i]]
this.x = this.sol$xopt
if (!is.null(obs.mat)){
# need to remove the additional values added due to the constraints
this.x = this.x[1:(2*length(gw))]
}
this.cnf = rep(c(cn.field, "indicator"), each = length(gw))
this.ls = split(this.x, this.cnf)
names(this.ls) = paste(names(this.ls), i, sep = sep)
Expand Down
2 changes: 2 additions & 0 deletions R/converters.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# assigning this operator since sometimes R tries to use the ggplot2 operator instead of the gUtils one (depending on the order of libraries loaded in a session)
`%+%` = gUtils::`%+%`

#' @name breakgraph
#' @title breakgraph
Expand Down
2 changes: 1 addition & 1 deletion R/eventCallers.R
Original file line number Diff line number Diff line change
Expand Up @@ -2068,7 +2068,7 @@ simple = function(gg,

if (!is.element("cn", colnames(gg$nodes$dt)))
{
stop('nodes and edges must have $cn annotation for bfb function')
stop('nodes and edges must have $cn annotation')
}

if (!any(gg$edges$dt[, type=="ALT"])){
Expand Down
8 changes: 5 additions & 3 deletions R/gGnome.R
Original file line number Diff line number Diff line change
Expand Up @@ -2376,6 +2376,7 @@ gGraph = R6::R6Class("gGraph",
return(gWalk$new(snode.id = c(paths, cycles), graph = self, circular = circular))
},


#' @name set
#' @description
#'
Expand Down Expand Up @@ -8248,7 +8249,6 @@ gWalk = R6::R6Class("gWalk", ## GWALKS
sense = ll$sense
vtype = ll$vtype
}
## sol = Rcplex::Rcplex(cvec = c,
sol = Rcplex2(cvec = c,
Amat = A,
bvec = b,
Expand Down Expand Up @@ -8281,7 +8281,6 @@ gWalk = R6::R6Class("gWalk", ## GWALKS
bhat = c(b, p)
sensehat = c(sense, rep('L', length(p)))

## sol.new = Rcplex::Rcplex(cvec = c,
sol.new = Rcplex2(cvec = c,
Amat = Ahat,
bvec = bhat,
Expand Down Expand Up @@ -8336,6 +8335,7 @@ gWalk = R6::R6Class("gWalk", ## GWALKS
'labels.suppress',
'labels.suppress.gr',
'label.suppress.grl',
'cex.label',
'yaxis'), names(private$pgraph$meta))]

args = list(...)
Expand All @@ -8360,7 +8360,9 @@ gWalk = R6::R6Class("gWalk", ## GWALKS

gt.args[['data']] = tmp.grl

gt.args[['grl.labelfield']] = "name"
if (is.null(gt.args[['grl.labelfield']])){
gt.args[['grl.labelfield']] = "name"
}

do.call(gTrack, gt.args)
}
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test_gGnome_ops.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ test_that('fitcn, simple/TRA', { # we include the test for TRA here since h526 h

sol = gGnome::fitcn(wks, return.gw = FALSE)

# TODO: not adding a test for obs.mat for now since it is failing.
# obs.mat = matrix(1, nrow = length(wks), ncol = length(wks))
#res = gGnome::fitcn(wks, obs.mat = obs.mat, verbose = TRUE)
# test fitcn with obs.mat
obs.mat = matrix(1, nrow = length(wks), ncol = length(wks))
res = gGnome::fitcn(wks, obs.mat = obs.mat, verbose = TRUE)

foo = refresh(wks2)$fitcn(verbose = TRUE)
foo = refresh(wks2)$fitcn(verbose = TRUE, edgeonly = TRUE)
Expand Down