Skip to content

Commit

Permalink
Merge pull request #2 from oelhammouchi/develop
Browse files Browse the repository at this point in the history
Tweak some more CRAN things and add requirement for Fortran 2003
  • Loading branch information
oelhammouchi authored May 9, 2024
2 parents f7e06ae + 0a2f87e commit ab54bb5
Show file tree
Hide file tree
Showing 10 changed files with 90 additions and 47 deletions.
44 changes: 23 additions & 21 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,42 +1,44 @@
Package: trngl
Type: Package
Package: trngl
Title: Bootstrap Simulations for Claims Reserving Models
Version: 0.1.0
Date: 2023-02-08
Authors@R: c(
Authors@R:
person("Othman", "El Hammouchi", , "[email protected]", role = c("aut", "cph", "cre"))
)
Description: Check the assumptions of popular actuarial reserving models against a given claims triangle using
efficient parallel bootstrap simulations. Various simulation configurations are supported for the Mack and ODP models.
Facilities are provided for visualising the results and flagging suspicious observations.
Description: Check the assumptions of popular actuarial reserving models
against a given claims triangle using efficient parallel bootstrap
simulations. Various simulation configurations are supported for the
Mack and overdispersed Poisson models. Facilities are provided for visualising the
results and flagging suspicious observations.
License: MIT + file LICENSE
Depends: R (>= 3.5.0)
Depends:
R (>= 3.5.0)
Imports:
rTRNG (>= 4.23.1.2),
ChainLadder (>= 0.2.18),
cli (>= 3.6.2),
ggplot2 (>= 3.5.1),
ggrepel (>= 0.9.5),
reshape2 (>= 1.4.4),
rlang (>= 1.1.3),
cli (>= 3.6.2)
LinkingTo:
Rcpp (>= 0.11.0),
RcppArmadillo (>= 0.12.8.2.1),
BH (>= 1.84.0.0),
rTRNG (>= 4.23.1.2),
RcppProgress (>= 0.4.2)
rTRNG (>= 4.23.1.2)
Suggests:
covr,
testthat (>= 3.0.0),
withr (>= 3.0.0)
LazyData: true
LinkingTo:
BH (>= 1.84.0.0),
Rcpp (>= 0.11.0),
RcppArmadillo (>= 0.12.8.2.1),
RcppProgress (>= 0.4.2),
rTRNG (>= 4.23.1.2)
Config/testthat/edition: 3
Config/testthat/parallel: true
Encoding: UTF-8
RoxygenNote: 7.2.3
Roxygen: list(load = "source", old_usage = TRUE, markdown = TRUE)
LazyData: true
NeedsCompilation: yes
Packaged: 2023-02-26 18:07:38 UTC; othman
Config/testthat/edition: 3
Config/testthat/parallel: true
Roxygen: list(load = "source", old_usage = TRUE, markdown = TRUE)
RoxygenNote: 7.2.3
SystemRequirements: Fortran 2003
Collate:
'RcppExports.R'
'boot_res.R'
Expand Down
6 changes: 0 additions & 6 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ S3method(plot,single)
S3method(print,mack)
S3method(print,odp)
S3method(print,trngl)
export(.mackPairsBoot)
export(.mackPairsSim)
export(.mackParamBoot)
export(.mackParamSim)
export(.mackResidBoot)
export(.mackResidSim)
export(UKMotor)
export(as.trngl)
export(cum2incr)
Expand Down
6 changes: 0 additions & 6 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,26 @@ getTrnglSeed <- function() {
.Call('_trngl_getTrnglSeed', PACKAGE = 'trngl')
}

#' @export
.mackParamBoot <- function(trngl, dist, cond, n_boot = 1e3L, n_sim = 1e3L, progress = TRUE) {
.Call('_trngl_mackParamBoot', PACKAGE = 'trngl', trngl, dist, cond, n_boot, n_sim, progress)
}

#' @export
.mackResidBoot <- function(trngl, resid_type, cond, n_boot = 1e3L, n_sim = 1e3L, progress = TRUE) {
.Call('_trngl_mackResidBoot', PACKAGE = 'trngl', trngl, resid_type, cond, n_boot, n_sim, progress)
}

