RAPLER / dst-1

Combine basic probability assignments with Dempster's rule of combination
6 stars 3 forks source link

`nzdsr` isn't working with the sparse matrix version 1.5.1.9007 #14

Closed garyzhubc closed 1 year ago

garyzhubc commented 1 year ago

nzdsr isn't working with the sparse matrix version 1.5.1.9007

RAPLER commented 1 year ago

See the patch for nzdsr in the bca_mod branch: Temporary patch for bug "object 'm_empty' not found".

garyzhubc commented 1 year ago

How to install the patch? Didn't seem to reflect on the code

function (x) 
{
  if (inherits(x, "bcaspec") == FALSE) {
    stop("Input argument not of class bcaspec.")
  }
  if (is.null(x$ssnames)) {
    w12 <- cbind(x$spec[, 2], x$tt)
    w1 <- x$tt
    mac <- x$spec[, 2]
    nc = ncol(w1)
    if (is.null(x$sort_order)) {
      x$sort_order <- order(apply(x$tt, 1, sum))
    }
    tri <- x$sort_order
    ind <- w12[tri[1], ]
    if ((ind[1] != 0) & (sum(ind[-1]) == 0)) {
      empty <- tri[1]
      W2 <- matrix(w1[tri[-1], ], ncol = nc)
      MACC <- mac[tri[-1]]/(1 - mac[empty])
      m_empty <- mac[empty]
    }
    else {
      empty <- 0
      W2 <- matrix(w1, ncol = nc)
      MACC <- mac
      m_empty <- 0
    }
    tt <- W2
    colnames(tt) <- colnames(x$tt)
    rownames(tt) <- nameRows(tt)
    spec <- cbind((1:nrow(tt)), MACC)
    colnames(spec) <- c("specnb", "mass")
    infovar <- x$infovar
    varnames <- x$varnames
    valuenames <- x$valuenames
    relnb <- (x$inforel)[1, 1]
    inforel <- matrix(c(relnb, nrow(infovar)), ncol = 2)
    colnames(inforel) <- c("relnb", "depth")
    z <- list(con = m_empty, tt = tt, spec = spec, infovar = infovar, 
      varnames = varnames, valuenames = valuenames, inforel = inforel)
    class(z) <- append(class(z), "bcaspec")
  }
  else {
    MAC <- x$spec[, 2]
    if (x$spec[1, 2] != 0) {
      MACC <- MAC[-1]/(1 - MAC[1])
    }
    else {
      MACC <- MAC
    }
    ssnames <- x$ssnames[-1]
    spec <- cbind((1:(-1 + length(x$ssnames))), MACC)
    colnames(spec) <- c("specnb", "mass")
    infovar <- x$infovar
    varnames <- x$varnames
    relnb <- (x$inforel)[1, 1]
    inforel <- matrix(c(relnb, nrow(infovar)), ncol = 2)
    colnames(inforel) <- c("relnb", "depth")
    z <- list(con = m_empty, tt = NULL, spec = spec, infovar = infovar, 
      varnames = varnames, valuenames = NULL, inforel = inforel)
    class(z) <- append(class(z), "bcaspec")
  }
  return(z)
}

and the problem persist

> bpa<-addTobca(nzdsr(bpa),tt_)
Error in nzdsr(bpa) : object 'm_empty' not found
RAPLER commented 1 year ago

I have published pre-release v1.5.1.9008 with the patch to nzdsr function.

Le jeu. 28 sept. 2023 à 01:30, Peiyuan Zhu @.***> a écrit :

How to install the patch? Didn't seem to reflect on the code

function (x) { if (inherits(x, "bcaspec") == FALSE) { stop("Input argument not of class bcaspec.") } if (is.null(x$ssnames)) { w12 <- cbind(x$spec[, 2], x$tt) w1 <- x$tt mac <- x$spec[, 2] nc = ncol(w1) if (is.null(x$sort_order)) { x$sort_order <- order(apply(x$tt, 1, sum)) } tri <- x$sort_order ind <- w12[tri[1], ] if ((ind[1] != 0) & (sum(ind[-1]) == 0)) { empty <- tri[1] W2 <- matrix(w1[tri[-1], ], ncol = nc) MACC <- mac[tri[-1]]/(1 - mac[empty]) m_empty <- mac[empty] } else { empty <- 0 W2 <- matrix(w1, ncol = nc) MACC <- mac m_empty <- 0 } tt <- W2 colnames(tt) <- colnames(x$tt) rownames(tt) <- nameRows(tt) spec <- cbind((1:nrow(tt)), MACC) colnames(spec) <- c("specnb", "mass") infovar <- x$infovar varnames <- x$varnames valuenames <- x$valuenames relnb <- (x$inforel)[1, 1] inforel <- matrix(c(relnb, nrow(infovar)), ncol = 2) colnames(inforel) <- c("relnb", "depth") z <- list(con = m_empty, tt = tt, spec = spec, infovar = infovar, varnames = varnames, valuenames = valuenames, inforel = inforel) class(z) <- append(class(z), "bcaspec") } else { MAC <- x$spec[, 2] if (x$spec[1, 2] != 0) { MACC <- MAC[-1]/(1 - MAC[1]) } else { MACC <- MAC } ssnames <- x$ssnames[-1] spec <- cbind((1:(-1 + length(x$ssnames))), MACC) colnames(spec) <- c("specnb", "mass") infovar <- x$infovar varnames <- x$varnames relnb <- (x$inforel)[1, 1] inforel <- matrix(c(relnb, nrow(infovar)), ncol = 2) colnames(inforel) <- c("relnb", "depth") z <- list(con = m_empty, tt = NULL, spec = spec, infovar = infovar, varnames = varnames, valuenames = NULL, inforel = inforel) class(z) <- append(class(z), "bcaspec") } return(z) }

