Load packages and set working directory:
knitr::opts_knit$set(root.dir = "/Users/turx/Projects/machine-teaching-23sp/hw05-machine-teaching-knn")
knitr::opts_chunk$set(warning = FALSE, message = FALSE, error = TRUE) # error = TRUE
setwd("/Users/turx/Projects/machine-teaching-23sp/hw05-machine-teaching-knn")
library(tidyverse)
library(lubridate)
library(ggplot2)
library(purrr)
library(rjson)
library(digest)
set.seed(digest2int("machine teaching"))
pool <- tibble(read.table("hw5data.txt", col.names = c("x1", "x2", "y")))
# pool_idx <- sample(nrow(pool), size = 50, replace = FALSE)
# pool <- pool[pool_idx, ]
pool
## # A tibble: 807 × 3
## x1 x2 y
## <dbl> <dbl> <int>
## 1 0.776 0.0528 1
## 2 0.992 0.0874 1
## 3 0.264 0.131 1
## 4 0.0795 0.109 1
## 5 0.689 0.983 1
## 6 0.117 0.434 1
## 7 0.453 0.721 1
## 8 0.179 0.928 1
## 9 0.0787 0.245 1
## 10 0.480 0.980 1
## # … with 797 more rows
k <- 1 # number of nearest neighbors
Z <- pool %>% rename(x1p = x1, x2p = x2, yp = y) # superset of all teaching sets
enum_upper <- 2 # n_star for enum, threshold for the number of teaching examples
greedy_upper <- 20 # n_star for greedy, threshold for the number of teaching examples
# saved_run_debug <- TRUE # uncomment to ignore saved csv files