Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/rjdverse/rjd3toolkit int…
Browse files Browse the repository at this point in the history
…o develop

# Conflicts:
#	.gitignore
#	R/modellingcontext.R
#	README.Rmd
#	README.md
#	man/modelling_context.Rd
  • Loading branch information
palatej committed Jun 28, 2024
2 parents 6df6d30 + 1168721 commit 3391712
Show file tree
Hide file tree
Showing 44 changed files with 1,014 additions and 363 deletions.
2 changes: 1 addition & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ TO_DO
^\.github$
.DS_Store
^reconf\.sh$
^rjd3toolkit-java-deps\.xml$
^pom\.xml$
57 changes: 54 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,58 @@
.Rproj.user
# History files
.Rhistory
.Rapp.history

# Session Data files
.RData
.RDataTmp

# User-specific files
.Ruserdata

TO_DO
docs
# Example code in package build process
*-Ex.R

# Output files from R CMD build
/*.tar.gz

# Output files from R CMD check
/*.Rcheck/

# RStudio files
.Rproj.user/

# produced vignettes
vignettes/*.html
vignettes/*.pdf
Meta/
inst/doc/
doc/

# OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3
.httr-oauth

# knitr and R markdown default cache directories
*_cache/
/cache/

# Temporary files created by R markdown
*.utf8.md
*.knit.md

# R Environment Variables
.Renviron

# pkgdown site
docs/

# translation temp files
po/*~

# RStudio Connect folder
rsconnect/

# Hidden file from mac-os
.DS_Store

# produced README.html
README.html
8 changes: 2 additions & 6 deletions .lintr
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
linters: linters_with_defaults(
indentation_linter = NULL,
trailing_blank_lines_linter = NULL,
trailing_whitespace_linter = NULL,
assignment_linter = NULL,
whitespace_linter = NULL,
brace_linter = NULL,
infix_spaces_linter = NULL,
paren_body_linter = NULL,
Expand All @@ -12,9 +9,8 @@ linters: linters_with_defaults(
spaces_left_parentheses_linter = NULL,
commas_linter = NULL,
quotes_linter = NULL,
spaces_inside_linter = NULL,
vector_logic_linter = NULL,
seq_linter = NULL,
#spaces_inside_linter = NULL,
#vector_logic_linter = NULL,
object_length_linter = NULL,
semicolon_linter = NULL,
cyclocomp_linter = NULL,
Expand Down
48 changes: 24 additions & 24 deletions R/arima.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ NULL
#' @return A `"JD3_SARIMA"` model.
#' @export
sarima_model<-function(name="sarima", period, phi=NULL, d=0, theta=NULL, bphi=NULL, bd=0, btheta=NULL){
return (structure(
return(structure(
list(name = name, period = period, phi = phi, d = d, theta = theta,
bphi = bphi, bd = bd, btheta = btheta), class="JD3_SARIMA"))
}
Expand All @@ -35,7 +35,7 @@ sarima_properties<-function(model, nspectrum=601, nacf=36){
jmodel<-.r2jd_sarima(model)
spectrum<-.jcall("jdplus/toolkit/base/r/arima/SarimaModels", "[D", "spectrum", jmodel, as.integer(nspectrum))
acf<-.jcall("jdplus/toolkit/base/r/arima/SarimaModels", "[D", "acf", jmodel, as.integer(nacf))
return (list(acf=acf, spectrum=spectrum))
return(list(acf=acf, spectrum=spectrum))
}


Expand All @@ -58,7 +58,7 @@ sarima_properties<-function(model, nspectrum=601, nacf=36){
sarima_random<-function(model, length, stde=1, tdegree=0, seed=-1){
if (!inherits(model, "JD3_SARIMA"))
stop("Invalid model")
return (.jcall("jdplus/toolkit/base/r/arima/SarimaModels", "[D", "random",
return(.jcall("jdplus/toolkit/base/r/arima/SarimaModels", "[D", "random",
as.integer(length),
as.integer(model$period),
.jarray(as.numeric(model$phi)),
Expand Down Expand Up @@ -91,8 +91,8 @@ sarima_decompose<-function(model, rmod=0, epsphi=0){
jmodel<-.r2jd_sarima(model)
jucm<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "Ljdplus/toolkit/base/core/ucarima/UcarimaModel;", "decompose",
jmodel, as.numeric(rmod), as.numeric(epsphi))
if (is.jnull(jucm)) return (NULL)
return (.jd2r_ucarima(jucm))
if (is.jnull(jucm)) return(NULL)
return(.jd2r_ucarima(jucm))

}

Expand All @@ -109,25 +109,25 @@ sarima_decompose<-function(model, rmod=0, epsphi=0){
#'
#' @examples
arima_model<-function(name="arima", ar=1, delta=1, ma=1, variance=1){
return (structure(list(name=name, ar=ar, delta=delta, ma=ma, var=variance), class="JD3_ARIMA"))
return(structure(list(name=name, ar=ar, delta=delta, ma=ma, var=variance), class="JD3_ARIMA"))
}

.jd2r_doubleseq<-function(jobj, jprop){
jseq<-.jcall(jobj, "Ljdplus/toolkit/base/api/data/DoubleSeq;", jprop)
return (.jcall(jseq, "[D", "toArray"))
return(.jcall(jseq, "[D", "toArray"))
}


.jd2r_sarima<-function(jsarima){
q<-.jcall("jdplus/toolkit/base/r/arima/SarimaModels", "[B", "toBuffer", jsarima)
rq<-RProtoBuf::read(modelling.SarimaModel, q)
return (.p2r_sarima(rq))
return(.p2r_sarima(rq))
}

#' @export
#' @rdname jd3_utilities
.r2jd_sarima<-function(model){
return (.jcall("jdplus/toolkit/base/r/arima/SarimaModels", "Ljdplus/toolkit/base/core/sarima/SarimaModel;", "of",
return(.jcall("jdplus/toolkit/base/r/arima/SarimaModels", "Ljdplus/toolkit/base/core/sarima/SarimaModel;", "of",
as.integer(model$period),
.jarray(as.numeric(model$phi)),
as.integer(model$d),
Expand All @@ -142,11 +142,11 @@ arima_model<-function(name="arima", ar=1, delta=1, ma=1, variance=1){
.jd2r_arima<-function(jarima){
q<-.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "[B", "toBuffer", jarima)
rq<-RProtoBuf::read(modelling.ArimaModel, q)
return (.p2r_arima(rq))
return(.p2r_arima(rq))
}

.r2jd_arima<-function(model){
return (.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "Ljdplus/toolkit/base/core/arima/ArimaModel;", "of",
return(.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "Ljdplus/toolkit/base/core/arima/ArimaModel;", "of",
.jarray(as.numeric(model$ar)),
.jarray(as.numeric(model$delta)),
.jarray(as.numeric(model$ma)),
Expand Down Expand Up @@ -176,13 +176,13 @@ arima_model<-function(name="arima", ar=1, delta=1, ma=1, variance=1){
#' @export
arima_sum<-function(...){
components<-list(...)
return (arima_lsum(components))
return(arima_lsum(components))
}

arima_lsum<-function(components){
q<-.jarray(lapply(components, .r2jd_arima), "jdplus/toolkit/base/core/arima/ArimaModel")
jsum<-.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "Ljdplus/toolkit/base/core/arima/ArimaModel;", "sum", q)
return (.jd2r_arima(jsum))
return(.jd2r_arima(jsum))
}

#' Remove an arima model from an existing one
Expand All @@ -205,7 +205,7 @@ arima_difference<-function(left, right, simplify=TRUE){
jleft<-.r2jd_arima(left)
jright<-.r2jd_arima(right)
jdiff<-.jcall(jleft, "Ljdplus/toolkit/base/core/arima/ArimaModel;", "minus", jright, as.logical(simplify))
return (.jd2r_arima(jdiff))
return(.jd2r_arima(jdiff))
}


Expand All @@ -223,7 +223,7 @@ arima_properties<-function(model, nspectrum=601, nacf=36){
jmodel<-.r2jd_arima(model)
spectrum<-.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "[D", "spectrum", jmodel, as.integer(nspectrum))
acf<-.jcall("jdplus/toolkit/base/r/arima/ArimaModels", "[D", "acf", jmodel, as.integer(nacf))
return (list(acf=acf, spectrum=spectrum))
return(list(acf=acf, spectrum=spectrum))
}

#' Title
Expand All @@ -242,24 +242,24 @@ ucarima_model<-function(model=NULL, components, complements=NULL, checkmodel=FAL
else if (! is(model, "JD3_ARIMA") && ! is(model, "JD3_SARIMA")) stop("Invalid model")

# TODO: checkmodel
return (structure(list(model=model, components=components, complements=complements), class="JD3_UCARIMA"))
return(structure(list(model=model, components=components, complements=complements), class="JD3_UCARIMA"))
}

.r2jd_ucarima<-function(ucm){
jmodel<-.r2jd_arima(ucm$model)
jcmps<-.jarray(lapply(ucm$components, .r2jd_arima), "jdplus/toolkit/base/core/arima/ArimaModel")
return (.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "Ljdplus/toolkit/base/core/ucarima/UcarimaModel;", "of", jmodel, jcmps))
return(.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "Ljdplus/toolkit/base/core/ucarima/UcarimaModel;", "of", jmodel, jcmps))
}

#' @export
#' @rdname jd3_utilities
.jd2r_ucarima<-function(jucm){
# model<-.jcall(jucm, "Ljdplus/toolkit/base/core/arima/ArimaModel;", "sum")
# jcmps<-.jcall(jucm, "[Ljdplus/toolkit/base/core/arima/ArimaModel;", "getComponents")
# return (ucarima_model(.jd2r_arima(model), lapply(jcmps, .jd2r_arima)))
# return(ucarima_model(.jd2r_arima(model), lapply(jcmps, .jd2r_arima)))
q<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "[B", "toBuffer", jucm)
rq<-RProtoBuf::read(modelling.UcarimaModel, q)
return (.p2r_ucarima(rq))
return(.p2r_ucarima(rq))
}


Expand All @@ -284,7 +284,7 @@ ucarima_wk<-function(ucm, cmp, signal=TRUE, nspectrum=601, nwk=300){
wk<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "[D", "filter", jwk, as.integer(nwk))
gain<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "[D", "gain", jwk, as.integer(nspectrum))

return (structure(list(spectrum=spectrum, filter=wk, gain2=gain*gain), class="JD3_UCARIMA_WK"))
return(structure(list(spectrum=spectrum, filter=wk, gain2=gain*gain), class="JD3_UCARIMA_WK"))
}

#' Title
Expand All @@ -300,7 +300,7 @@ ucarima_canonical<-function(ucm, cmp=0, adjust=TRUE){
jucm<-.r2jd_ucarima(ucm)
jnucm<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "Ljdplus/toolkit/base/core/ucarima/UcarimaModel;", "doCanonical",
jucm, as.integer(cmp-1), as.logical(adjust))
return (.jd2r_ucarima(jnucm))
return(.jd2r_ucarima(jnucm))
}

#' Estimate UCARIMA Model
Expand All @@ -317,7 +317,7 @@ ucarima_estimate<-function(x, ucm, stdev=TRUE){
jucm<-.r2jd_ucarima(ucm)
jcmps<-.jcall("jdplus/toolkit/base/r/arima/UcarimaModels", "Ljdplus/toolkit/base/api/math/matrices/Matrix;", "estimate",
as.numeric(x), jucm, as.logical(stdev))
return (.jd2r_matrix(jcmps))
return(.jd2r_matrix(jcmps))
}

#' Estimate SARIMA Model
Expand Down Expand Up @@ -373,7 +373,7 @@ sarima_estimate<-function(x, order=c(0,0,0), seasonal = list(order=c(0,0,0), per
sprintf("btheta(%i)", seq_len(seasonal$order[3])))
res$orders <- list(order = order, seasonal = seasonal)
class(res) <- c("JD3_SARIMA_ESTIMATE", "JD3_REGARIMA_RSLTS")
return (res)
return(res)
}

#' Title
Expand Down Expand Up @@ -402,5 +402,5 @@ sarima_hannan_rissanen<-function(x, order=c(0,0,0), seasonal = list(order=c(0,0,
seasonal$period <- frequency(x)
jmodel<-.jcall("jdplus/toolkit/base/r/arima/SarimaModels", "Ljdplus/toolkit/base/core/sarima/SarimaModel;", "hannanRissanen",
as.numeric(x), as.integer(order), as.integer(seasonal$period), as.integer(seasonal$order), as.character(initialization), as.logical(biasCorrection), as.logical(finalCorrection))
return (.jd2r_sarima(jmodel))
return(.jd2r_sarima(jmodel))
}
Loading

0 comments on commit 3391712

Please sign in to comment.