Code Monkey home page Code Monkey logo

rcpptn's People

Contributors

bitdeli-chef avatar olmjo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

napovargas

rcpptn's Issues

Fix integer arguments

See the CRAN check page for your package and §1.6 of the manual. Standard math functions such as log and sqrt are not defined for integer arguments in C++.

Some of these are long-standing: please correct ASAP and by Dec 1 if you want to retain the package on CRAN. Make sure you check for similar occurrences and other issues shown on the CRAN results page before submitting a corrected update.

Pnorm and Dnorm on log scale

Thanks for the package, I've found it's really useful!

I ran into overflow/underflow problems, and was able to re-implement them on the log scale, which fixed this problem. I thought I'd share it, in case this is a problem others have run into:

I did not do this using the truncated above and below, only for the separate ones, since those were the only two I'm using. Here's the c++ code:

`
using namespace Rcpp ;

/// No Truncation
double e0 (const double mean,
const double sd,
const double low,
const double high
) {
return(mean) ;
}

/// Truncated Below and Above
double e1 (const double mean,
const double sd,
const double low,
const double high
) {
double s_low = (low - mean) / sd ;
double s_high = (high - mean) / sd ;

double q1 = R::dnorm(s_low, 0.0, 1.0, false) ;
double q2 = R::dnorm(s_high, 0.0, 1.0, false) ;
double q3 = R::pnorm(s_low, 0.0, 1.0, true, false) ;
double q4 = R::pnorm(s_high, 0.0, 1.0, true, false) ;

return(mean + sd * ((q1 - q2) / (q4 - q3))) ;

}

/// Truncated Below
double e2 (const double mean,
const double sd,
const double low
) {
double s_low = (low - mean) / sd ;

double q1 = R::dnorm(s_low, 0.0, 1.0, true) ;
double q3 = R::pnorm(s_low, 0.0, 1.0, true, true) ;

return(mean + sd * exp((q1) - (1 - q3))) ;

}

/// Truncated Above
double e3 (const double mean,
const double sd,
const double high
) {
double s_high = (high - mean) / sd ;

double q2 = R::dnorm(s_high, 0.0, 1.0, false) ;
double q4 = R::pnorm(s_high, 0.0, 1.0, true, false) ;

return( mean - sd * exp(q2 - q4)) ;

}

/// Main Function
double etn2(const double mean,
const double sd,
const double low,
const double high
) {
// Init Useful Values
double out = NA_REAL ;
//

if (low == R_NegInf &&
    high == R_PosInf
    ) {
  // No Truncation
    out = e0(mean, sd, low, high) ;
} else if (low == R_NegInf) {
    // Truncated Above
    out = e3(mean, sd, high) ;
} else if (high == R_PosInf) {
    // Truncation Below
    out = e2(mean, sd, low) ;
} else {
    // Truncation Above and Below
    out = e1(mean, sd, low, high) ;
}
// Check if Mirror Problem is Numerically Better
if (!std::isfinite(out)) {
    return(-e1(-mean, sd, -high, -low)) ;
}
//
return(out) ;

}`

non-conditional use of microbenchmark

Non-required packages must be used conditionally: see §1.1.3.1 of the manual.

For RcppTN this applies to microbenchmark, which only works on a few platforms.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.