Skip to content

Instantly share code, notes, and snippets.

@maxpagels
maxpagels / explore-first-knapsack.py
Last active November 5, 2021 13:50
explore-first-knapsack.py
import numpy as np
# -- Globals
N_ARMS = 4
N_RESOURCES = 3
N_EXPLORATION_ROUNDS = 1
CONSUMPTION_PER_PLAY = [
[4, 0, 0], # Example: first arm consumes 4 of resource 1 and 0 of resources 2 & 3
#!/bin/bash
brew install foma
brew install libvoikko
git clone https://github.com/voikko/corevoikko.git
cd corevoikko/voikko-fi
make vvfst
make vvfst-install DESTDIR=/usr/lib/voikko
pip install voikko
@maxpagels
maxpagels / test.vw
Last active February 3, 2019 15:41
vw-ldf-example
shared | s1 s2
| a b c
| a b c
| a b c
| a b c
| a b c
| a b c
| a b c
| a b c
| a b c
@maxpagels
maxpagels / oaa_transformed.csv
Last active November 17, 2018 17:00
OOA transformed training set
label 1_a 1_b 1_c 1_d 2_a 2_b 2_c 2_d 3_a 3_b 3_c 3_d
1 0.2 0.5 0.3 0.1 0 0 0 0 0 0 0 0
1 0.2 0.5 0.2 0.2 0 0 0 0 0 0 0 0
0 0.3 0.8 0.9 0.2 0 0 0 0 0 0 0 0
0 0.3 0.9 0.9 0.2 0 0 0 0 0 0 0 0
0 0.9 0.1 0.1 0.1 0 0 0 0 0 0 0 0
0 0.9 0.1 0.1 0.2 0 0 0 0 0 0 0 0
1 0 0 0 0 0.3 0.8 0.9 0.2 0 0 0 0
1 0 0 0 0 0.3 0.9 0.9 0.2 0 0 0 0
0 0 0 0 0 0.2 0.5 0.2 0.2 0 0 0 0
@maxpagels
maxpagels / oaa_original.csv
Last active November 13, 2018 19:11
OAA original training set
label a b c d
1 0.2 0.5 0.3 0.1
2 0.3 0.8 0.9 0.2
2 0.3 0.9 0.9 0.2
3 0.9 0.1 0.1 0.1
3 0.9 0.1 0.1 0.2
1 0.2 0.5 0.2 0.2
@maxpagels
maxpagels / parallel-evolution-strategies.py
Created September 19, 2018 06:28
parallel-evolution-strategies.py
import numpy as np
import multiprocessing
from joblib import Parallel, delayed
np.random.seed(0)
# the function we want to optimize
def f(w):
reward = -np.sum(np.square(solution - w))
return reward
import socket
from flask import Flask
from flask import jsonify
from flask import request
VW_HOST = '127.0.0.1'
VW_PORT = 26542
BUFFER_SIZE = 1024*10
import socket
from flask import Flask
from flask import jsonify
from flask import request
VW_HOST = '127.0.0.1'
VW_PORT = 26542
BUFFER_SIZE = 1024*10
@maxpagels
maxpagels / ml-jargon.csv
Last active August 26, 2018 13:47
Machine Learning Jargon
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 6.
Term,Explanation
model,"one or more functions trying to explain some system/environment works. Most models are terrible approximations of the real world, but some are less terrible than others. The whole idea of machine learning is to find the least terrible model for a particular problem. Yes, we're pessimists."
regression,"predicting a number; e.g. predicting someone's income based on their education, country and so on."
logistic regression, "classification; predicting if something belongs to a particular class ('is this photo a photo of a cat or a dog?'). Logistic regression is one of many learning algorithms for classification."
feature engineering, "massaging data so that it yields the most predictive power; generating variables from data that fit our understanding of the context we're trying to model but are not found as-is in the raw data we are using."
hypothesis space, "a set of possible functions. It's machine learning's job to learn which of these possible functions best approximates the relationsh
# Python implementation of the EXP3 (Exponential weight for Exploration and Exploitation)
# algorithm for solving adversarial bandit problems. Based on the original paper:
# http://rob.schapire.net/papers/AuerCeFrSc01.pdf
import numpy as np
import time
np.random.seed(12345)
n_arms = 4