Skip to content

Instantly share code, notes, and snippets.

Avatar
🚲

Cyril Auburtin caub

🚲
View GitHub Profile
@caub
caub / bordereffects.md
Last active Aug 29, 2015
Border effects, the importance of padding method
View bordereffects.md

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; % http://en.wikipedia.org/wiki/Savitzky%E2%80%93Golay_filter#Tables_of_selected_convolution_coefficients

z = zeros(length(y)+10,1); % bigger
z(5:end-4) = y; 
z(1:5) = flipud(z(6:10)); % symmetric padding
@caub
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
View LDA.md

lda

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
gscatter(X(:,1),X(:,2),y','rb','v^',[],'off');
hold on
subtract = @(X) X(:,2) - X(:,1);
ezplot(@(x,y) subtract(m.decision_function([x y])))
View mountain_goats.py
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 http://www.mathworks.fr/matlabcentral/fileexchange/37932-automated-trading-with-matlab-2012
% 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
caub / Triangulations.md
Last active Aug 29, 2015
triangulations
View Triangulations.md

triangulations

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

View indic.py
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
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++){
c[i]=0;
for(var m=0;m<aa.length;m++)
if (0<=i-m && i-m<b.length)
c[i]+=aa[m]*b[i-m];
View SEChat.java
package ws;
import java.lang.reflect.Type;
import java.net.CookieManager;
import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.URI;
import java.util.LinkedHashMap;
import java.util.concurrent.Future;
@caub
caub / scoped.js
Last active Jul 24, 2016
<style scoped> polyfill
View scoped.js
(function(){
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||selector.startsWith(':root')||selector.startsWith('body')?
css:
`${selector.split(',').map(s=>`${scope} ${s}`).join(', ')} {${cssText}}`;
//`${selector.replace(/([^,]+)/g, (_, s) => `${scope} ${s}`)} {${cssText}}`;