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 / 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 / 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 / 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
{-# LANGUAGE FlexibleContexts #-}
-- Version 2.0
import Data.Ratio
(*!) _ 0 = 0
(*!) a b = a*b
(^+) a b = zipWith (+) a b
@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)
@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
> import qualified Data.Map as M
> vowel :: Char -> Bool
> vowel 'a' = True
> vowel 'e' = True
> vowel 'i' = True
> vowel 'o' = True
> vowel 'u' = True
> vowel _ = False
@dpiponi
dpiponi / ellipse.py
Created August 12, 2017 17:07
Compute perimeter of ellipse
# Based on http://www.ams.org/notices/201208/rtx120801094p.pdf
import math
EPS = 1e-8
# Arithmetico-geometric mean
def agm(a, b):
while True:
a1 = 0.5*(a+b)
@dpiponi
dpiponi / main.hs
Created November 25, 2017 18:30
Primality test based on Chebyshev polynomials
import Data.Bits
import Control.Monad
type Z = Integer
-- Find smallest power of two >= given integer.
-- Sadly it's not convenient using the usual interface to Integer
-- Got exceptions when using Data.Bits.Bitwise
suitablePower :: Z -> Int
@dpiponi
dpiponi / simple.py
Created December 16, 2017 01:23
Neural style transfer based on https://arxiv.org/abs/1508.06576. I don't vouch for the current set of parameters in this code...
# See https://arxiv.org/abs/1508.06576
import tensorflow as tf
import numpy
import imageio
import scipy.io
print "Tensorflow Version", tf.__version__
# Options