Skip to content

Instantly share code, notes, and snippets.

View dpiponi's full-sized avatar
🧱
In material form

Dan Piponi dpiponi

🧱
In material form
View GitHub Profile
@dpiponi
dpiponi / self.py
Last active June 14, 2017 17:28
Here are some tanh units being self-normalising
# See "Self-Normalizing Neural Networks" https://arxiv.org/abs/1706.02515
# "SNNs cannot be derived with...tanh units..."
# So I'm probably missing the point somewhere...
import math
import numpy
# Magic number
lambda0 = 1.59254
@dpiponi
dpiponi / self.py
Created June 13, 2017 22:21
Here are some tanh units being self-normalising
import math
import numpy
lambda0 = 1.59254
n = 1000
nlayers = 100
# Incoming activiations have mean 0, variance 1
x = numpy.random.normal(0, 1, n)
{-# LANGUAGE FlexibleContexts #-}
-- Version 2.0
import Data.Ratio
(*!) _ 0 = 0
(*!) a b = a*b
(^+) a b = zipWith (+) a b
@dpiponi
dpiponi / log.hs
Created February 1, 2017 17:46
Compute "functional logarithm" of x -> x+x^2
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
-- Uses exact-real package
import Data.Ratio
import Data.CReal
(*!) _ 0 = 0
(*!) a b = a*b
@dpiponi
dpiponi / comb.hs
Created January 31, 2017 16:06
Compute formal power series for functional square root of sin function
import Data.Ratio
(^+) a b = zipWith (+) a b
(^-) a b = zipWith (-) a b
(a : as) `convolve` (b : bs) = (a * b) :
((map (a *) bs) ^+ (as `convolve` (b : bs)))
compose (f : fs) (0 : gs) = f : (gs `convolve` (compose fs (0 : gs)))
@dpiponi
dpiponi / pearcey.py
Created September 12, 2016 00:30
Pearcey integral
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as integrate
# Dimension of image in pixels
N = 256
# Number of samples to use for integration
M = 33
@dpiponi
dpiponi / swallowtail.py
Created September 11, 2016 19:38
The swallowtail catastrophe with diffraction
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as integrate
# Dimension of image in pixels
N = 256
# Number of samples to use for integration
M = 257
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import scipy.integrate as integrate
# Dimension of image in pixels
N = 256
# Number of samples to use for integration
M = 257
@dpiponi
dpiponi / elliptic-umbilic.py
Created September 10, 2016 16:29
The elliptic umbilic caustic rendered with diffraction
# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import random
import scipy.integrate as integrate
# Dimension of image in pixels
N = 129
# Number of samples to use for integration
@dpiponi
dpiponi / graph.hs
Created August 26, 2016 13:58
Perfect matchings and continued fractions
import Data.Ratio
import Data.List
import Control.Monad
-- I'm using two Haskell types for the two vertex types in
-- a bipartite graph.
-- Edges only go from type a to type b.
data BipartiteGraph a b = G [a] [b] [(a, b)]
instance (Show a, Show b) => Show (BipartiteGraph a b) where