0

I have the following function:

fitWindowing <- function(sfa, samples, windowSize, wordLength, symbolSet, normMean, lowerBounding) {
  sfa[["transformation"]] <- createMFT(windowSize, normMean, lowerBounding)
  # some code
  catch <- fitTransformSupervised(sfa, sa, wordLength, symbolSet, normMean)
  # some code
  return(sfa)}

When I call it:

weasel[["signature"]][[index]] <- fitWindowing(weasel[["signature"]][[index]], samples, weasel[["windowLengths"]][index], weasel[["maxF"]], weasel[["symbolSet"]], weasel[["normMean"]], FALSE)

it passes all arguments but weasel[["maxF"]], weasel[["symbolSet"]] (numbers). During debugging the function keeps .Primitive("call") (unevaluated promise) in their place and passes 0's to fitTransformSupervised instead of correct values. weasel stores correct values and reassigning them doesn't solve the issue. Interestingly, these two arguments are the only ones not used in fitWindowing before passing them to fitTransformSupervised, yet createMFT handles all arguments correctly. How can I force fitWindowing to also get/use all arguments properly?

Edit: code

weasel:

createWEASEL <- function(maxF, maxS, windowLength, normMean) {
  weasel <- list()
  weasel[["maxF"]] <- maxF
  weasel[["symbolSet"]] <- maxS
  weasel[["windowLengths"]] <- windowLength
  weasel[["normMean"]] <- normMean
  weasel[["signature"]] <- vector("list", length(weasel[["windowLengths"]]))
  weasel[["dict"]] <- createDictionary()
  return(weasel)
}

function calling fitWindowing:

createWords <- function(weasel, samples, index, bar) {
  if (is.null(weasel[["signature"]][[index]])) {
    weasel[["signature"]][[index]] <- createSFA("INFORMATION_GAIN", TRUE, FALSE)
    weasel[["signature"]][[index]] <- fitWindowing(weasel[["signature"]][[index]], samples, weasel[["windowLengths"]][index], weasel[["maxF"]], weasel[["symbolSet"]], weasel[["normMean"]], FALSE)
  }
  wordsList <- list()
  catch <- list()
  for (i in 1:samples[["samples"]]) {
    catch <- SFAWindowingInt(weasel[["signature"]][[index]], samples[["tseries"]][[i]], weasel[["maxF"]])
    weasel[["signature"]][[index]] <- catch[[1]]
    wordsList[[i]] <- catch[[2]]
  }
  weasel[["words"]][[index]] <- wordsList
  if (!is.null(bar)) {
    setTxtProgressBar(bar, index)
  }
  return(weasel)
}

and fitWindowing:

fitWindowing <- function(sfa, samples, windowSize, wordLength, symbolSet, normMean, lowerBounding) {
  sfa[["transformation"]] <- createMFT(windowSize, normMean, lowerBounding)
  sa <- list()
  index = 0
  
  for (i in 1:samples[["samples"]]) {
    newList <- getDisjointSequences(samples[["tseries"]][[i]], windowSize, normMean)
    for (j in 1:length(newList)) {
      index = index + 1
      sa[[index]] <- newList[[j]]
    }
  }
  sa[["samples"]] <- index
  catch <- list()
  if (sfa[["SUP"]] == TRUE) catch <- fitTransformSupervised(sfa, sa, wordLength, symbolSet, normMean)
  else catch <- fitTransform(sfa, sa, wordLength, symbolSet, normMean)
  return(catch[[1]])
}

Edit No. 2: more code

Creation of weasel:

fitWEASEL <- function(classifier, train) {
  maxCorrect = -1
  bestF = -1
  bestNorm = FALSE
  classifier[["minWindowLength"]] <- 4
  maxWindowLength = classifier[["maxWindowLength"]]
  for (i in 1:train[["samples"]]) {
    maxWindowLength = min(length(train[["tseries"]][[i]][["data"]]), maxWindowLength)
  }
  classifier[["windows"]] <- classifier[["minWindowLength"]]:maxWindowLength
  
  keepGoing = TRUE
  catch <- list()
  for (normMean in c(TRUE, FALSE)) {
    if (keepGoing) {
      weasel <- createWEASEL(classifier[["maxF"]], classifier[["maxS"]], classifier[["windows"]], normMean)
  # more code
}

function calling the function calling fitWindowing:

createFitting <- function(weasel, samples) {
  weasel[["words"]] <- rep(NA, length(weasel[["windowLengths"]]))
  print("Fitting...")
  for (i in 1:length(weasel[["windowLengths"]])) {
    weasel <- createWords(weasel, samples, i, NULL)
  }
  value <- list()
  value[[1]] <- weasel
  value[[2]] <- weasel[["words"]]
  return (value)
}

weasel args as visible from createWords

args passed to fitWindowing

konogaame
  • 1
  • 2
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 30 '21 at 04:07
  • 1
    You might find `?force` useful here - can't say for sure without a reproducible example. – Mikael Jagan Nov 30 '21 at 04:14
  • 1
    Can you show us the call to `createWEASEL` that you have used to construct `weasel`, and show us the call to `createWords` that produces the issue you have described, _and_ tell us what packages you have loaded (e.g., by pasting the output of `sessionInfo()`)? – Mikael Jagan Nov 30 '21 at 05:44
  • @MikaelJagan I hope this is enough, I don't think that posting all the route is possible (2000 lines of nested functions), moreover copying values, converting them by `as.integer()` doesn't help. I used no additional packages throughout the whole project. `force` helped partially - values were passed to the next function correctly but then the same issue appeared after passing them again to the following functions – konogaame Nov 30 '21 at 09:45

0 Answers0