Skip to content

Instantly share code, notes, and snippets.

@aerinkim
aerinkim / my_adam.py
Last active December 24, 2020 16:58
Adam Implementation from scratch
from torch.optim import Optimizer
class ADAMOptimizer(Optimizer):
"""
implements ADAM Algorithm, as a preceding step.
"""
def __init__(self, params, lr=1e-3, betas=(0.9, 0.99), eps=1e-8, weight_decay=0):
defaults = dict(lr=lr, betas=betas, eps=eps, weight_decay=weight_decay)
super(ADAMOptimizer, self).__init__(params, defaults)
@aerinkim
aerinkim / Kmeans.py
Created February 24, 2019 23:05
K-means Python Implementation from scratch
from sklearn import datasets
def Kmeans(X, K):
m = len(X)
X_centroid = dict() # Save which sample belong to which cluster.
X_centroid.fromkeys(range(0, m))
C = dict() # Save cluster's cordinate
C.fromkeys(range(0, K))
old_C = None # Cache to save old C. Used for an early termination.
# 1. Randomly initialize k centroids.
@aerinkim
aerinkim / beta_distribution_graph.py
Created January 1, 2020 23:48
Plotting the beta distribution with different shapes
import numpy as np
from scipy.stats import beta
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [10, 7]
# Bell shape
x = np.linspace(0, 1, 10000)
y1 = beta.pdf(x, 2, 8)
y2 = beta.pdf(x, 5, 5)
y3 = beta.pdf(x, 8, 2)
@aerinkim
aerinkim / conjugate_prior.py
Created January 3, 2020 23:36
Calculate the posterior of binomial likelihood
import numpy as np
import scipy.stats as stats
success_prob = 0.3
data = np.random.binomial(n=1, p=success_prob, size=1000) # sucess is 1, failure is 0.
# Domain θ
theta_range = np.linspace(0, 1, 1000)
# Prior P(θ)
class Calibration:
"""Calibration matrices and utils.
3d XYZ are in 3D egovehicle coord.
2d box xy are in image coord, normalized by width and height
Point cloud are in egovehicle coord
::
xy_image = K * [R|T] * xyz_ego
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
export function lint(response) {
const lintIssues = [];
let isLabelable = true;
if (response.values) {
for (const value of response.values) {
if (value.field_id === 'invoice_labeling' && !value.selected.includes('yes')) {
isLabelable = false;
}
}
const REGEX_ISO_CURRENCY_CODE = /[A-Z]{3}/;
const labelsToCheck = ['Invoice Total', 'Invoice Amount Due', 'Item Amount', 'Unit Price'];
export function lint(response) {
const lintIssues = [];
if (response.annotations) {
for (const annotation of response.annotations) {
if (labelsToCheck.includes(annotation.label)) {
const REGEX_no_dollar_sign = /[!@#$%^&*()_+\-=\[\]{};':"\\|<>\/?~]/;
const labelsToCheck = ['Invoice Total', 'Invoice Amount Due', 'Item Amount', 'Unit Price'];
export function lint(response) {
const lintIssues = [];
if (response.annotations) {
for (const annotation of response.annotations) {
if (labelsToCheck.includes(annotation.label)) {
const REGEX_contains_hashtag = /[#]/;
const labelsToCheck = ['Invoice Number'];
export function lint(response) {
const lintIssues = [];
if (response.annotations) {
for (const annotation of response.annotations) {
if (labelsToCheck.includes(annotation.label)) {