Skip to content

Instantly share code, notes, and snippets.

View yanniskatsaros's full-sized avatar

Yannis Katsaros yanniskatsaros

View GitHub Profile
@yanniskatsaros
yanniskatsaros / settings.json
Created January 7, 2021 22:11
Windows Terminal settings
// This file was initially generated by Windows Terminal Preview 1.5.3242.0
// It should still be usable in newer versions, but newer versions might have additional
// settings, help text, or changes that you will not see unless you clear this file
// and let us generate a new one for you.
// To view the default settings, hold "alt" while clicking on the "Settings" button.
// For documentation on these settings, see: https://aka.ms/terminal-documentation
{
"$schema": "https://aka.ms/terminal-profiles-schema",
@yanniskatsaros
yanniskatsaros / smoothing.py
Last active November 13, 2020 15:49
Exponential Smoothing on a Random Walk
from typing import Iterable
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from numpy import ndarray
def generate_random_walk(size: int) -> ndarray:
draw = np.random.random(size)
@yanniskatsaros
yanniskatsaros / itersplit.py
Created November 8, 2020 02:41
Split an iterable into n chunks using Python generators
from itertools import islice
def itersplit(iterable, n):
i = len(iterable) % n
start = 0; stop = i
for _ in range(n):
yield list(islice(iterable, start, stop))
start += i; stop += i
@yanniskatsaros
yanniskatsaros / .gitlab-ci.yml
Last active November 1, 2022 15:06
Example GitLab CI YAML files and mkdocs configurations for documentation
image: python:3.7.8-slim
default:
tags:
- common_runner
- docker_spot_runner
- group_runners
variables:
USER: "{username}"
@yanniskatsaros
yanniskatsaros / scrape.py
Created May 7, 2020 19:32
Simple requests and beautiful soup example
import sys
import requests
from bs4 import BeautifulSoup
def download_html(url: str, filename: str):
r = requests.get(url)
r.raise_for_status()
html = r.text
@yanniskatsaros
yanniskatsaros / autoregressive.py
Created May 1, 2020 15:24
A pure autoregressive model from scratch with Python and numpy.
"""
A pure auto-regressive model from scratch. (WIP)
--------------------------------------------------
The current implementation is incorrect. A proper
auto-regressive model uses $p$ "lags" of the variable
from $x_t$ to $x_{t-p}$ each with its own coefficient.
An auto-regressive model of order $p$ is written as:
$x_t = \sum_{i=1}^{p} \alpha_i x_{t-i} + \epsilon_t
"""
Download a selection or all of the 500+ freely available Springer textbooks.
For significantly better IO performance, prefer this asynchronous
implementation to the synchronous alternative also provided.
Orginally inspired by:
https://towardsdatascience.com/download-all-free-textbooks-from-springer-using-python-bd0b10e0ccc
"""
@yanniskatsaros
yanniskatsaros / fourier_transform.py
Created April 29, 2020 15:02
Convenience class for simplifying the process of computing FFT and IFFT. Provides helpful interactive diagnostic and trend plots using Plotly.
import numpy as np
import plotly.graph_objects as go
from scipy.fft import fft, ifft, fftfreq
from scipy.signal import find_peaks
from plotly.subplots import make_subplots
class FourierTransform:
def __init__(self, x, time_step: int=1):
"""
@yanniskatsaros
yanniskatsaros / gamma_example.py
Created April 26, 2020 22:53
Boilerplate code for working with a Gamma Distribution using scipy that matches the functional form defined on Wikipedia: https://en.wikipedia.org/wiki/Gamma_distribution
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns # optional, just for aesthetics
from scipy.stats import gamma
# recreate the example shown in Wikipedia for reference
# param = (alpha, beta) == (k, 1/theta)
params = [
(1, 1/2),
(2, 1/2),
@yanniskatsaros
yanniskatsaros / environment.yml
Created April 22, 2020 17:16
A simple and cross-platform effective way to create a conda env with appropriate dependencies
# for more info see:
# https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html#create-env-file-manually
name: core-env
channels:
- conda-forge
dependencies:
- python=3.7
- matplotlib
- jupyterlab
- xlrd