Skip to content

Instantly share code, notes, and snippets.

View Laurae2's full-sized avatar

Laurae Laurae2

View GitHub Profile
@Laurae2
Laurae2 / date_conversion_benchmark.md
Created December 8, 2020 21:38
R date conversion benchmark copy pasta

Code:

library(anytime)
library(flipTime)
library(data.table)

set.seed(1)
system.time({
  some_dates <- as.Date("2020-12-31") - sample(40000, 1e7, TRUE)
@Laurae2
Laurae2 / lightgbm_cuda_R_on_thin_ice.Rmd
Last active September 25, 2020 20:38
Install LightGBM with CUDA on R (walk on thin ice)
Walk on thin ice in R for gcc-7/g++-7 + CUDA 10.0.130
Note: OpenCL can run on Single Precision (gpu_use_dp = FALSE) or Double Precision (gpu_use_dp = TRUE) whereas CUDA is strictly Double Precision in LightGBM.
--
STEP 1: HACK IN SOME FILES
Hack in the following:
```
@Laurae2
Laurae2 / benchmark_xgb_lgb_HIGGS.R
Created March 29, 2020 14:16
Benchmark xgboost and LightGBM using HIGGS dataset in R
library(xgboost)
library(lightgbm)
library(data.table)
setwd("/home/laurae/Documents/R/GBM-perf")
n_threads <- 16
data <- fread("HIGGS.csv")
labels <- data$V1
@Laurae2
Laurae2 / xgboost_GPU_RAM_usage.R
Last active December 24, 2018 21:34
RAM usage of xgboost GPU in R
library(xgboost)
set.seed(1)
N <- 1000000
p <- 100
pp <- 25
X <- matrix(runif(N * p), ncol = p)
betas <- 2 * runif(pp) - 1
sel <- sort(sample(p, pp))
m <- X[, sel] %*% betas - 1 + rnorm(N)
@Laurae2
Laurae2 / matrix_size.R
Created December 24, 2018 21:05
Matrix size
set.seed(1)
N <- 500000
p <- 100
pp <- 25
X <- matrix(runif(N * p), ncol = p)
betas <- 2 * runif(pp) - 1
sel <- sort(sample(p, pp))
m <- X[, sel] %*% betas - 1 + rnorm(N)
y <- rbinom(N, 1, plogis(m))
@Laurae2
Laurae2 / xgboost_cpu_vs_gpu.R
Last active December 24, 2018 14:38
xgboost CPU vs GPU
library(xgboost)
set.seed(1)
N <- 10000000
p <- 100
pp <- 25
X <- matrix(runif(N * p), ncol = p)
betas <- 2 * runif(pp) - 1
sel <- sort(sample(p, pp))
m <- X[, sel] %*% betas - 1 + rnorm(N)
@Laurae2
Laurae2 / cplex.md
Created November 25, 2018 23:13
Windows + CPLEX + R + cplexAPI

Step 1: download cplexAPI : Step 2: edit src/Makevars.win like the following, make sure cplex1280 is equal to your version you must change to the corresponding number you can find in C:/Program Files/IBM/ILOG/CPLEX_Studio128/cplex/bin/x64_win64:

PKG_CPPFLAGS=-g -D_R_=1 -DUSE_R=1 -I"C:/Program Files/IBM/ILOG/CPLEX_Studio128/cplex/include"
PKG_LIBS=-L"C:/Program Files/IBM/ILOG/CPLEX_Studio128/cplex/bin/x64_win64" -lm -lcplex1280

Step 3: in a R console, on the right folder:

@Laurae2
Laurae2 / stream.R
Created October 14, 2018 21:48
Stream in R (brute force & slow version)
library(Rcpp)
Sys.setenv(PKG_CXXFLAGS = "-fopenmp -std=c++11")
cppFunction(code = '#include <Rcpp.h>
#include <omp.h>
Rcpp::NumericVector streamer(Rcpp::NumericVector threads, int triad_size = 2147483647, int repeats = 10, int repeats_alloc = 3, bool simd = false) {
int i;
@Laurae2
Laurae2 / data.table_benchmark_2bn.R
Last active October 25, 2018 18:24
data.table benchmark 2 billions
# library(data.table)
# N=2e9; K=100
# set.seed(1)
# DT <- data.table(
# id1 = sample(sprintf("id%03d",1:K), N, TRUE), # large groups (char)
# id2 = sample(sprintf("id%03d",1:K), N, TRUE), # large groups (char)
# id3 = sample(sprintf("id%010d",1:(N/K)), N, TRUE), # small groups (char)
# id4 = sample(K, N, TRUE), # large groups (int)
# id5 = sample(K, N, TRUE), # large groups (int)
# id6 = sample(N/K, N, TRUE), # small groups (int)
@Laurae2
Laurae2 / enable-all-advanced-power-settings.ps1
Created June 11, 2018 20:25 — forked from raspi/enable-all-advanced-power-settings.ps1
Enable all advanced power settings in Windows.
# List all possible power config GUIDs in Windows
# Run: this-script.ps1 | Out-File powercfg.ps1
# Then edit and run powercfg.ps1
# (c) Pekka "raspi" Järvinen 2017
$powerSettingTable = Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSetting
$powerSettingInSubgroubTable = Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingInSubgroup
Get-WmiObject -Namespace root\cimv2\power -Class Win32_PowerSettingCapabilities | ForEach-Object {
$tmp = $_.ManagedElement