and the problem persist

bpa<-addTobca(nzdsr(bpa),tt_) Error in nzdsr(bpa) : object 'm_empty' not found

— Reply to this email directly, view it on GitHub https://github.com/RAPLER/dst-1/issues/14#issuecomment-1738479353, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5D5IOQXLMZSDYA5OLDMGLX4UDNTANCNFSM6AAAAAA5KFYK2A . You are receiving this because you commented.Message ID: @.***>

RAPLER commented 1 year ago

problem with the pre-release. I have deleted the release. Will be redone later this morning. Sorry.

Le jeu. 28 sept. 2023 à 07:59, Claude Boivin @.***> a écrit :

I have published pre-release v1.5.1.9008 with the patch to nzdsr function.

Le jeu. 28 sept. 2023 à 01:30, Peiyuan Zhu @.***> a écrit :

How to install the patch? Didn't seem to reflect on the code

function (x) { if (inherits(x, "bcaspec") == FALSE) { stop("Input argument not of class bcaspec.") } if (is.null(x$ssnames)) { w12 <- cbind(x$spec[, 2], x$tt) w1 <- x$tt mac <- x$spec[, 2] nc = ncol(w1) if (is.null(x$sort_order)) { x$sort_order <- order(apply(x$tt, 1, sum)) } tri <- x$sort_order ind <- w12[tri[1], ] if ((ind[1] != 0) & (sum(ind[-1]) == 0)) { empty <- tri[1] W2 <- matrix(w1[tri[-1], ], ncol = nc) MACC <- mac[tri[-1]]/(1 - mac[empty]) m_empty <- mac[empty] } else { empty <- 0 W2 <- matrix(w1, ncol = nc) MACC <- mac m_empty <- 0 } tt <- W2 colnames(tt) <- colnames(x$tt) rownames(tt) <- nameRows(tt) spec <- cbind((1:nrow(tt)), MACC) colnames(spec) <- c("specnb", "mass") infovar <- x$infovar varnames <- x$varnames valuenames <- x$valuenames relnb <- (x$inforel)[1, 1] inforel <- matrix(c(relnb, nrow(infovar)), ncol = 2) colnames(inforel) <- c("relnb", "depth") z <- list(con = m_empty, tt = tt, spec = spec, infovar = infovar, varnames = varnames, valuenames = valuenames, inforel = inforel) class(z) <- append(class(z), "bcaspec") } else { MAC <- x$spec[, 2] if (x$spec[1, 2] != 0) { MACC <- MAC[-1]/(1 - MAC[1]) } else { MACC <- MAC } ssnames <- x$ssnames[-1] spec <- cbind((1:(-1 + length(x$ssnames))), MACC) colnames(spec) <- c("specnb", "mass") infovar <- x$infovar varnames <- x$varnames relnb <- (x$inforel)[1, 1] inforel <- matrix(c(relnb, nrow(infovar)), ncol = 2) colnames(inforel) <- c("relnb", "depth") z <- list(con = m_empty, tt = NULL, spec = spec, infovar = infovar, varnames = varnames, valuenames = NULL, inforel = inforel) class(z) <- append(class(z), "bcaspec") } return(z) }

and the problem persist

bpa<-addTobca(nzdsr(bpa),tt_) Error in nzdsr(bpa) : object 'm_empty' not found

— Reply to this email directly, view it on GitHub https://github.com/RAPLER/dst-1/issues/14#issuecomment-1738479353, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5D5IOQXLMZSDYA5OLDMGLX4UDNTANCNFSM6AAAAAA5KFYK2A . You are receiving this because you commented.Message ID: @.***>

RAPLER commented 1 year ago

I am having some problems with the drafting of a new pre-release. The files attached are not the latest ones. So Here is what can be done:

Go to: https://github.com/RAPLER/dst-1 (on github.com) Choose the bca_mod branch, With the green button "Code", download the zip file on your desktop Install in your library the package downloaded on your desktop.

Hope this will work.

Le jeu. 28 sept. 2023 à 08:05, Claude Boivin @.***> a écrit :

problem with the pre-release. I have deleted the release. Will be redone later this morning. Sorry.

Le jeu. 28 sept. 2023 à 07:59, Claude Boivin @.***> a écrit :

I have published pre-release v1.5.1.9008 with the patch to nzdsr function.

