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 / main.py
Created June 3, 2018 00:59
Tring to generate random vectors that look like eigenvalues of random matrices
from __future__ import print_function
import argparse
import torch
import torch.utils.data
from torch import nn, optim
from torch.nn import functional as F
from torchvision import datasets, transforms
from torchvision.utils import save_image
import numpy
@dpiponi
dpiponi / main.hs
Created February 17, 2018 20:16
Infinitely differentiable stochastic functions
{- LANGUAGE UnicodeSyntax -}
import Prelude hiding (sum)
import Control.Monad
import qualified System.Random as R
import qualified Data.Map.Strict as M
--
-- Define formal power series
-- I'm just using lists of coefficients rather than defining a new type.
import System.IO
import Data.List
rot :: Int -> String -> String
rot n s =
let (body, tail) = splitAt n s
in tail ++ body
lookups :: [String] -> [String] -> [String]
lookups [] _ = []
/*
* This is a literate quine. That means that
* 1. the comments will tell you a little about how it works and
* 2. if you compile and run it its output will be identical to its source
* code even though it doesn't look at its original source. It literally
* contains within itself a complete recipe for how to display itself.
*
* Quines are ten a penny. This one is unusual because
* 1. its main loop consists solely of a loop to print characters
* generated by a function called programChar() and
@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
@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 / 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)
> 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 / 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)