Skip to content

Instantly share code, notes, and snippets.

@danstowell
danstowell / schroeder.scd
Created February 2, 2016 14:52
Generate Schroeder-phase complexes in Supercollider
// schroeder-phase waveforms
s.boot
s.scope
// we'll do the simple flat-spectra case
// (The paper I saw this version in is "Phase effects on the perceived elevation of complex tones", <http://dx.doi.org/10.1121/1.3372753>.)
~nb = 5;
~nt = 250;
@danstowell
danstowell / maxpool_undo.py
Created January 11, 2016 12:00
A version of https://gist.github.com/danstowell/192ad65527965086693d exhibiting buggy shape behaviour?
import numpy as np
from numpy import float32
import theano
import theano.tensor as T
import lasagne
######################################################
# Test of reversing maxpooling
@danstowell
danstowell / maxpool_undo.py
Last active January 11, 2016 13:14
Test to show Lasagne/Theano automagically doing one-hot upsampling to reverse maxpooling
import numpy as np
from numpy import float32
import theano
import theano.tensor as T
import lasagne
######################################################
# Test of reversing maxpooling
init_OSC
empty
compiling class library...
NumPrimitives = 711
compiling dir: '/usr/local/share/SuperCollider/SCClassLibrary'
compiling dir: '/usr/local/share/SuperCollider/Extensions'
pass 1 done
ERROR: Class extension for nonexistent class 'Document'
In file:'/deprecated/3.7/deprecated-3.7.sc'
ERROR: Class extension for nonexistent class 'KDTree'
@danstowell
danstowell / wiener_deconvolution_example.py
Last active April 19, 2024 09:41
Simple example of Wiener deconvolution in Python
#!/usr/bin/env python
# Simple example of Wiener deconvolution in Python.
# We use a fixed SNR across all frequencies in this example.
#
# Written 2015 by Dan Stowell. Public domain.
import numpy as np
from numpy.fft import fft, ifft, ifftshift
@danstowell
danstowell / stderr
Last active August 29, 2015 14:21
theano.test() failure report (Linux 3.13.0-49-generic; Ubuntu 14.04; cuda tools V7.0.27; CUDNN_VERSION 2000; gpu is GeForce GT 730M; python 2.7; theano 0.7.0; gcc Ubuntu 4.8.2-19ubuntu1)
/usr/local/lib/python2.7/dist-packages/theano/misc/pycuda_init.py:34: UserWarning: PyCUDA import failed in theano.misc.pycuda_init
warnings.warn("PyCUDA import failed in theano.misc.pycuda_init")
Using gpu device 0: GeForce GT 730M
...............................................K................../usr/local/lib/python2.7/dist-packages/theano/compile/profilemode.py:103: UserWarning: DEPRECATION WARNING: The ProfileMode is deprecated. Use the Theano flags/parameter to theano.function 'profile=True' instead of 'mode=ProfileMode'
"DEPRECATION WARNING: The ProfileMode is deprecated. Use the Theano"
................................................../usr/local/lib/python2.7/dist-packages/theano/gof/vm.py:729: UserWarning: CVM does not support memory profile, using Stack VM.
'CVM does not support memory profile, using Stack VM.')
................................./usr/local/lib/python2.7/dist-packages/theano/gof/cmodule.py:293: RuntimeWarning: numpy.ndarray size changed, may indicate binary incompatibility
rva
@danstowell
danstowell / data_for_nmf.data.R
Last active May 18, 2020 14:15
Implementations of non-negative matrix factorisation (NMF) in Stan
N <- 15
M <- 12
K <- 3
Wconc <- 100
Hconc <- 5
Winit <- structure(c(.056,.111,.056,.111,.056,.111,.056,.111,.056,.111,.056,.111,.111,.056,.111,.056,.111,.056,.111,.056,.111,.056,.111,.056,.063,.063,.125,.063,.063,.125,.063,.063,.125,.063,.063,.125
), .Dim=c(12,3))
X <- structure(c(.032,.032,.091,.032,.157,.264,.157,.139,.486,.257,.709,.934,.036,.036,.08,.036,.255,.192,.255,.1,.638,.171,1.228,.62,.039,.039,.226,.039,.119,.521,.119,.128,.809,.227,.475,1.537,.047,.047,.212,.047,.113,.589,.113,.242,.717,.458,.407,2.002,.02,.02,.058,.02,.07,.189,.07,.107,.251,.203,.293,.705,.033,.033,.062,.033,.128,.268,.128,.208,.325,.403,.549,1.142,.039,.039,.245,.039,.144,.516,.144,.081,.923,.128,.609,1.39,.05,.05,.189,.05,.326,.383,.326,.091,1.077,.136,1.55,1.024,.039,.039,.245,.039,.106,.548,.106,.112,.847,.194,.407,1.565,.023,.023,.134,.023,.072,.301,.072,.065,.486,.112,.291,.862,.04,.04,.145,.04,.205,.352,.205,.131,.726,.233,.938,1.107,.028,.028,.173,.028,.076,.397,.076,.093,.593,.164,.287,1.163,.028,.028,.058,.028,.14,.1
N <- 200
K <- 4
timepos <- c(0.0, 2.08978153718, 2.6774000865, 3.47584796473, 3.78710127148, 4.75454597707, 6.66987539583, 7.24902152136, 8.49394193938, 10.4795896694, 10.7914520039, 11.4969222693, 13.3095734861, 14.7212655024, 15.2931492467, 15.4171748097, 15.7443055882, 16.3382608385, 19.567384084, 20.9367692864, 22.0817809742, 22.7254312132, 23.403135471, 23.8066143306, 25.4891533587, 26.6521259878, 28.8649882504, 28.9655706897, 29.1462279535, 30.8224952884, 32.4190207294, 32.4851131989, 33.7009422433, 34.200217965, 35.0046621559, 36.5020537758, 37.2170190379, 37.9581204385, 37.9809986145, 39.206561022, 39.5827104717, 39.9391764411, 39.9627692061, 41.1659966046, 41.8917759456, 44.1068011549, 44.4874876662, 45.468215782, 46.0485677517, 47.0857797338, 47.9105602445, 48.3423708895, 51.2038621099, 51.6573257642, 52.1885429832, 54.4739163581, 55.63263262, 55.7679908666, 57.0184307288, 58.4159798588, 58.6414905971, 61.4434801692, 61.9000345735, 62.64477926, 63.23209667, 65.3153604468, 65.7821474602, 66.397281497
@danstowell
danstowell / mapat_chance.py
Created April 8, 2014 19:20
Empirical plot of the chance values attained for the "Mean Average Precision" statistic
# understanding chance level in MAP calculation
import ml_metrics
import numpy as np
import matplotlib.pyplot as plt
results = np.zeros((100,100))
data = np.zeros((100, 10))
# no need to shuffle the annots since the groundtruth will be randomly generated
@danstowell
danstowell / crosstab.py
Last active August 29, 2015 13:56
Cross-tabulation analysis of the data comparing HOT OSM building damage annotations against damage annotations from the American Red Cross, at https://github.com/AmericanRedCross/OSM-Assessment/tree/gh-pages/data
#!/usr/bin/env python
import os, json
import numpy as np
# crosstabulate the geojson records for OSM damage indicators vs "observed" (by American Red Cross analysts) damage
datadir = '.'