R/RcppExports.R

Defines functions call_not_r_wrapper exhaust_sc setBitNumber get_local_costs comb_contains_cpt numberOfSetBits is_child next_bit_permutation start_bit_permutations extract_sub get_comb_ind

# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Get integer vector of changepoint indices,
#' based on bool-field representation of combinations.
#' E.g. for combination index 11 [=1011]: get_comb_ind(c(T,F,T,T))=11
#' @keywords internal
#' @noRd
get_comb_ind <- function(active) {
    .Call(`_breakfast_get_comb_ind`, active)
}

#' Helping function for algorithm 2: Pre-compute the partial sums
#' S_i = sum{j=k_i+1}^{k_{i+1}}x_i and the partial sums of squared
#' T_i = sum{j=k_i+1}^{k_{i+1}}x_i^2
#' between the (sorted) candidates k_i and k_{i+1} in cand.
#' Output: data frame with 4 columns k_i | k_{i+1} | S_i | T_i
#' @keywords internal
#' @noRd
extract_sub <- function(cand, x) {
    .Call(`_breakfast_extract_sub`, cand, x)
}

#' Starting value to iterate (in lexicographical order) 
#' over all bit permutaions having l bits set to 1.
#' E.g.: start_bit_permutations(2) = 3 [=0..011].
#' @keywords internal
#' @noRd
start_bit_permutations <- function(l) {
    .Call(`_breakfast_start_bit_permutations`, l)
}

#' Next value to iterate (in lexicographical order) over all bit 
#' permutaions having l bits set to 1.
#' Example sequence (2 bits): {0011, 0101, 0110, 1001, 1010, 1100}.
#' Source: https://stackoverflow.com/questions/1851134/generate-all-binary-strings-of-length-n-with-k-bits-set
#' @keywords internal
#' @noRd
next_bit_permutation <- function(v) {
    .Call(`_breakfast_next_bit_permutation`, v)
}

#' Is index i_child a child of index i_parent?
#' ASSERT: i_child is of the form (i_parent XOR i_help),
#'         with i_help having exactly one non-zero bit
#' @keywords internal
#' @noRd
is_child <- function(i_child, i_parent) {
    .Call(`_breakfast_is_child`, i_child, i_parent)
}

#' Get number of non-zero bits of a 32bit integer
#' Source: https://stackoverflow.com/questions/109023/how-to-count-the-number-of-set-bits-in-a-32-bit-integer
#' @keywords internal
#' @noRd
numberOfSetBits <- function(i) {
    .Call(`_breakfast_numberOfSetBits`, i)
}

#' Does the combination comb of changepoints contain the changepoint k_ind?
#' @keywords internal
#' @noRd
comb_contains_cpt <- function(comb, k_ind) {
    .Call(`_breakfast_comb_contains_cpt`, comb, k_ind)
}

#' Compute the Local cost terms of combination icomb (for RSS resp. sBIC).
#' Use pre-computed partial sum matrix sub_sums (see extract_sub) for speedup
#' @keywords internal
#' @noRd
get_local_costs <- function(icomb, sub_sums) {
    .Call(`_breakfast_get_local_costs`, icomb, sub_sums)
}

#' where is leftmost one?
#' https://www.geeksforgeeks.org/find-significant-set-bit-number/
#' @keywords internal
#' @noRd
setBitNumber <- function(n) {
    .Call(`_breakfast_setBitNumber`, n)
}

#' Algorithm II (Local change-point search with SC)
#' 
#' Input cand: =mathcal D, conflicting changepoints candidate set
#' Input sub_sums: Pre-computed partial sums, as obtained by extract_sub
#' Input strength: Exponent for penalty
#' Input log_penalty: log (or polynomial) penalty term?
#' Input n: Overall length of data
#' Input auc: =|mathcal C|, total number of currently active changepoints 
#'       (+candidates)
#' Input min_cost: Minimal RSS with all the candidates
#' 
#' Output sc: (Mx2) matrix (M=2^m with m=|cand|) containing RSS/cost and SC
#'         terms for all combinations within cand. Combinations are indexed
#'         by their implicit integer representation, i.e. sc[0,] corresponds
#'         to the empty set, sc[3,] to {k_1,k_2} [0..011], etc.
#'         Note: Row May be Inf, if combination was not visited in algorithm.
#' Output est_cpts: Integer Vector of estimated changepoints
#' Output final: Bool Vector indicating if combinations are final states
#' Output num_cpts: For debugging purposes
#' @keywords internal
#' @noRd
exhaust_sc <- function(cand, sub_sums, strength, log_penalty, n, auc, min_cost) {
    .Call(`_breakfast_exhaust_sc`, cand, sub_sums, strength, log_penalty, n, auc, min_cost)
}

#' @keywords internal
#' @noRd
call_not_r_wrapper <- function(x, intervals, method, contrast_type, parallel, augmented) {
    .Call(`_breakfast_call_not_r_wrapper`, x, intervals, method, contrast_type, parallel, augmented)
}

Try the breakfast package in your browser

Any scripts or data that you put into this service are public.

breakfast documentation built on Oct. 18, 2022, 5:08 p.m.