Random Numbers In C++

Want to make some random numbers in C++? Buckle up. default_random_engine We start by creating a default_random_engine from C++’s <random> library. #include <random> int main() { std::default_random_engine myRandomEngine; } Now we can use myRandomEngine to generate some random numbers. #include <iostream>#include <random> int main() { std::default_random_engine myRandomEngine; std::cout << myRandomEngine() << " " << std::endl; std::cout << myRandomEngine() << " " << std::endl; std::cout << myRandomEngine() << " " << std::endl; } For me, this produces the output

Reading And Writing CSV Files With C++

As a data scientist, reading and writing data from/to CSV is one of the most common tasks I do on the daily. R, my language of choice, makes this easy with read.csv() and write.csv() (although I tend to use fread() and fwrite() from the data.table package). Hot Take. C++ is not R. As far as I know, there is no CSV reader/writer built into the C++ STL. That’s not a knock against C++; it’s just a lower level language.

Exposing a C++ Student Class With Rcpp

Intro The purpose of this tutorial is to document my notes as I experiment with exposing a simple C++ Student class to R using Rcpp. It’s more or less part two of a series of articles on Rcpp. (See part one here). Setup In part one of my tutorial on using Rcpp, we discussed how to use Rcpp’s sourceCpp() function to compile a C++ file with simple C++ functions. My next question was “How can I use Rcpp to expose more complicated C++ code that uses multiple files including header files?

Rcpp Notes From a Newbie

Intro You probably already know that C++ has speed advantages compared to R, and Rcpp is the package for exposing that fast and efficient C++ code to R. For me, the motive to learn Rcpp (and C++) stems from xgboost and lightgbm - two prominent machine learning models used in Kaggle competitions. At their core, they’re both written in C++. However, they both have R and Python interfaces which, in my opinion, is a huge part of their popularity.

Dates and Times in R Without Losing Your Sanity

Working with dates and times in R can be frustrating! This isn’t R’s fault; dates and times are naturally complicated. One must consider time zones, leap years, leap seconds, Daylight Savings, hundreds of potential date and time formats, and other quirky complexities. The goal of this article is to give you the tools and knowledge to deal with dates and times in R so you can avoid common mistakes, saving your hair and extending your lifespan.

A Machine Learning Approach to Inventory Demand Forecasting

The problem of Inventory Demand Forecasting is extremely simple to understand, yet challenging to solve optimize. The classic example is a grocery store that needs to forecast demand for perishable items. Purchase too many and you’ll end up discarding valuable product. Purchase too few and you’ll run out of stock. Numerous businesses face different flavors of the same basic problem, yet many of them use outdated or downright naive methods to tackle it (like spreadsheet guided, stock-boy adjusted guessing).