Le jeu. 28 sept. 2023 à 01:30, Peiyuan Zhu @.***> a écrit :

How to install the patch? Didn't seem to reflect on the code

function (x) { if (inherits(x, "bcaspec") == FALSE) { stop("Input argument not of class bcaspec.") } if (is.null(x$ssnames)) { w12 <- cbind(x$spec[, 2], x$tt) w1 <- x$tt mac <- x$spec[, 2] nc = ncol(w1) if (is.null(x$sort_order)) { x$sort_order <- order(apply(x$tt, 1, sum)) } tri <- x$sort_order ind <- w12[tri[1], ] if ((ind[1] != 0) & (sum(ind[-1]) == 0)) { empty <- tri[1] W2 <- matrix(w1[tri[-1], ], ncol = nc) MACC <- mac[tri[-1]]/(1 - mac[empty]) m_empty <- mac[empty] } else { empty <- 0 W2 <- matrix(w1, ncol = nc) MACC <- mac m_empty <- 0 } tt <- W2 colnames(tt) <- colnames(x$tt) rownames(tt) <- nameRows(tt) spec <- cbind((1:nrow(tt)), MACC) colnames(spec) <- c("specnb", "mass") infovar <- x$infovar varnames <- x$varnames valuenames <- x$valuenames relnb <- (x$inforel)[1, 1] inforel <- matrix(c(relnb, nrow(infovar)), ncol = 2) colnames(inforel) <- c("relnb", "depth") z <- list(con = m_empty, tt = tt, spec = spec, infovar = infovar, varnames = varnames, valuenames = valuenames, inforel = inforel) class(z) <- append(class(z), "bcaspec") } else { MAC <- x$spec[, 2] if (x$spec[1, 2] != 0) { MACC <- MAC[-1]/(1 - MAC[1]) } else { MACC <- MAC } ssnames <- x$ssnames[-1] spec <- cbind((1:(-1 + length(x$ssnames))), MACC) colnames(spec) <- c("specnb", "mass") infovar <- x$infovar varnames <- x$varnames relnb <- (x$inforel)[1, 1] inforel <- matrix(c(relnb, nrow(infovar)), ncol = 2) colnames(inforel) <- c("relnb", "depth") z <- list(con = m_empty, tt = NULL, spec = spec, infovar = infovar, varnames = varnames, valuenames = NULL, inforel = inforel) class(z) <- append(class(z), "bcaspec") } return(z) }

and the problem persist

bpa<-addTobca(nzdsr(bpa),tt_) Error in nzdsr(bpa) : object 'm_empty' not found

— Reply to this email directly, view it on GitHub https://github.com/RAPLER/dst-1/issues/14#issuecomment-1738479353, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5D5IOQXLMZSDYA5OLDMGLX4UDNTANCNFSM6AAAAAA5KFYK2A . You are receiving this because you commented.Message ID: @.***>

garyzhubc commented 1 year ago
> install.packages("~/Downloads/dst-1-bca_mod.zip")
Warning in install.packages :
  package ‘~/Downloads/dst-1-bca_mod.zip’ is not available for this version of R

A version of this package for your version of R might be available elsewhere,
see the ideas at
https://cran.r-project.org/doc/manuals/r-patched/R-admin.html#Installing-packages

Is there a specific R version that needs for this update?

garyzhubc commented 1 year ago

Either way doesn't work here.

install.packages("devtools")
library(devtools)
install_github("RAPLER/dst-1", ref="bca_mod")
install.packages("~/Downloads/dst-1-bca_mod.zip")
garyzhubc commented 1 year ago

I ended up using source("nzdsr.R"), which seem to have worked.

RAPLER commented 1 year ago

I work with R version 4.0.0. So, there should be no installation problem. No specific version is needed. I am considering bringing the master branch level with bca_mod, or switching branches. I don't know.

Le jeu. 28 sept. 2023 à 14:11, Peiyuan Zhu @.***> a écrit :

I ended up using source("nzdsr.R"), which seem to have worked.

— Reply to this email directly, view it on GitHub https://github.com/RAPLER/dst-1/issues/14#issuecomment-1739793838, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA5D5IJHGSHZGU7A6PT4UHDX4W4UJANCNFSM6AAAAAA5KFYK2A . You are receiving this because you commented.Message ID: @.***>

RAPLER commented 1 year ago

Is this issue resolved? Seems the case to me:)

garyzhubc commented 1 year ago

Yes, it is resolved. Thanks.

On Wed, Oct 4, 2023 at 6:32 PM Claude Boivin @.***> wrote:

Is this issue resolved? Seems the case to me:)

— Reply to this email directly, view it on GitHub https://github.com/RAPLER/dst-1/issues/14#issuecomment-1747900016, or unsubscribe https://github.com/notifications/unsubscribe-auth/AHHVV35FNBSRSVTQFQ6CYUDX5YE2DAVCNFSM6AAAAAA5KFYK2CVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTONBXHEYDAMBRGY . You are receiving this because you authored the thread.Message ID: @.***>