Skip to content

Instantly share code, notes, and snippets.

View jeroenboeye's full-sized avatar

Jeroen Boeye jeroenboeye

View GitHub Profile
@jeroenboeye
jeroenboeye / mosquito.py
Created September 30, 2018 20:10
Mosquito population model
import numpy as np
class Mosquito:
"""Contains the details of each Mosquito"""
def __init__(self, mother_gene_infected, father_gene_infected, sex):
self.genes = [mother_gene_infected, father_gene_infected]
self.sex = sex
@jeroenboeye
jeroenboeye / pandas_utc_to_local_timestamp.py
Created October 9, 2019 09:32
Pandas UTC timestamp to local time based on timezone column
import pandas as pd
# Example dataframe
tz_df = pd.DataFrame({'timestamp': pd.to_datetime(['2019-10-08 11:20:00+00:00',
'2019-10-08 01:20:00+00:00']),
'tz': ['cet', 'est']})
# Add local_time
tz_df['local_time'] = tz_df.apply(lambda x: x.timestamp.tz_convert(x.tz), axis=1)
print(tz_df)
@jeroenboeye
jeroenboeye / recommender.py
Created December 12, 2019 09:33
Fast Numpy implementation of collaborative filtering
import numpy as np
import pandas as pd
import sklearn.metrics.pairwise
def get_recommendation_matrix(listening_history, n_similar = 20):
"""Collaborative filtering using cosine similarity"""
# Get similarity matrix, shape = (n artists, n artists)
sim_matrix = sklearn.metrics.pairwise.cosine_similarity(listening_history.T)
# add miniscule noise for sorting without duplicate values

Keybase proof

I hereby claim:

  • I am jeroenboeye on github.
  • I am jeroenboeye (https://keybase.io/jeroenboeye) on keybase.
  • I have a public key ASAamCw_-jZZz1EENFIDcZ4Vs5rfudU85q_2MvURs_3Aewo

To claim this, I am signing this object:

@jeroenboeye
jeroenboeye / blackjack_simple_strategy.py
Created August 21, 2020 09:32
Blackjack simulator where rewards of a fixed policy are calculated using Monte Carlo method. As described in Chapter 5(.1) of Reinforcement Learning, an introduction by Sutton and Barto
"""
Blackjack simulator where rewards of a fixed policy are calculated using Monte Carlo method.
As described in Chapter 5(.1) of Reinforcement Learning, an introduction by Sutton and Barto
"""
from dataclasses import dataclass, field
from typing import List, Tuple
import numpy as np
DECK = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10])
@jeroenboeye
jeroenboeye / blackjack_monte_carlo_optimizer.py
Last active August 31, 2020 07:55
Blackjack simulator where player policy is optimized using the Monte Carlo method. As described in Chapter 5(.3) of Reinforcement Learning, an introduction by Sutton and Barto
"""
Blackjack simulator where player policy is optimized using the Monte Carlo method.
As described in Chapter 5(.3) of Reinforcement Learning, an introduction by Sutton and Barto
"""
from dataclasses import dataclass, field
from typing import List, Tuple
import numpy as np
DECK = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10, 10])
@jeroenboeye
jeroenboeye / higher_lower_optimizer.py
Last active August 31, 2020 07:55
Higher lower (simple card game) optimizer using epsilon greedy Monte Carlo learning. For educational purposes.
"""
Higher lower (simple card game) optimizer using epsilon greedy Monte Carlo learning. For educational purposes.
"""
from dataclasses import dataclass, field
from typing import List, Tuple
import numpy as np
@dataclass
class Player:
@jeroenboeye
jeroenboeye / png_to_gif.py
Last active April 8, 2021 13:46
Resize png images and create GIF
import glob
from PIL import Image
# Measure current aspect ratio beforehand
width = 700 # desired width
aspect_ratio = 0.64267 # original aspect ratio (width / height)
height = int(width / aspect_ratio) # derived new height
# Read png images from plots folder, resize them and add to list.
# First list element is saved as img, rest as imgs (list)
from __future__ import annotations
from dataclasses import dataclass
from typing import Optional
@dataclass
class Node:
d: int
x: int
@jeroenboeye
jeroenboeye / .pre-commit-config.yaml
Last active December 12, 2023 14:36
Pre-commit hook to avoid Excel files being committed
repos:
- repo: local
hooks:
- id: avoid-excel-files
name: Check for Excel files
entry: Excel files should not be committed to the repo
language: fail
files: \.(xls|xlsx|xlsm)$
description: 'Fails on Excel files, see: https://pre-commit.com/#fail'