Skip to content

Commit

Permalink
Merge pull request #37 from bhelsel/issue_3536
Browse files Browse the repository at this point in the history
Update C++ code to resolve issues 20, 34-36
  • Loading branch information
bhelsel authored May 20, 2024
2 parents 903a689 + f76d6bd commit b1d1972
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
^codecov\.yml$
^README\.Rmd$
^tests/testthat/test_gcalibrateC\.R$
^man/figures
^man/figures
.vscode/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
.RData
.Ruserdata
.DS_Store
.vscode/
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: agcounts
Type: Package
Title: Calculate 'ActiGraph' Counts from Accelerometer Data
Version: 0.6.7
Version: 0.6.8
Authors@R: c(
person(c("Brian", "C."), "Helsel", email = "[email protected]", role = c("aut", "cre")),
person(c("Paul", "R."), "Hibbing", role = "ctb"),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# agcounts 0.6.8
* Fix issue #20 related to C++ compiling by adding the `Rcpp` plugin for C++ 11.
* Update C++ code for `gcalibrateC` to resolve issue when there are NaN values in sphere data (issue #35)
* Resolve issue #36 when `calErrorEnd` never gets below 0.01.
* Change minloadcrit from 72 to 168 as recommended in issue #34

# agcounts 0.6.7
* Update `agcalibrate` to speed up function by first converting to a `data.table` before merging with the time stamps.
* Add parameter `imputeTimeGaps` to `agcalibrate` for users to decide if zeros are added back after calibration.
Expand Down
11 changes: 8 additions & 3 deletions src/gcalibrate.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// [[Rcpp::plugins(cpp11)]]
#include <RcppArmadillo.h>
#include <iostream>
#include <vector>
Expand Down Expand Up @@ -91,7 +92,7 @@ Rcpp::List gcalibrateC(Rcpp::Nullable<Rcpp::String> pathname = R_NilValue, Rcpp:
}

Rcpp::NumericVector ws {5, 900, 3600};
int startpage, endpage, blocksize = 12 * ws(2), minloadcrit = 72;
int startpage, endpage, blocksize = 12 * ws(2), minloadcrit = 168;
double NR = ceil((90*pow(10, 6)) / (sf*10)) + 1000; // NR = number of '10' second rows (this is for 10 days at 80 Hz)
int count = 0; // counter to keep track of the number of seconds that have been read
double spherecrit = 0.3, sdcriter = 0.013;
Expand Down Expand Up @@ -162,7 +163,8 @@ Rcpp::List gcalibrateC(Rcpp::Nullable<Rcpp::String> pathname = R_NilValue, Rcpp:
if((use > 0) && (use != LD)){
S = data(Rcpp::Range(use, LD-1), Rcpp::_);
}
data = data(Rcpp::Range(0, use-1), Rcpp::_);

if(use != 0) data = data(Rcpp::Range(0, use-1), Rcpp::_);

if(data.nrow() < blocksize * 30){
LD = 0;
Expand Down Expand Up @@ -274,7 +276,9 @@ Rcpp::List gcalibrateC(Rcpp::Nullable<Rcpp::String> pathname = R_NilValue, Rcpp:

for(int i = 0; i < input.nrow(); i++){
for(int j = 0; j < input.ncol(); j++){
closestpoint(i, j) = curr(i, j) / sqrt(rsum[i]);
if(curr(i, j) != 0){
closestpoint(i, j) = curr(i, j) / sqrt(rsum[i]);
}
}
}

Expand Down Expand Up @@ -311,6 +315,7 @@ Rcpp::List gcalibrateC(Rcpp::Nullable<Rcpp::String> pathname = R_NilValue, Rcpp:

if((calErrorEnd < calErrorStart) && (calErrorEnd < 0.01) && (nhoursused > minloadcrit)){
LD = 0;
Rcpp::Rcout << "Recalibration done, no problems detected";
}
}
i += 1;
Expand Down
1 change: 1 addition & 0 deletions src/resample_helpers.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// [[Rcpp::plugins(cpp11)]]
#include <Rcpp.h>
using namespace Rcpp;

Expand Down

0 comments on commit b1d1972

Please sign in to comment.