Skip to content

Instantly share code, notes, and snippets.

View masterdezign's full-sized avatar

masterdezign

View GitHub Profile
@masterdezign
masterdezign / dct.hs
Created December 5, 2015 18:27 — forked from vi/dct.hs
Simple command-line Discrete Cosine Transform in Haskell
-- "cabal install vector-fftw split"
import qualified Numeric.FFT.Vector.Unnormalized as FFT
import Data.Vector (fromList, toList)
import Data.List.Split (splitOneOf)
import Data.List (intersperse)
import Control.Monad (forever)
import Control.Arrow ((>>>))
main = forever $
@masterdezign
masterdezign / CrazyIO.hs
Created December 19, 2015 13:27 — forked from nkpart/CrazyIO.hs
CrazyIO - binary deserialization using mmaped I/O and Data.Vector.Storable
{-# LANGUAGE ScopedTypeVariables #-}
module CrazyIO (module CrazyIO, mmapFileByteString) where
import qualified Data.Vector.Storable as V
import qualified Data.ByteString as BS
import qualified Data.ByteString.Internal as BS
import Foreign
import System.IO.MMap
crazyLoad :: forall a. Storable a => FilePath -> Maybe (Int64, Int) -> IO (V.Vector a)
@masterdezign
masterdezign / min-char-rnn.py
Created February 17, 2016 17:28 — forked from karpathy/min-char-rnn.py
Minimal character-level language model with a Vanilla Recurrent Neural Network, in Python/numpy
"""
Minimal character-level Vanilla RNN model. Written by Andrej Karpathy (@karpathy)
BSD License
"""
import numpy as np
# data I/O
data = open('input.txt', 'r').read() # should be simple plain text file
chars = list(set(data))
data_size, vocab_size = len(data), len(chars)
@masterdezign
masterdezign / xor_keras.py
Created August 31, 2016 10:25 — forked from cburgdorf/xor_keras.py
Comparing XOR between tensorflow and keras
import numpy as np
from keras.models import Sequential
from keras.layers.core import Activation, Dense
from keras.optimizers import SGD
X = np.array([[0,0],[0,1],[1,0],[1,1]], "float32")
y = np.array([[0],[1],[1],[0]], "float32")
model = Sequential()
model.add(Dense(2, input_dim=2, activation='sigmoid'))
@masterdezign
masterdezign / network.py
Last active July 8, 2017 16:38
Backpropagation in Python
from random import random
from numpy import tanh
from scipy import array, vectorize, transpose
class Network:
""" Class builds neural network
"""
def __init__(self, inputs, outputs, hlayers=None, activation=tanh,
learning_rate=1.):
@masterdezign
masterdezign / gist:5eb03e834299b8b67750
Last active November 15, 2017 20:03
Remark.js+MathJax essentials
<!DOCTYPE html>
<html>
<head>
<title>My Presentation</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
.red { color: red }
</style>
</head>
<body>
-- Run a one dimensional gradient descent written in Clash [1],
-- a high level language that compiles to Verilog and VHDL.
-- Gradient descent can be described by a formula:
--
-- a_n+1 = a_n - gamma * Grad F(a_n),
--
-- where the constant `gamma` is what is referred to in deep learning as
-- the learning rate.
--
-- [1] https://clash-lang.org/
@masterdezign
masterdezign / Grad.hs
Last active December 10, 2018 13:23
A brief gradient descent illustration in Haskell
descent1D gradF iterN gamma x0 = take iterN (iterate _descend x0)
where
_descend gamma' x = x - gamma' * gradF x
-- Suppose, we have a function F(x) = (x - 3)^2.
-- Therefore, Grad F(x) = 2 * (x - 3).
gradF_test x = 2 * (x - 3)
main = print (descent1D gradF_test 10 gamma 0.0)
where gamma = 0.5
@masterdezign
masterdezign / cellular.py
Created January 21, 2019 10:37
Cellular automata in Python
#!/usr/bin/env python3
"""
Cellular automata in Python
"""
import sys
Z = '.'
O = '#'
@masterdezign
masterdezign / timelapse.sh
Created March 20, 2020 10:52
A video from images
# Concatenate images
ffmpeg -framerate 5 -pattern_type glob -i "*.jpg" output.mp4
# Compress
ffmpeg -i output.mp4 -vcodec libx265 -acodec aac -crf 23 output_compressed.mp4