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
""" | |
Fit a Gaussian process to a signal using SKLearn. | |
""" | |
import numpy as np | |
from sklearn import gaussian_process | |
from sklearn.gaussian_process import kernels as K | |
import matplotlib.pyplot as plt | |
from scipy.signal import resample | |
import argparse |
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
import torch | |
import torch.nn as nn | |
from torch.autograd import Variable | |
__CUDA__ = torch.cuda.is_available() | |
class CausalConv1d(nn.Module): | |
""" | |
A causal 1D convolution. | |
""" |
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
""" | |
Tensorflow ops for computing percent-identity between two sequences. | |
""" | |
import tensorflow as tf | |
def sparsify_seq(dseq, maxtime, pad_value=0): | |
""" | |
Convert a dense rank-2 sequence tensor `dseq` to a sparse tensor, applying masking to | |
pad values to avoid spuriously high edit distances when comparing two sparsified | |
tensors. |
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
class GaussianNoiseWrapper(tf.contrib.rnn.RNNCell): | |
""" | |
Wrapper for RNNCells to add gaussian noise to the input with specified mean, | |
stdv before each call of the internal RNNCell. | |
(The structure of this wrapper class follows the design of wrappers in tf.contrib.rnn | |
such as InputProjectionWrapper, DropoutWrapper, OutputProjectionWrapper, etc.) | |
""" | |
def __init__(self, cell, mean=0.0, stddev=0.1): | |
""" |
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
""" | |
Binomial asset price dynamics model class definiton. | |
""" | |
class BinomialModel: | |
""" | |
Initialize with the following parameters: | |
R <- interest rate on cash account investment; | |
u <- up movement percentage (d := 1/u); |
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
function median(A,B,x,y) { | |
/* | |
Function that takes sorted arrays A and B and their medians x and y | |
and returns the median of A.concat(B). | |
x is assumed to be the median of A and y is assumed to be the median | |
of B. | |
Arrays are assumed to be the same length. (Arrays of differing length | |
may be handled with a different recursion case.) |
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
function dist(p,q) { | |
/* | |
Euclidean distance function between two points. | |
*/ | |
return Math.sqrt((p.x - q.x)^2, (p.y - q.y)^2); | |
} | |
function average(datapts) { | |
/* | |
Takes an array of datapoints, where each |
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
boundingSphere :: [(Float,Float,Float)] -> ((Float,Float,Float),Float) --takes a list of points in 3D to a pair (center,radius) | |
boundingSphere points = | |
case points of --induction on number of points: 0,1,2, or 3+ | |
[] -> ((0,0,0),0) | |
p:[] -> (p,0) | |
(p1,p2,p3):(q1,q2,q3):[] -> (((p1+q1)/2,(p2+q2)/2,(p3+q3)/2),dist (p1,p2,p3) (q1,q2,q3)) | |
p:pts -> let | |
y@(y1,y2,y3) = head $ filter (\pt -> (dist pt p) - 0.1 < (maximum $ map (dist p) pts)) pts | |
z@(z1,z2,z3) = head $ filter (\pt -> (dist pt y) - 0.1 < (maximum $ map (dist y) pts)) pts | |
initSphere@(ctr,rad) = (((y1+z1)/2, (y2+z2)/2, (y3+z3)/2), dist y z / 2) |