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])))
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() |
% 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 |
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) |
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]; |
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; |
(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}}`; |
const babel = require('babel-standalone'); | |
const fs = require('fs'); | |
const express = require('express'); | |
const app = express(); | |
app.get('/*.jsx', function(req, res){ | |
fs.readFile('.'+req.path, (err,data)=>{ | |
res.send(babel.transform(data, {presets:['react']}).code); | |
}); | |
}); |
var cheerio = require('cheerio'); | |
var Promise = require("bluebird"); | |
var request = Promise.promisifyAll(require('request')); | |
var WebSocket = require('ws'); | |
var email = "SE email", | |
password = "SE pw", | |
roomid = 17; | |
var j = request.jar() |