Skip to content

Commit

Permalink
Format workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
doccstat committed Aug 25, 2023
1 parent 977b8b6 commit 25ae79d
Show file tree
Hide file tree
Showing 9 changed files with 530 additions and 493 deletions.
84 changes: 42 additions & 42 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,35 @@
# Generated by using Rcpp::compileAttributes() -> do not edit by hand
# Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393

#' Function to calculate the gradient at the current data.
#' This function is not meant to be called directly by the user.
#'
#' @param data A data frame containing the data to be segmented.
#' @param theta Estimated theta from the previous iteration.
#' @param family Family of the model.
#' @keywords internal
#'
#' @noRd
#' @return Gradient at the current data.
cost_update_gradient <- function(data, theta, family) {
.Call(`_fastcpd_cost_update_gradient`, data, theta, family)
}

#' Function to calculate the Hessian matrix at the current data.
#' This function is not meant to be called directly by the user.
#'
#' @param data A data frame containing the data to be segmented.
#' @param theta Estimated theta from the previous iteration.
#' @param family Family of the model.
#' @param min_prob Minimum probability to avoid numerical issues.
#' @keywords internal
#'
#' @noRd
#' @return Hessian at the current data.
cost_update_hessian <- function(data, theta, family, min_prob) {
.Call(`_fastcpd_cost_update_hessian`, data, theta, family, min_prob)
}

#' Update the cost values for the segmentation.
#' This function is not meant to be called directly by the user.
#'
Expand Down Expand Up @@ -36,33 +65,26 @@ cost_update <- function(data, theta_hat, theta_sum, hessian, tau, i, k, family,
.Call(`_fastcpd_cost_update`, data, theta_hat, theta_sum, hessian, tau, i, k, family, momentum, momentum_coef, epsilon, min_prob, winsorise_minval, winsorise_maxval, lambda, cost_gradient, cost_hessian)
}

#' Function to calculate the gradient at the current data.
#' This function is not meant to be called directly by the user.
#'
#' @param data A data frame containing the data to be segmented.
#' @param theta Estimated theta from the previous iteration.
#' @param family Family of the model.
#' @keywords internal
#'
#' @noRd
#' @return Gradient at the current data.
cost_update_gradient <- function(data, theta, family) {
.Call(`_fastcpd_cost_update_gradient`, data, theta, family)
}

