Skip to content

Instantly share code, notes, and snippets.

View jponf's full-sized avatar
🐕

Josep Pon Farreny jponf

🐕
View GitHub Profile
@jponf
jponf / stacktracer.py
Last active September 8, 2021 08:36
Python stacktracer
# -*- coding: utf-8 -*-
"""Stack tracer for multi-threaded applications.
This code is a copy of https://pypi.python.org/pypi/stacktracer/0.1.2
with minor modifications.
Usage:
@jponf
jponf / gmeans.py
Last active February 25, 2021 16:13
A GMeans implementation that I used in some projects back in 2017
# -*- coding: utf-8 -*-
import numpy as np
import sklearn.utils
from scipy.stats import anderson, kstest, normaltest, shapiro
from sklearn.cluster import KMeans
@jponf
jponf / cosine_decay_lr_scheduler.py
Created November 29, 2020 06:59
TF Warmup Cosine Decay LR Scheduler
import tensorflow as tf
import math
class WarmupCosineDecayLRScheduler(
tf.keras.optimizers.schedules.LearningRateSchedule):
def __init__(self,
max_lr: float,
warmup_steps: int,
decay_steps: int,
// Open browser JS console and Copy&Paste the following code
function ConnectButton(){
console.log("Connect pushed");
document.querySelector("#top-toolbar > colab-connect-button").shadowRoot.querySelector("#connect").click()
}
setInterval(ConnectButton, 300000);
def aitken_interpolation(x, y):
if len(x) != len(y):
raise ValueError()
# Constants
x_poly = np.polynomial.Polynomial([0, 1])
# Initialize algorithm
n = len(x)
p = [np.polynomial.Polynomial([y[0]])]
@jponf
jponf / filter_outliers_iqr.py
Last active May 3, 2019 14:18
Remove outliers from a numpy array using IQR
import numpy as np
# `data` is expected to be a numpy array
def filter_outliers_iqr(data, iqr_factor=1.5):
quartile_1, quartile_3 = np.percentile(data, (25, 75))
iqr = quartile_3 - quartile_1
lw_bound = quartile_1 - (iqr * iqr_factor)
up_bound = quartile_3 + (iqr * iqr_factor)
return data[data >= lw_bound & data <= up_bound]