Skip to content

Instantly share code, notes, and snippets.

View kastnerkyle's full-sized avatar

Kyle Kastner kastnerkyle

View GitHub Profile
@kastnerkyle
kastnerkyle / audio_tools.py
Last active November 17, 2024 12:01
Audio tools for numpy/python. Constant work in progress.
raise ValueError("DEPRECATED/FROZEN - see https://github.com/kastnerkyle/tools for the latest")
# License: BSD 3-clause
# Authors: Kyle Kastner
# Harvest, Cheaptrick, D4C, WORLD routines based on MATLAB code from M. Morise
# http://ml.cs.yamanashi.ac.jp/world/english/
# MGC code based on r9y9 (Ryuichi Yamamoto) MelGeneralizedCepstrums.jl
# Pieces also adapted from SPTK
from __future__ import division
import numpy as np
@kastnerkyle
kastnerkyle / vector_kuhn.py
Last active November 11, 2024 11:05
Vectorized, alternating update versions of various algorithms for Kuhn poker
# Author: Kyle Kastner
# License: BSD 3-Clause
# Vectorized, alternating update CFR+ for Kuhn poker
# For specific algorithmic details see
# http://jeskola.net/cfrp_mt.pdf
# https://pdfs.semanticscholar.org/ed52/8594465e96f51fd9a3cf00401bfba20597fa.pdf
# An alternate overview using scalar, simultaneous updates
# https://justinsermeno.com/posts/cfr/
@kastnerkyle
kastnerkyle / conv_deconv_vae.py
Last active October 19, 2024 08:20
Convolutional Variational Autoencoder, modified from Alec Radford at (https://gist.github.com/Newmu/a56d5446416f5ad2bbac)
# Alec Radford, Indico, Kyle Kastner
# License: MIT
"""
Convolutional VAE in a single file.
Bringing in code from IndicoDataSolutions and Alec Radford (NewMu)
Additionally converted to use default conv2d interface instead of explicit cuDNN
"""
import theano
import theano.tensor as T
from theano.compat.python2x import OrderedDict
@kastnerkyle
kastnerkyle / rover_simple_python.py
Last active July 14, 2024 19:58
ROVER system combination algorithm
# -*- coding: utf-8 -*-
from __future__ import print_function
from __future__ import unicode_literals
# author: Kyle Kastner
# References:
# needleman wunsch (could use other alignment algorithms instead)
# https://colab.research.google.com/github/zaneveld/full_spectrum_bioinformatics/blob/master/content/08_phylogenetic_trees/needleman_wunsch_alignment.ipynb
@kastnerkyle
kastnerkyle / handwriter.py
Last active July 11, 2024 12:26
Single file handwriting experiment
# Author: Kyle Kastner
# License: BSD 3-clause
# Thanks to Jose (@sotelo) for tons of guidance and debug help
# Credit also to Junyoung (@jych) and Shawn (@shawntan) for help/utility funcs
# Strangeness in init could be from onehots, via @igul222. Ty init for one hot layer as N(0, 1) just as in embedding
# since oh.dot(w) is basically an embedding
import os
import re
import tarfile
from collections import Counter
@kastnerkyle
kastnerkyle / flow_matching.py
Created June 19, 2024 18:55 — forked from francois-rozet/flow_matching.py
Flow Matching in 100 LOC
#!/usr/bin/env python
import math
import matplotlib.pyplot as plt
import torch
import torch.nn as nn
from sklearn.datasets import make_moons
from torch import Tensor
from tqdm import tqdm
@kastnerkyle
kastnerkyle / tanh_rnn.py
Last active May 17, 2024 08:44
Basic tanh rnn in Theano
# Author: Kyle Kastner
# License: BSD 3-clause
# THEANO_FLAGS="optimizer=None,compute_test_value=raise" python tanh_rnn.py
import numpy as np
import theano
import theano.tensor as T
from scipy import linalg
class sgd(object):
@kastnerkyle
kastnerkyle / fancy_youtube_encode.sh
Last active April 23, 2024 06:22
Fancy encoding of a wav file (or possibly others in the future) to youtube format
# Based on example here https://trac.ffmpeg.org/wiki/Encode/YouTube
text=$(basename $1 .wav)
ffmpeg -i $1 -filter_complex \
"[0:a]avectorscope=s=640x518,pad=1280:720[vs]; \
[0:a]showspectrum=mode=separate:color=intensity:scale=cbrt:s=640x518[ss]; \
[0:a]showwaves=s=1280x202:mode=line[sw]; \
[vs][ss]overlay=w[bg]; \
[bg][sw]overlay=0:H-h,drawtext=fontfile=/usr/share/fonts/truetype/fonts-japanese-gothic.ttf:fontcolor=white:x=10:y=10:text=$text[out]" \
-map "[out]" -map 0:a -c:v libx264 -preset fast -crf 18 -c:a copy $text.mkv
@kastnerkyle
kastnerkyle / shared_memory_example.py
Last active April 20, 2024 22:14
Shared memory example
# Example from J.F. Sebastien on SO
# http://stackoverflow.com/questions/7894791/use-numpy-array-in-shared-memory-for-multiprocessing/7908612#7908612
import ctypes
import logging
import multiprocessing as mp
from contextlib import closing
import numpy as np
# Author: Kyle Kastner
# License: BSD 3-Clause
# Inspired from blogpost by Justin Sermeno https://justinsermeno.com/posts/cfr/
# Extended with algorithms described by Oskari Tammelin http://jeskola.net/cfr/demo/ by
# Particularly, solve has core game logic
# http://jeskola.net/cfr/demo/solve.js
# basecfr: http://poker.cs.ualberta.ca/publications/NIPS07-cfr.pdf
# cfrplus: https://arxiv.org/abs/1407.5042