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
# Native Python packages | |
import numpy as np | |
import pandas as pd | |
# R2pi package | |
from rpy2.robjects import numpy2ri, pandas2ri | |
from rpy2.robjects.packages import importr | |
# R imports (Assuming AER and ivpack are installed in R) | |
base = importr("base") |
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
# Reference: https://github.com/swager/grf/issues/247 | |
# Here I shut off nonlinearity in true model, just for diagnostics | |
library(tidyverse) | |
library(grf) | |
simple_oracle_data <- function(nsamp, | |
beta=c(2,-1,0,0,0), | |
te=1, | |
hete=1, |
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
library(tidyverse) | |
test_fun <- function(n=200, p=20, num.trees=NULL, mtry=NULL) { | |
# Creating regressors: x1, ..., xp | |
X <- as.data.frame(matrix(rnorm(n*p), n, p)) | |
colnames(X) <- paste("x", seq_len(p), sep="") | |
# Let x1 be the only relevant covariate | |
Y <- X[,1] |
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
library(grf) | |
n <- 100 | |
# X ~ Unif[-5,-2]+[2, 5] | |
X <- matrix(c(seq(-5, -2, length.out=n/2), seq(2, 5, length.out=n/2)), n, 1) | |
# P( W=1 | X > 0) = 1 and P( W=1 | X < 0) = 1 | |
W <- matrix(X[,1] > 0, n, 1) |
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
# PART II | |
library(DiceKriging) | |
n <- 100 | |
k <- 3 | |
# Design (fit.draws in tune_*_forest) | |
design <- matrix(runif(n*k), n, k) | |
# If both 'response' and 'noise.var' are constants, |
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
library(grf) | |
n <- 100 | |
k <- 3 | |
X <- matrix(rnorm(n*k), n, k) | |
# Outcome is constant! | |
Y_constant <- matrix(rep(0, n)) |
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
#include <iostream> | |
#include <set> | |
#include <vector> | |
void fill_skipping(std::vector<size_t>& result, | |
std::set<size_t>& skip) { | |
auto p_skip = skip.begin(); | |
auto p_result = result.begin(); |
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
library(grf) | |
# Some forest | |
n <- 1000 | |
k <- 3 | |
X <- matrix(runif(n*k), nrow=n, ncol=k) | |
Y <- matrix(runif(n), nrow=n, ncol=1) | |
forest <- grf::regression_forest(X, Y) | |
# Get tree |
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
library(grf) | |
p = 3 | |
n = 2000 | |
sigma = 0.1 | |
X = matrix(2 * runif(n * p) - 1, n, p) | |
W = rbinom(n, 1, 0.1) | |
TAU = (X[,1] > 0) | |
Y = TAU * (W - 1/2) + sigma * rnorm(n) |
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
library(grf) | |
set.seed(123) | |
# Very simple scenario, but already adversarial | |
n <- 200 | |
p <- 2 | |
X <- matrix(rnorm(n * p), n, p) | |
W <- rbinom(p=0.5, size=1, n=n) | |
eta <- 1 |
OlderNewer