This file contains hidden or 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
class Table(dict): | |
def __getattr__(self, name): | |
return self[name] if name in self else None | |
def __setattr__(self, name, value): | |
if value is not None: | |
self[name] = value | |
elif name in self: | |
del self[name] | |
def __delattr__(self, name): | |
self.__setattr__(name, None) |
This file contains hidden or 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
class Constant(Module): | |
def __init__(self, val = 0): | |
self.out = val | |
def __repr__(self): | |
return 'Constant({})'.format(self.out) | |
class Mul(Module): | |
def __repr__(self): | |
return 'Mul()' |
This file contains hidden or 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
local function utf8_iter(s, i) | |
if i >= #s then return end | |
local b, nbytes = s:byte(i+1,i+1), 1 | |
-- determine width of the codepoint by counting the number if set bits | |
-- from top to bottom. not 100% to standard, but it works well enough | |
if b/4 >= 63 then nbytes = 6 | |
elseif b/8 >= 31 then nbytes = 5 | |
elseif b/16 >= 15 then nbytes = 4 | |
elseif b/32 >= 7 then nbytes = 3 |
This file contains hidden or 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
#include <omp.h> | |
#include <vector> | |
#include <complex> | |
#include <iostream> | |
#include <fstream> | |
#include <sstream> | |
#include <exception> | |
#include <string> | |
#include <cstdint> |
This file contains hidden or 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
-- Euclidean rythm (http://en.wikipedia.org/wiki/Euclidean_Rhythm) | |
function rythm(k,n) | |
local r = {} | |
for i = 1,n do | |
r[i] = {i <= k} | |
end | |
local function cat(i,k) | |
for _,v in ipairs(r[k]) do | |
r[i][#r[i]+1] = v |
This file contains hidden or 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
module Crossvalidation | |
export KFold, StratifiedKFold, LOO, RandomSplit | |
#== | |
K-Fold cross validation | |
Example (5-Fold CV): | |
KFold(X, y, 5) do X_tr, y_tr, X_te, y_te | |
train!(model, X_tr, y_tr) |
This file contains hidden or 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
function forward_difference(c::Matrix) | |
out = zeros(c) | |
@simd for i = 1:size(c,1)-1 | |
@inbounds out[i,:] = c[i+1,:] - c[i,:] | |
end | |
@inbounds out[size(c,1),:] = c[1,:] - c[size(c,1),:] | |
out | |
end | |
function at(c::Matrix, t::Number, Δc::Matrix, cumlen::Vector{Float64}) |
This file contains hidden or 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
type Perceptron | |
w::Vector{Float64} | |
Perceptron(d::Int) = new(zeros(d)) | |
Perceptron(w::Vector{Float64}) = new(w) | |
end | |
type Winnow | |
w::Vector{Float64} | |
η::Float64 | |
Perceptron(d::Int, η::Float64) = new(ones(d)./d, η) |
This file contains hidden or 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
function chol_(A::Matrix, L::Matrix) | |
for i = 1:size(A,1) | |
s = 0 | |
@simd for j = 1:i-1 | |
@inbounds L[i,j] = (A[i,j] - sum([L[i,k]*L[j,k] for k = 1:j-1])) / L[j,j] | |
@inbounds s += L[i,j]^2 | |
end | |
L[i,i] = sqrt(A[i,i] - s) | |
end | |
L |
This file contains hidden or 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
import requests | |
from collections import namedtuple | |
class Dirble(object): | |
Category = namedtuple("Category", "id name description") | |
Station = namedtuple("Station", "id name streamurl country bitrate status") | |
StationDetails = namedtuple("StationDetails", "id name streamurl country bitrate status description added urlid website songhistory") | |
Song = namedtuple("Song", "artist title") | |
def __init__(self, key, base_url): |