Skip to content

Instantly share code, notes, and snippets.


Cyril Auburtin caub

View GitHub Profile
caub /
Last active Aug 29, 2015
Border effects, the importance of padding method

padding in green without padding, in red with symmetric padding

% generate a  noisy signal
y = flipud( 3*sin(0.14*(1:128)')-1/20*(1:128)'+ (((1:128)'-64)/20).^2 + randn(128,1));
w=[-21;14;39;54;59;54;39;14;-21]/231; %

z = zeros(length(y)+10,1); % bigger
z(5:end-4) = y; 
z(1:5) = flipud(z(6:10)); % symmetric padding
caub / normalize.m
Last active Aug 29, 2015
normalizes data
View normalize.m
% classic case, feature are by column
function [Xnorm, Xmean, Xsigma] = normalizeFeature(X)
Xmean = mean(X);
Xnorm = bsxfun(@minus, X, Xmean);
Xsigma = sqrt(sum(Xnorm.^2)/(size(Xnorm,1)-1));
Ynorm = bsxfun(@rdivide, Xnorm, Xsigma);
% all this is equivalent to zscore(X) :)
% for example collaborative filtering sets, classes are in row, and users in col


X =[-1 -1; -2 -1;-3 -2;1 1;2 1; 3 2];
y = [1 1 1 2 2 2];
m = lda(X,y);
m.predict([-0.8 -1]) %1
hold on
subtract = @(X) X(:,2) - X(:,1);
ezplot(@(x,y) subtract(m.decision_function([x y])))
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException,ElementNotVisibleException
import time
import requests
import json
import urlparse
browser = webdriver.Firefox()
View rsi.m
% largely inspired from
% small script to generate signals from rsi indicator, and calculate the return
function [s,r,sh,mar] = rsi(price,M,N,thresh,scaling,cost)
% returns the signals array, the returns array (profit and loss), the
% sharpe ratio, the MAR ratio
if nargin==0
% fill params for you..
M = 22; % Moving Average for rsi
N = 14; % rsi loopback
caub /
Last active Aug 29, 2015


The positions of green nodes are initially set, other nodes are guessed incrementally from neighbors distance. A noise is added to distances, up to N(0, 1.7^2) to simulate measurement error, greater values can make the nodes positions diverge importantly
To fix this stability problem, it's possible to avoid 'flat' triangles (where the 3 points are almost collinear)
Other perspective: make it work in 3D, or more, with the intersection of (n+1) n-spheres, compare with more robust optimizations in litterature
Another perspective, average the result of multiple different estimations for a node positions, to eliminate the noise better

from scipy import *
def sma(v, k):
weights = repeat(1.0,k)/k
return convolve(v, weights, 'valid')
def ema(v, k):
weights = exp(linspace(-1,0,k))
weights /= weights.sum()
#print 'we: %s' % weights
#print 'c: %s' % convolve(v, weights)
caub / conv.js
Last active Aug 29, 2015
convolution product in js
View conv.js
function conv(a, b, mode){
var dl = b.length-1
var aa=a.concat(repeat(0, dl)) //0-padding
var c=[]
for(var i=0;i<aa.length;i++){
for(var m=0;m<aa.length;m++)
if (0<=i-m && i-m<b.length)
package ws;
import java.lang.reflect.Type;
import java.util.LinkedHashMap;
import java.util.concurrent.Future;
caub / scoped.js
Last active Jul 24, 2016
<style scoped> polyfill
View scoped.js
let scopedRule = (scope, {selectorText: selector='', cssText:css, style: {cssText}={}, styleSheet, cssRules, media}) =>
styleSheet? // @import rules
scopedRules(scope, styleSheet.cssRules):
cssRules && media? // @media rules
`@media ${Array.from(media).join(',\n')} {${scopedRules(scope, cssRules)}}`:
`${selector.split(',').map(s=>`${scope} ${s}`).join(', ')} {${cssText}}`;
//`${selector.replace(/([^,]+)/g, (_, s) => `${scope} ${s}`)} {${cssText}}`;