Skip to content

Commit

Permalink
minor updates of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fchamroukhi committed Jul 29, 2019
1 parent 62f38f9 commit 1cf1d80
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 16 deletions.
2 changes: 1 addition & 1 deletion R/ParamMRHLP.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ ParamMRHLP <- setRefClass(
beta[, , k] <<- solve(M, tol = FALSE) %*% t(Xk) %*% yk # Maximization w.r.t betak
z <- (mData$Y - phi$XBeta %*% beta[, , k]) * (sqrt(weights) %*% ones(1, mData$d))

# Maximisation w.r.t sigmak (the variances)
# Maximisation w.r.t sigma2k (the variances)
sk <- t(z) %*% z

if (variance_type == "homoskedastic") {
Expand Down
6 changes: 3 additions & 3 deletions R/emHMMR.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ emHMMR <- function(X, Y, K, p = 3, variance_type = c("heteroskedastic", "homoske
stat$loglik <- stat$loglik + log(lambda)

if (verbose) {
cat(paste0("EM: Iteration : ", iter, " || log-likelihood : " , stat$loglik, "\n"))
cat(paste0("EM: Iteration : ", iter, " | log-likelihood : " , stat$loglik, "\n"))
}

if ((prev_loglik - stat$loglik) > 1e-4) {
Expand All @@ -108,7 +108,7 @@ emHMMR <- function(X, Y, K, p = 3, variance_type = c("heteroskedastic", "homoske
converged <- (abs(stat$loglik - prev_loglik) / abs(prev_loglik) < threshold)
if (is.na(converged)) {
converged <- FALSE
} # Basically for the first iteration when prev_loglik is Inf
} # Basically for the first iteration when prev_loglik is -inf

prev_loglik <- stat$loglik
stat$stored_loglik <- c(stat$stored_loglik, stat$loglik)
Expand Down Expand Up @@ -145,7 +145,7 @@ emHMMR <- function(X, Y, K, p = 3, variance_type = c("heteroskedastic", "homoske
# Smoothing state sequences : argmax(smoothing probs), and corresponding binary allocations partition
statSolution$MAP()

# Finish the computation of statistics
# Finish the computation of the model statistics
statSolution$computeStats(paramSolution)

return(ModelHMMR(param = paramSolution, stat = statSolution))
Expand Down
4 changes: 2 additions & 2 deletions R/emMHMMR.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ emMHMMR <- function(X, Y, K, p = 3, variance_type = c("heteroskedastic", "homosk
converged <- (abs(stat$loglik - prev_loglik) / abs(prev_loglik) < threshold)
if (is.na(converged)) {
converged <- FALSE
} # Basically for the first iteration when prev_loglik is Inf
} # Basically for the first iteration when prev_loglik is -inf

prev_loglik <- stat$loglik
stat$stored_loglik <- c(stat$stored_loglik, stat$loglik)
Expand Down Expand Up @@ -147,7 +147,7 @@ emMHMMR <- function(X, Y, K, p = 3, variance_type = c("heteroskedastic", "homosk
# Smoothing state sequences : argmax(smoothing probs), and corresponding binary allocations partition
statSolution$MAP()

# Finish the computation of statistics
# Finish the computation of model statistics
statSolution$computeStats(paramSolution)

return(ModelMHMMR(param = paramSolution, stat = statSolution))
Expand Down
2 changes: 1 addition & 1 deletion R/emMRHLP.R
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ emMRHLP <- function(X, Y, K, p = 3, q = 1, variance_type = c("heteroskedastic",
converge <- abs((stat$loglik - prev_loglik) / prev_loglik) <= threshold
if (is.na(converge)) {
converge <- FALSE
} # Basically for the first iteration when prev_loglik is Inf
} # Basically for the first iteration when prev_loglik is -inf

prev_loglik <- stat$loglik
stat$stored_loglik <- c(stat$stored_loglik, stat$loglik)
Expand Down
2 changes: 1 addition & 1 deletion R/emRHLP.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ emRHLP <- function(X, Y, K, p = 3, q = 1, variance_type = c("heteroskedastic", "
converge <- abs((stat$loglik - prev_loglik) / prev_loglik) <= threshold
if (is.na(converge)) {
converge <- FALSE
} # Basically for the first iteration when prev_loglik is Inf
} # Basically for the first iteration when prev_loglik is -inf

prev_loglik <- stat$loglik
stat$stored_loglik <- c(stat$stored_loglik, stat$loglik)
Expand Down
15 changes: 7 additions & 8 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,17 @@ mhmmr$plot(what = c("smoothed", "regressors", "loglikelihood"))

# Model selection

In this package, it is possible to select models based on information criteria
such as **BIC**, **AIC** and **ICL**.
samurais also implements model selection procedures to select an optimal model based on information criteria including **BIC**, **AIC** and **ICL**.

The selection can be done for the two following parameters:

* **K**: The number of regimes;
* **K**: The number of regimes (segments);
* **p**: The order of the polynomial regression.

Instructions below can be used to illustrate the model on provided simulated and real data sets.
<details>
<summary>RHLP</summary>

Let's select a RHLP model for the following time series **Y**:
Let's select a RHLP model for the following time series:

```{r, message = FALSE}
data("univtoydataset")
Expand All @@ -331,7 +330,7 @@ selectedrhlp$plot(what = "estimatedsignal")
<details>
<summary>HMMR</summary>

Let's select a HMMR model for the following time series **Y**:
Let's select a HMMR model for the following time series:

```{r, message = FALSE}
data("univtoydataset")
Expand All @@ -352,7 +351,7 @@ selectedhmmr$plot(what = "smoothed")
<details>
<summary>MRHLP</summary>

Let's select a MRHLP model for the following multivariate time series **Y**:
Let's select a MRHLP model for the following multivariate time series:

<br />

Expand All @@ -374,7 +373,7 @@ selectedmrhlp$plot(what = "estimatedsignal")
<details>
<summary>MHMMR</summary>

Let's select a MHMMR model for the following multivariate time series **Y**:
Let's select a MHMMR model for the following multivariate time series:

```{r}
data("multivtoydataset")
Expand Down

0 comments on commit 1cf1d80

Please sign in to comment.