#' Function to calculate the Hessian matrix at the current data.
#' Solve logistic/poisson regression using Gradient Descent Extension to the
#' multivariate case
#' This function is not meant to be called directly by the user.
#'
#' @param data A data frame containing the data to be segmented.
#' @param theta Estimated theta from the previous iteration.
#' @param theta Estimate of the parameters. If null, the function will estimate
#' the parameters.
#' @param family Family of the model.
#' @param min_prob Minimum probability to avoid numerical issues.
#' @param lambda Lambda for L1 regularization. Only used for lasso.
#' @param cv Whether to perform cross-validation to find the best lambda.
#' @param start Starting point for the optimization for warm start.
#' @keywords internal
#' @importFrom glmnet glmnet cv.glmnet predict.glmnet
#' @importFrom fastglm fastglm
#'
#' @noRd
#' @return Hessian at the current data.
cost_update_hessian <- function(data, theta, family, min_prob) {
.Call(`_fastcpd_cost_update_hessian`, data, theta, family, min_prob)
#' @return Negative log likelihood of the corresponding data with the given
#' family.
negative_log_likelihood <- function(data, theta, family, lambda, cv = FALSE, start = NULL) {
.Call(`_fastcpd_negative_log_likelihood`, data, theta, family, lambda, cv, start)
}

#' Vanilla PELT implementation.
Expand Down Expand Up @@ -98,25 +120,3 @@ fastcpd_vanilla <- function(data, beta, segment_count, trim, momentum_coef, k, f
.Call(`_fastcpd_fastcpd_vanilla`, data, beta, segment_count, trim, momentum_coef, k, family, epsilon, min_prob, winsorise_minval, winsorise_maxval, p, cost, cp_only)
}

#' Solve logistic/poisson regression using Gradient Descent Extension to the
#' multivariate case
#' This function is not meant to be called directly by the user.
#'
#' @param data A data frame containing the data to be segmented.
#' @param theta Estimate of the parameters. If null, the function will estimate
#' the parameters.
#' @param family Family of the model.
#' @param lambda Lambda for L1 regularization. Only used for lasso.
#' @param cv Whether to perform cross-validation to find the best lambda.
#' @param start Starting point for the optimization for warm start.
#' @keywords internal
#' @importFrom glmnet glmnet cv.glmnet predict.glmnet
#' @importFrom fastglm fastglm
#'
#' @noRd
#' @return Negative log likelihood of the corresponding data with the given
#' family.
negative_log_likelihood <- function(data, theta, family, lambda, cv = FALSE, start = NULL) {
.Call(`_fastcpd_negative_log_likelihood`, data, theta, family, lambda, cv, start)
}

74 changes: 37 additions & 37 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,33 @@ Rcpp::Rostream<true>& Rcpp::Rcout = Rcpp::Rcpp_cout_get();
Rcpp::Rostream<false>& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get();
#endif

// cost_update_gradient
arma::colvec cost_update_gradient(arma::mat data, arma::colvec theta, std::string family);
RcppExport SEXP _fastcpd_cost_update_gradient(SEXP dataSEXP, SEXP thetaSEXP, SEXP familySEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< arma::mat >::type data(dataSEXP);
Rcpp::traits::input_parameter< arma::colvec >::type theta(thetaSEXP);
Rcpp::traits::input_parameter< std::string >::type family(familySEXP);
rcpp_result_gen = Rcpp::wrap(cost_update_gradient(data, theta, family));
return rcpp_result_gen;
END_RCPP
}
// cost_update_hessian
arma::mat cost_update_hessian(arma::mat data, arma::colvec theta, std::string family, double min_prob);
RcppExport SEXP _fastcpd_cost_update_hessian(SEXP dataSEXP, SEXP thetaSEXP, SEXP familySEXP, SEXP min_probSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< arma::mat >::type data(dataSEXP);
Rcpp::traits::input_parameter< arma::colvec >::type theta(thetaSEXP);
Rcpp::traits::input_parameter< std::string >::type family(familySEXP);
Rcpp::traits::input_parameter< double >::type min_prob(min_probSEXP);
rcpp_result_gen = Rcpp::wrap(cost_update_hessian(data, theta, family, min_prob));
return rcpp_result_gen;
END_RCPP
}
// cost_update
Rcpp::List cost_update(const arma::mat data, arma::mat theta_hat, arma::mat theta_sum, arma::cube hessian, const int tau, const int i, Rcpp::Function k, const std::string family, arma::colvec momentum, const double momentum_coef, const double epsilon, const double min_prob, const double winsorise_minval, const double winsorise_maxval, const double lambda, Rcpp::Function cost_gradient, Rcpp::Function cost_hessian);
RcppExport SEXP _fastcpd_cost_update(SEXP dataSEXP, SEXP theta_hatSEXP, SEXP theta_sumSEXP, SEXP hessianSEXP, SEXP tauSEXP, SEXP iSEXP, SEXP kSEXP, SEXP familySEXP, SEXP momentumSEXP, SEXP momentum_coefSEXP, SEXP epsilonSEXP, SEXP min_probSEXP, SEXP winsorise_minvalSEXP, SEXP winsorise_maxvalSEXP, SEXP lambdaSEXP, SEXP cost_gradientSEXP, SEXP cost_hessianSEXP) {
Expand Down Expand Up @@ -38,30 +65,19 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// cost_update_gradient
arma::colvec cost_update_gradient(arma::mat data, arma::colvec theta, std::string family);
RcppExport SEXP _fastcpd_cost_update_gradient(SEXP dataSEXP, SEXP thetaSEXP, SEXP familySEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< arma::mat >::type data(dataSEXP);
Rcpp::traits::input_parameter< arma::colvec >::type theta(thetaSEXP);
Rcpp::traits::input_parameter< std::string >::type family(familySEXP);
rcpp_result_gen = Rcpp::wrap(cost_update_gradient(data, theta, family));
return rcpp_result_gen;
END_RCPP
}
// cost_update_hessian
arma::mat cost_update_hessian(arma::mat data, arma::colvec theta, std::string family, double min_prob);
RcppExport SEXP _fastcpd_cost_update_hessian(SEXP dataSEXP, SEXP thetaSEXP, SEXP familySEXP, SEXP min_probSEXP) {
// negative_log_likelihood
Rcpp::List negative_log_likelihood(arma::mat data, Rcpp::Nullable<arma::colvec> theta, std::string family, double lambda, bool cv, Rcpp::Nullable<arma::colvec> start);
RcppExport SEXP _fastcpd_negative_log_likelihood(SEXP dataSEXP, SEXP thetaSEXP, SEXP familySEXP, SEXP lambdaSEXP, SEXP cvSEXP, SEXP startSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< arma::mat >::type data(dataSEXP);
Rcpp::traits::input_parameter< arma::colvec >::type theta(thetaSEXP);
Rcpp::traits::input_parameter< Rcpp::Nullable<arma::colvec> >::type theta(thetaSEXP);
Rcpp::traits::input_parameter< std::string >::type family(familySEXP);
Rcpp::traits::input_parameter< double >::type min_prob(min_probSEXP);
rcpp_result_gen = Rcpp::wrap(cost_update_hessian(data, theta, family, min_prob));
Rcpp::traits::input_parameter< double >::type lambda(lambdaSEXP);
Rcpp::traits::input_parameter< bool >::type cv(cvSEXP);
Rcpp::traits::input_parameter< Rcpp::Nullable<arma::colvec> >::type start(startSEXP);
rcpp_result_gen = Rcpp::wrap(negative_log_likelihood(data, theta, family, lambda, cv, start));
return rcpp_result_gen;
END_RCPP
}
Expand Down Expand Up @@ -89,31 +105,15 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// negative_log_likelihood
Rcpp::List negative_log_likelihood(arma::mat data, Rcpp::Nullable<arma::colvec> theta, std::string family, double lambda, bool cv, Rcpp::Nullable<arma::colvec> start);
RcppExport SEXP _fastcpd_negative_log_likelihood(SEXP dataSEXP, SEXP thetaSEXP, SEXP familySEXP, SEXP lambdaSEXP, SEXP cvSEXP, SEXP startSEXP) {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
Rcpp::traits::input_parameter< arma::mat >::type data(dataSEXP);
Rcpp::traits::input_parameter< Rcpp::Nullable<arma::colvec> >::type theta(thetaSEXP);
Rcpp::traits::input_parameter< std::string >::type family(familySEXP);
Rcpp::traits::input_parameter< double >::type lambda(lambdaSEXP);
Rcpp::traits::input_parameter< bool >::type cv(cvSEXP);
Rcpp::traits::input_parameter< Rcpp::Nullable<arma::colvec> >::type start(startSEXP);
rcpp_result_gen = Rcpp::wrap(negative_log_likelihood(data, theta, family, lambda, cv, start));
return rcpp_result_gen;
END_RCPP
}

RcppExport SEXP run_testthat_tests(void *);

static const R_CallMethodDef CallEntries[] = {
{"_fastcpd_cost_update", (DL_FUNC) &_fastcpd_cost_update, 17},
{"_fastcpd_cost_update_gradient", (DL_FUNC) &_fastcpd_cost_update_gradient, 3},
{"_fastcpd_cost_update_hessian", (DL_FUNC) &_fastcpd_cost_update_hessian, 4},
{"_fastcpd_fastcpd_vanilla", (DL_FUNC) &_fastcpd_fastcpd_vanilla, 14},
{"_fastcpd_cost_update", (DL_FUNC) &_fastcpd_cost_update, 17},
{"_fastcpd_negative_log_likelihood", (DL_FUNC) &_fastcpd_negative_log_likelihood, 6},
{"_fastcpd_fastcpd_vanilla", (DL_FUNC) &_fastcpd_fastcpd_vanilla, 14},
{"run_testthat_tests", (DL_FUNC) &run_testthat_tests, 1},
{NULL, NULL, 0}
};
Expand Down
134 changes: 0 additions & 134 deletions src/cost_update.cc

This file was deleted.

30 changes: 0 additions & 30 deletions src/cost_update_gradient.cc

This file was deleted.

Loading

0 comments on commit 25ae79d

Please sign in to comment.