Skip to content

Instantly share code, notes, and snippets.

@Slater-Victoroff
Slater-Victoroff / gist:8426757
Created January 14, 2014 22:04
I've gone too far this time
import collections
def rec_dict():
"""
Just a recursive dictionary
"""
return collections.defaultdict(rec_dict)
class Tree(object):
@Slater-Victoroff
Slater-Victoroff / gist:8543588
Last active January 4, 2016 00:39
Simplest Possible Geometric Restricted Boltzmann Machine. Doesn't include training, just random generation and prediction for now.
import numpy as np
def transfer_function(x, y):
return np.power(np.prod(x, axis=1)[:, None] * np.prod(y, axis=0), 1./x.shape[1])
def gnn(c):
return normalize([np.random.random(c[i] * c[i + 1]).reshape((c[i], c[i + 1])) for i in range(len(c) - 1)])
def predict(weights, input_vector, reverse=False):
current_net = [input_vector] + weights
@Slater-Victoroff
Slater-Victoroff / nn.jl
Created February 11, 2014 06:13
Julia Neural Net
type NeuralNet
weight_matrices::Array{Array{FloatingPoint}}
NeuralNet(layer_sizes::Array{Int64}) = new([
rand(layer_sizes[i], layer_sizes[i+1]) for i in [1:length(layer_sizes)-1]
])
end
function predict(input_vector::Array{Float64}, net::NeuralNet)
unshift!(net.weight_matrices, input_vector)
def fired(inputs, threshold):
if sum(inputs) > threshold:
return True
else:
return 0
@Slater-Victoroff
Slater-Victoroff / and.py
Created March 10, 2014 06:58
Neural AND Gate
import numpy as np
def neural_logic_gate(input_vector, weight_matrix=[0.5, 0.5], threshold=0.75):
return np.dot(input_vector, weights) > threshold
@Slater-Victoroff
Slater-Victoroff / transfer.py
Created March 10, 2014 07:33
Neural Transfer Function
import numpy as np
def transfer_function(input_vector, weight_matrix, threshold):
return np.dot(input_vector, weight_matrix) > threshold
@Slater-Victoroff
Slater-Victoroff / neural_net.py
Created March 10, 2014 08:02
Simple Neural Net
import numpy as np
def normalize(vector, span=(0,1)):
minimum, maximum = (np.min(vector), np.max(vector))
scaling = (span[1] - span[0]) / (maximum - minimum)
return ((vector - minimum) * scaling) + span[0]
class NeuralNet(object):
def __init__(self, layer_sizes=(10,50,20), threshold=0.5):
@Slater-Victoroff
Slater-Victoroff / normalize.py
Created March 10, 2014 08:07
Normalization
def normalize(vector, span=(0,1)):
minimum, maximum = (np.min(vector), np.max(vector))
scaling = (span[1] - span[0]) / (maximum - minimum)
return ((vector - minimum) * scaling) + span[0]
from zipline.algorithm import TradingAlgorithm
from zipline.transforms import MovingAverage
from zipline.utils.factory import load_from_yahoo
from zipline.finance.slippage import FixedSlippage
from zipline.finance.commission import PerShare
from datetime import datetime
import matplotlib.pyplot as plt
class DualMovingAverage(TradingAlgorithm):
import json, os
from boto.s3.connection import S3Connection, OrdinaryCallingFormat
from boto.s3.key import Key
CREDENTIALS = ['AWSAccessKeyId', 'AWSSecretKey']
class MissingCredentialsException(Exception):
def __init__(self, credentials_dict):