Created
January 22, 2020 08:36
-
-
Save boennecd/770cd7db6f0fa1b6829311ef005436b7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Weibull_mix.cpp */ | |
#include <Rcpp.h> | |
using Rcpp::NumericVector; | |
/* Computes the survival probability of a Weibull mixture. No checks are | |
* made on the length of the input vectors. */ | |
// [[Rcpp::export]] | |
NumericVector Surv_Weibull_mix( | |
NumericVector const t, NumericVector const ps, NumericVector const gs, | |
NumericVector const ls){ | |
std::size_t const n = t.size(), n_comp = ps.size(); | |
NumericVector out(n); | |
for(std::size_t i = 0; i < n_comp; ++i){ | |
double const *to = &t[0L]; | |
for(auto o = out.begin(); o != out.end(); ++o, ++to) | |
*o += ps[i] * std::exp(- ls[i] * std::pow(*to, gs[i])); | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment