Last active
June 13, 2017 16:10
-
-
Save r9y9/3d0c6a90dd155801c4c1 to your computer and use it in GitHub Desktop.
GaP-NMF short benchmark scripts for Python and Julia.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
push!(LOAD_PATH, ".") | |
using BNMF | |
using PyCall | |
# bp_nmf のコードと比較するために、librosaを使う | |
@pyimport librosa | |
function spectrogram() | |
x, ss = librosa.load("test.wav", sr=16000) | |
X = abs(librosa.stft(x, n_fft=1024, hop_length=256)) | |
return X | |
end | |
function test_gap(X) | |
srand(98765) | |
p = GaPNMF(X, K=100) | |
fit!(p, epochs=100, verbose=true) | |
nothing | |
end | |
function benchmark(N) | |
X = spectrogram() | |
elapsed = Array(Float64, N) | |
for i=1:N | |
tic() | |
test_gap(X) | |
elapsed[i] = toc() | |
end | |
println("Mean elapsed time: $(mean(elapsed))") | |
end | |
benchmark(10) | |
versioninfo() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import gap_nmf | |
import librosa | |
import numpy as np | |
import scipy | |
import time | |
def spectrogram(): | |
x, _ = librosa.load('test.wav', sr=16000) | |
X = np.abs(librosa.stft(x, n_fft=1024, hop_length=256)) | |
return X | |
def test_gap(X): | |
obj = gap_nmf.GaP_NMF(X, K=100, seed=98765) | |
score = -np.inf | |
for i in range(100): | |
obj.update() | |
# obj.figures() | |
lastscore = score | |
score = obj.bound() | |
improvement = (score - lastscore) / np.abs(lastscore) | |
print('iteration {}: bound = {:.2f} ({:.5f} improvement)'.format( | |
i, score, improvement)) | |
def benchmark(N=100): | |
X = spectrogram() | |
elapsed = [] | |
for n in range(N): | |
s = time.clock() | |
test_gap(X) | |
e = time.clock() - s | |
elapsed.append(e) | |
print(e) | |
print("Mean elapsed time:", np.mean(elapsed)) | |
benchmark(10) | |
np.show_config() | |
scipy.show_config() | |
librosa.show_versions() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ubuntu 16.04
Julia
Python