This file contains hidden or 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 collections | |
def rec_dict(): | |
""" | |
Just a recursive dictionary | |
""" | |
return collections.defaultdict(rec_dict) | |
class Tree(object): |
This file contains hidden or 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 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 |
This file contains hidden or 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
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) |
This file contains hidden or 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
def fired(inputs, threshold): | |
if sum(inputs) > threshold: | |
return True | |
else: | |
return 0 |
This file contains hidden or 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 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 |
This file contains hidden or 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 numpy as np | |
def transfer_function(input_vector, weight_matrix, threshold): | |
return np.dot(input_vector, weight_matrix) > threshold |
This file contains hidden or 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 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): |
This file contains hidden or 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
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] |
This file contains hidden or 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
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): |
This file contains hidden or 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 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): |