R/RcppExports.R

Defines functions lpoly_make_system_xptr lpoly_model_matrix lpoly_compute_jacobian lpoly_sde lpoly_sde_precached lpoly_sde_averages solve_general_sde solve_implicit_sde solve_implicit_sde_averages

Documented in lpoly_compute_jacobian lpoly_make_system_xptr lpoly_model_matrix lpoly_sde lpoly_sde_averages lpoly_sde_precached solve_general_sde solve_implicit_sde solve_implicit_sde_averages

# This file was generated by Rcpp::compileAttributes
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' LPoly system constructor
#'
#' Returns an XPtr to an lpoly_system_type object
#' @param cm Model coefficient matrix
#' @param trm Model term specification, as generated by lpoly_model_spec (each row represents the powers of the different factors in a term)
#' @export
lpoly_make_system_xptr <- function(cm, trm) {
    .Call('SimpleSDESampler_lpoly_make_system_xptr', PACKAGE = 'SimpleSDESampler', cm, trm)
}

#' LPoly model matrix generator
#'
#' Builds the model matrix from the data using the lpoly_system_type object
#' @param lps XPtr to an lpoly_system_type object created by a call to lpoly_make_system
#' @param data One column per measurement variable
#' @export
lpoly_model_matrix <- function(lps, data) {
    .Call('SimpleSDESampler_lpoly_model_matrix', PACKAGE = 'SimpleSDESampler', lps, data)
}

#' LPoly Jacobian
#'
#' Builds the model matrix from the data using the lpoly_system_type object
#' @param lps XPtr to an lpoly_system_type object created by a call to lpoly_make_system
#' @param state Single row matrix
#' @export
lpoly_compute_jacobian <- function(lps, state) {
    .Call('SimpleSDESampler_lpoly_compute_jacobian', PACKAGE = 'SimpleSDESampler', lps, state)
}

#' LPoly System Implicit SDE Simulator using NLOPT
#'
#' Simulates a trajectory to the SDE specified by *sys* and the noise level sigma, starting at the point start and integrating over times [*from*,*to*] on *steps + 1* time points.
#' @param sys lpoly_system_type XPtr object created with lpoly_make_system
#' @param sigma Amplitude of noise: scalar
#' @param start Initial position: n vector
#' @param from Initial time: scalar
#' @param to Final time: scalar
#' @param steps Number of points to take, s.t. dt = (from - to) / (steps + 1): integer
#' @export
lpoly_sde <- function(sys, sigma, start, from, to, steps, x_tol = 0, algorithm = "LBFGS") {
    .Call('SimpleSDESampler_lpoly_sde', PACKAGE = 'SimpleSDESampler', sys, sigma, start, from, to, steps, x_tol, algorithm)
}

#' LPoly System Implicit SDE Simulator using NLOPT, with precached noise data
#'
#' Simulates a trajectory to the SDE specified by *sys* and the noise level sigma, starting at the point start and integrating over times [*from*,*to*] on *steps + 1* time points.
#' @param sys lpoly_system_type XPtr object created with lpoly_make_system
#' @param noise Noise buffer (brownian motion normalised steps ~N(0,sigma^2))
#' @param start Initial position: n vector
#' @param from Initial time: scalar
#' @param to Final time: scalar
#' @param steps Number of points to take, s.t. dt = (from - to) / (steps + 1): integer
#' @export
lpoly_sde_precached <- function(sys, noise, start, from, to, steps, x_tol = 0, algorithm = "LBFGS") {
    .Call('SimpleSDESampler_lpoly_sde_precached', PACKAGE = 'SimpleSDESampler', sys, noise, start, from, to, steps, x_tol, algorithm)
}

#' LPoly System Implicit SDE Simulator: time-wise averages
#'
#' Samples multiple times from lpoly_sde and returns the time-wise average
#' @param nrep Number of repetitions to average over: integer
#' @param sys lpoly_system_type XPtr object created with lpoly_make_system
#' @param sigma Amplitude of noise: scalar
#' @param start Initial position: n vector
#' @param from Initial time: scalar
#' @param to Final time: scalar
#' @param steps Number of points to take, s.t. dt = (from - to) / (steps + 1): integer
#' @export
lpoly_sde_averages <- function(nrep, sys, sigma, start, from, to, steps) {
    .Call('SimpleSDESampler_lpoly_sde_averages', PACKAGE = 'SimpleSDESampler', nrep, sys, sigma, start, from, to, steps)
}

#' Simulates an SDE explicitly (derivative free)
#' 
#' For an Ito form SDE dx = f(x) dt + g(x) E sqrt(dt)
#' 
#' @param d_det R function representing f(x)
#' @param d_stoch R function representing g(x) E
#' @param start numeric vector with initial state
#' @param from scalar with initial time
#' @param to scalar with final time
#' @param steps number of steps to take
#' @export
solve_general_sde <- function(d_det, d_stoch, start, from, to, steps) {
    .Call('SimpleSDESampler_solve_general_sde', PACKAGE = 'SimpleSDESampler', d_det, d_stoch, start, from, to, steps)
}

#' General implicit SDE simulator
#'
#' @param d_det Deterministic component: an R function: (m x n matrix of m states, scalar time) -> m x n matrix of m time derivatives
#' @param jacobian Jacobian of deterministic component: an R function: (1 x n matrix state, scalar time) -> n x n matrix df_i / du_j
#' @param sigma Amplitude of noise: scalar
#' @param start Initial position: n vector
#' @param from Initial time: scalar
#' @param to Final time: scalar
#' @param steps Number of points to take, s.t. dt = (from - to) / (steps + 1): integer
#' @export
solve_implicit_sde <- function(d_det, jacobian, sigma, start, from, to, steps, x_tol = 0, algorithm = "TNEWTON") {
    .Call('SimpleSDESampler_solve_implicit_sde', PACKAGE = 'SimpleSDESampler', d_det, jacobian, sigma, start, from, to, steps, x_tol, algorithm)
}

#' General implicit SDE simulator: time-wise averages
#'
#' @param nrep Number of repetitions to average over: integer
#' @param d_det Deterministic component: an R function: m x n matrix of m states -> m x n matrix of m time derivatives
#' @param d_stoch Stochastic component: an R function: (1 x n matrix state, scalar time) -> 1 x n matrix state
#' @param jacobian Jacobian of deterministic component: an R function: (n vector state, scalar time) -> n x n matrix df_i / du_j
#' @param sigma Amplitude of noise: scalar
#' @param start Initial position: n vector
#' @param from Initial time: scalar
#' @param to Final time: scalar
#' @param steps Number of points to take, s.t. dt = (from - to) / (steps + 1): integer
#' @export
solve_implicit_sde_averages <- function(nrep, d_det, jacobian, sigma, start, from, to, steps, x_tol = 0, algorithm = "TNEWTON") {
    .Call('SimpleSDESampler_solve_implicit_sde_averages', PACKAGE = 'SimpleSDESampler', nrep, d_det, jacobian, sigma, start, from, to, steps, x_tol, algorithm)
}
rossklin/SimpleSDESampler documentation built on May 27, 2019, 11:37 p.m.