You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
HMM model constructors seem to only allow literal constraints #8
Thanks for the report. I'll clarify the documentation in help(hmm-dists). I agree it would be nice to support variables here, but I think some tricky "computing on the language" would be required to fix this. Any suggestions are welcome.
Thanks for the feedback. Unfortunately I'm not good enough with R yet to be sure of how to fix this. Here's what I think is going on:
In the code above, when the constructor for hmmNorm gets to hmmDist in R/hmm-dists.R and eval is called, it's looking for the variable t in the current environment, where it doesn't exist. One parameter to eval is envir, which is parent.frame(1) by default. If parent.frame(2) or parent.frame(3) is specified instead, it will look up that many generations in the call stack - maybe this can be used to look fr the value of t in the environment wherein hmmNorm was called?
In the meantime, here's a workaround/hack (which won't work for the variable name t, unfortunately, since it's already the name of a base function):
b<<-1d<<0.5h<- hmmNorm(b,d)
This works since b and d are then defined in the global scope and so eval doesn't have any trouble finding their values.
A few updates here. I also encountered this, but bare variables now work (presumably due to R interpreter?).
In addition to @wjchulme's suggestion, another workaround is to directly edit the attributes of the function post-construction.
## works in R 4.0.4, msm_1.6.9
val <- 0.2
obs.var <- hmmBinom(size=1, prob=val)
## also works
l.obs.sub <- lapply(seq(0.1, 0.9, by=0.1), function(x) {
ret <- hmmBinom(size=1, prob=1)
ret$pars['prob'] <- x
ret
})
Activity
lbakerIsazi commentedon Oct 5, 2017
The following code also produces an error:
chjackson commentedon Oct 6, 2017
Thanks for the report. I'll clarify the documentation in help(hmm-dists). I agree it would be nice to support variables here, but I think some tricky "computing on the language" would be required to fix this. Any suggestions are welcome.
lbakerIsazi commentedon Oct 6, 2017
Thanks for the feedback. Unfortunately I'm not good enough with R yet to be sure of how to fix this. Here's what I think is going on:
In the code above, when the constructor for
hmmNormgets tohmmDistinR/hmm-dists.Randevalis called, it's looking for the variabletin the current environment, where it doesn't exist. One parameter toevalisenvir, which isparent.frame(1)by default. Ifparent.frame(2)orparent.frame(3)is specified instead, it will look up that many generations in the call stack - maybe this can be used to look fr the value oftin the environment whereinhmmNormwas called?In the meantime, here's a workaround/hack (which won't work for the variable name
t, unfortunately, since it's already the name of a base function):This works since
banddare then defined in the global scope and soevaldoesn't have any trouble finding their values.wjchulme commentedon Feb 11, 2019
Hello @lbakerIsazi, the
lift_*()functions from thepurrrpackage can help in this situation. For instance:will behave as you need.
lift_dl(hmmNorm)is convertinghmmNormfrom a function that accepts...(or dots, hence thed) as its argument to a function that accepts a list (hence thel) as its argument. You can see more info at https://purrr.tidyverse.org/reference/lift.htmlhelmingstay commentedon Dec 9, 2021
A few updates here. I also encountered this, but bare variables now work (presumably due to R interpreter?).
In addition to @wjchulme's suggestion, another workaround is to directly edit the attributes of the function post-construction.