Skip to content

Instantly share code, notes, and snippets.

View daanklijn's full-sized avatar
👨‍🚀
Ready for take-off!

Daan Klijn daanklijn

👨‍🚀
Ready for take-off!
View GitHub Profile
@daanklijn
daanklijn / conllu_csv_to_tree.py
Created May 3, 2021 10:46
CONLL-U dataframe to dependency tree
df = pd.read_csv('conllu.csv')
words = []
arcs = []
for index, row in df.iterrows():
words.append({
'text': row['word'],
'tag': row['pos']
})
dep_head = row['dependency_head'] - 1
dep_label = row['dependency_label']
@daanklijn
daanklijn / sum_aliexpress.js
Created April 27, 2021 21:51
One-liner to compute the total value of aliexpress orders on a single page.
// Run in the console at https://trade.aliexpress.com/orderList.htm
Array.from(document.querySelectorAll('.amount-num')).map(x => parseFloat(x.innerText.replace('€ ','').replace('$ ',''))).reduce((a,b) => a+b)
@daanklijn
daanklijn / es.tex
Created March 23, 2021 15:57
Evolution Strategies Recombination LaTeX TiKz
\begin{figure}[h]
\centering
\captionsetup{justification=centering}
\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
box/.style={rectangle,draw=black, thick, minimum size=0.5cm},
dbox/.style={rectangle,draw=black, thick, minimum size=0.5cm, fill=black!20},
gbox/.style={rectangle,draw=black, thick, minimum size=0.5cm, fill=black!5},
@daanklijn
daanklijn / bitflip.tex
Created March 22, 2021 15:00
Bit flip mutation and 1-point crossover LaTeX Tikz visualization
\begin{figure}[h]
\centering
\captionsetup{justification=centering}
\begin{tikzpicture}
[%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
box/.style={rectangle,draw=black, thick, minimum size=0.5cm},
dbox/.style={rectangle,draw=black, thick, minimum size=0.5cm, fill=black!20},
]%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Bit flip
@daanklijn
daanklijn / ea.tex
Created March 22, 2021 14:13
Evolutionary Algorithm flowchart LaTeX tikz
\begin{figure}[h]
\centering
\captionsetup{justification=centering}
\begin{tikzpicture}[node distance = 4cm]
\node [frame] (pop) {Population};
\node [above=2cm, left of=pop] (init) {Initialisation};
\node [below=2cm, left of=pop] (term) {Termination};
\node [frame, above=2cm, right of=pop] (parents) {Parents};
\node [frame, below=2cm, right of=pop] (off) {Offspring};
@daanklijn
daanklijn / marl.tex
Created March 12, 2021 14:22
Multi-agent Reinforcement Learning flowchart using LaTeX and TikZ
\begin{tikzpicture}[node distance = 6em, auto, thick]
\node [block] (Agent1) {Agent$_1$};
\node [block, below of=Agent1] (Agent2) {Agent$_2$};
\node [below of=Agent2] (Dots) {\cvdots};
\node [block, below of=Dots] (Agent3) {Agent$_n$};
\node [block, below of=Agent3] (Environment) {Environment};
\path [line] (Agent1.0) --++ (10em,0em) |- node [near start]{$a_{1,t}$} (Environment.-15);
\path [line] (Agent2.0) --++ (6em,0em) |- node [near start]{$a_{2,t}$} (Environment.0);
\path [line] (Agent3.0) --++ (2em,0em) |- node [near start]{$a_{n,t}$} (Environment.15);
@daanklijn
daanklijn / main.py
Created January 11, 2021 14:45
main
def get_env():
env = gym.make('FrostbiteDeterministic-v4')
env = NoopResetEnv(env, noop_max=30)
env = WarpFrame(env, 84)
env = FrameStack(env, 4)
return env
register_env("frostbite", get_env)
config = {
@daanklijn
daanklijn / trainer.py
Created January 11, 2021 14:44
trainer
class GATrainer(Trainer):
_name = "GA"
@override(Trainer)
def _init(self, config, env_creator):
self.config = config
self._workers = [
Worker.remote(config, env_creator)
for _ in range(config["num_workers"])
]
@daanklijn
daanklijn / worker.py
Created January 11, 2021 14:44
worker.py
@ray.remote
class Worker:
def __init__(self,
config,
env_creator):
self.maximum_timesteps = config['max_timesteps_per_episode']
self.mutation_power = config['mutation_power']
self.model = AtariModel()
self.env = env_creator({})
@daanklijn
daanklijn / atari_model.py
Created January 11, 2021 14:43
Atari model
class AtariModel:
def __init__(self):
inputs = Input(shape=(84, 84, 4))
layer1 = Conv2D(32, [8, 8], strides=(4, 4), activation="relu")(inputs)
layer2 = Conv2D(64, [4, 4], strides=(2, 2), activation="relu")(layer1)
layer3 = Conv2D(64, [3, 3], strides=(1, 1), activation="relu")(layer2)
layer4 = Flatten()(layer3)
layer5 = Dense(512, activation="relu")(layer4)
action = Dense(6)(layer5)
self.model = Model(inputs=inputs, outputs=action)