Skip to content

Instantly share code, notes, and snippets.

View gdetor's full-sized avatar

Georgios Is. Detorakis gdetor

View GitHub Profile
#!/usr/bin/awk -f
# This program is a copy of guff, a plot device. https://github.com/silentbicycle/guff
# My copy here is written in awk instead of C, has no compelling benefit.
# Public domain. @thingskatedid
# Run as awk -v x=xyz ... or env variables for stuff?
# Assumptions: the data is evenly spaced along the x-axis
# TODO: moving average
@qpwo
qpwo / monte_carlo_tree_search.py
Last active May 21, 2024 15:03
Monte Carlo tree search (MCTS) minimal implementation in Python 3, with a tic-tac-toe example gameplay
"""
A minimal implementation of Monte Carlo tree search (MCTS) in Python 3
Luke Harold Miles, July 2019, Public Domain Dedication
See also https://en.wikipedia.org/wiki/Monte_Carlo_tree_search
https://gist.github.com/qpwo/c538c6f73727e254fdc7fab81024f6e1
"""
from abc import ABC, abstractmethod
from collections import defaultdict
import math
@bshishov
bshishov / forecasting_metrics.py
Last active April 20, 2024 04:29
Python Numpy functions for most common forecasting metrics
import numpy as np
EPSILON = 1e-10
def _error(actual: np.ndarray, predicted: np.ndarray):
""" Simple error """
return actual - predicted
def emr_step(dt_n, y_n, dy_n, dt_nm1, y_nm1):
"""Take a single step of the explicit midpoint rule.
From G&S pg. 715 and Prinja's thesis pg.45.
"""
dtr = dt_n / dt_nm1
y_np1 = (1 - dtr**2)*y_n + (1 + dtr)*dt_n*dy_n + (dtr**2)*(y_nm1)
return y_np1
def bdf2_dydt(ts, ys):
"""Get dy/dt at time ts[-1] (allowing for varying dt).