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)
}