#' @export
.mackPairsBoot <- function(trngl, n_boot = 1e3L, n_sim = 1e3L, progress = TRUE) {
.Call('_trngl_mackPairsBoot', PACKAGE = 'trngl', trngl, n_boot, n_sim, progress)
}

#' @export
.mackPairsSim <- function(trngl, sim_type, n_boot, n_sim, progress) {
.Call('_trngl_mackPairsSim', PACKAGE = 'trngl', trngl, sim_type, n_boot, n_sim, progress)
}

#' @export
.mackParamSim <- function(trngl, sim_type, cond, dist, n_boot, n_sim, progress) {
.Call('_trngl_mackParamSim', PACKAGE = 'trngl', trngl, sim_type, cond, dist, n_boot, n_sim, progress)
}

#' @export
.mackResidSim <- function(trngl, sim_type, cond, resid_type, n_boot, n_sim, progress) {
.Call('_trngl_mackResidSim', PACKAGE = 'trngl', trngl, sim_type, cond, resid_type, n_boot, n_sim, progress)
}
Expand Down
42 changes: 42 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/usr/bin/env sh

cat <<EOF > test-f03.f90
module mod_test
implicit none
type t_test
integer :: test_field
contains
procedure :: set_test_field
end type t_test
contains
subroutine set_test_field(this, val)
class(t_test) :: this
integer :: val
this%test_field = val
end subroutine set_test_field
end module mod_test
program test
use mod_test
implicit none
type(t_test) :: test_var
call test_var%set_test_field(0)
end program test
EOF

if ! "${R_HOME}"/bin/R CMD SHLIB test-f03.f90; then
echo "*********************************************************************************"
echo "Your Fortran compiler does not appear to support all features of the 2003"
echo "standard. Please install a compatible compiler, set this in your ~/.R/Makevars"
echo "and try again."
echo "*********************************************************************************"

exit 1
fi

rm -f test-f03.* mod_test.*
13 changes: 13 additions & 0 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
## Resubmission

* Spelled out "ODP" as "overdispersed Poisson".

* Removed erroneous export of internal package functions.

* Removed the "Date" field in DESCRIPTION.

* Added Fortran 2003 to "SystemRequirements" as well as a configure script that
checks whether the compiler supports this standard.

* Remove erroneously included "Rplots.pdf".

## R CMD check results

