Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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
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 / 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
@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 / 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 / wikidata_scan_osm.py
Created March 22, 2017 22:27
Script to build Wikidata -> OpenStreetMap lookup table
import os, sys, re
from datetime import datetime
from imposm.parser import OSMParser
########################################################
#osmsourcelbl = 'greater-london'
#osmsourcelbl = 'great-britain'
osmsourcelbl = 'planet'
@danstowell
danstowell / woodland_falsecolour.ipynb
Created October 16, 2017 14:11
Quick hack at a kind of false-colour long-duration spectrogram inspired by Towsey et al http://dx.doi.org/10.1016/j.procs.2014.05.063 - incomplete
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
import numpy as np
from numpy import log
# we generate two independent "parent" processes, then for each one we independently create thinnings.
# we aim to have a distance measure that correctly clusters the two sets according to their parent.
# by Dan Stowell, copyright Feb 2018
parents = [np.cumsum(np.random.exponential(size=100)) for whichp in range(2)]