0 errors | 0 warnings | 1 note
Expand Down
13 changes: 8 additions & 5 deletions inst/include/mask.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Mask {
Mask(int n_row, int n_col) : n_row_(n_row), n_col_(n_col) {
data_ = new bool[n_row * n_col];

// column major
for (int i = 0; i < n_row; i++) {
for (int j = 0; j < n_col; j++) {
if (j >= n_col - i) {
Expand All @@ -16,15 +17,17 @@ class Mask {
}
}
};

Mask(int n_dev) : Mask(n_dev, n_dev){};
~Mask() { delete[] data_; }

bool* begin() { return data_; }
int n_row() { return n_row_; }
int n_col() { return n_col_; }
int size() { return n_row_ * n_col_; }
int n_row() const { return n_row_; }
int n_col() const { return n_col_; }
int size() const { return n_row_ * n_col_; }

bool& operator()(int i, int j) { return data_[i + j * n_row_]; }
bool get(int i, int j) const { return data_[i + j * n_row_]; }

class RowProxy {
public:
Expand Down Expand Up @@ -70,10 +73,10 @@ class Mask {
}
}

friend std::ostream& operator<<(std::ostream& os, Mask& mask) {
friend std::ostream& operator<<(std::ostream& os, const Mask& mask) {
for (int i = 0; i < mask.n_row(); i++) {
for (int j = 0; j < mask.n_col(); j++) {
os << (mask(i, j) ? "T" : "F") << " ";
os << (mask.get(i, j) ? "T" : "F") << " ";
}
os << std::endl;
}
Expand Down
13 changes: 4 additions & 9 deletions src/mack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ void mack_pairs_boot_cpp(int n_dev, double* triangle, int n_boot, int n_sim,
bool* mask, double* reserve, void* pgb);
}

//' @export
// [[Rcpp::export(.mackParamBoot)]]
Rcpp::List mackParamBoot(Rcpp::NumericMatrix trngl, Rcpp::String dist,
bool cond, int n_boot = 1e3, int n_sim = 1e3,
Expand Down Expand Up @@ -60,7 +59,6 @@ Rcpp::List mackParamBoot(Rcpp::NumericMatrix trngl, Rcpp::String dist,
return res;
};

//' @export
// [[Rcpp::export(.mackResidBoot)]]
Rcpp::List mackResidBoot(Rcpp::NumericMatrix trngl, Rcpp::String resid_type,
bool cond, int n_boot = 1e3, int n_sim = 1e3,
Expand Down Expand Up @@ -96,7 +94,6 @@ Rcpp::List mackResidBoot(Rcpp::NumericMatrix trngl, Rcpp::String resid_type,
return res;
};

//' @export
// [[Rcpp::export(.mackPairsBoot)]]
Rcpp::List mackPairsBoot(Rcpp::NumericMatrix trngl, int n_boot = 1e3,
int n_sim = 1e3, bool progress = true) {
Expand Down Expand Up @@ -305,20 +302,20 @@ Rcpp::List mackSim(arma::mat triangle, options::SimType sim_type, int n_boot,
case options::ORIGIN: {
if (progress) {
pb = new CliProgressBar;
pgb = new Progress(n_dev * n_boot * n_sim, true, *pb);
pgb = new Progress((n_dev - 1) * n_boot * n_sim, true, *pb);
} else {
pb = nullptr;
pgb = nullptr;
}

reserves = arma::mat(n_boot * n_sim, n_dev);
reserves = arma::mat(n_boot * n_sim, n_dev - 1);
// clang-format off
#pragma omp parallel for num_threads(n_threads) default(none) \
shared(reserves, pgb, col_mapping_) \
firstprivate(boot_type, mask, triangle, n_boot, n_sim, n_dev) \
firstprivate(dist_type, resid_type, cond, progress)
// clang-format on
for (int i = 0; i < n_dev; i++) {
for (int i = 0; i < n_dev - 1; i++) {
bool abort_check;
if (progress) {
abort_check = !Progress::check_abort();
Expand All @@ -335,6 +332,7 @@ Rcpp::List mackSim(arma::mat triangle, options::SimType sim_type, int n_boot,
Mask mask_in = mask;
mask_in.row(i) = false;
mask_in(i, 0) = true;

if (boot_type == options::PAIRS ||
boot_type == options::PARAM)
mask_in(0, n_dev - 1) = true;
Expand Down Expand Up @@ -387,7 +385,6 @@ Rcpp::List mackSim(arma::mat triangle, options::SimType sim_type, int n_boot,
return res;
};

//' @export
// [[Rcpp::export(.mackPairsSim)]]
Rcpp::List mackPairsSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type,
int n_boot, int n_sim, bool progress) {
Expand All @@ -397,7 +394,6 @@ Rcpp::List mackPairsSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type,
options::Dist::NORMAL, options::STANDARD);
}

//' @export
// [[Rcpp::export(.mackParamSim)]]
Rcpp::List mackParamSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type,
bool cond, Rcpp::String dist, int n_boot, int n_sim,
Expand All @@ -408,7 +404,6 @@ Rcpp::List mackParamSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type,
options::dist_mapping.at(dist), options::STANDARD);
}

//' @export
// [[Rcpp::export(.mackResidSim)]]
Rcpp::List mackResidSim(Rcpp::NumericMatrix trngl, Rcpp::String sim_type,
bool cond, Rcpp::String resid_type, int n_boot,
Expand Down
Binary file modified tests/testthat/_snaps/calendar/sim_calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testthat/_snaps/origin/sim_origin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/testthat/_snaps/single/sim_single.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ab54bb5

Please sign in to comment.