Skip to content

Instantly share code, notes, and snippets.

def fired(inputs, threshold):
if sum(inputs) > threshold:
return True
else:
return 0
@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)
@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 / 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:6681032
Last active December 23, 2015 19:09
Simple Flask Server for parsing LabView XML and doing some scant logic.
import flask
import sys
from flask import Flask, request
import random
from lxml import etree
import xmltodict
import numpy as np
import operator
@Slater-Victoroff
Slater-Victoroff / gist:6299996
Created August 21, 2013 20:42
Determine the most random language
from pyfuzz.generator import random_regex
from guess_language import guessLanguageName
from collections import Counter
def randomness_histogram(iterations, length):
return Counter((guessLanguageName(random_regex(regex="[a-z \n]", length=length)) for i in xrange(length)))
print randomness_histogram(1000, 200).most_common(10) # returns the 10 most common languages
@Slater-Victoroff
Slater-Victoroff / PyMarkov
Last active March 28, 2022 13:55
Arbitrary ply markov constructor in python
from collections import Counter
import cPickle as pickle
import random
import itertools
import string
def words(entry):
return [word.lower().decode('ascii', 'ignore') for word in entry.split()]
def letters(entry):
@Slater-Victoroff
Slater-Victoroff / gist:6193947
Created August 9, 2013 14:19
The most functional line of python
def random_document(document_layout, type, **kwargs):
document_layout.append("dummy_item")
doc = lambda l:{l[i]:doc(l[i+1]) if isinstance(l[i+1],list) else random_item(type,**kwargs) for i in range(len(l)-1)}
return doc(document_layout)
@Slater-Victoroff
Slater-Victoroff / gist:6156734
Created August 5, 2013 15:19
ElasticSearch Settings file
{
"mappings": {
"properties": {
"searchable_text": {
"type": "multi_field",
"fields": {
"full_words": {
"type": "string",
"store": "yes",
"index": "analyzed",
from flask import Blueprint, request, redirect, render_template, url_for
from flask.views import MethodView
from flask.ext.mongoengine.wtf import model_form
from SpoolEngine.auth import requires_auth
from SpoolEngine.models import Post, BlogPost, Video, Image, Quote, Comment
admin = Blueprint('admin', __name__, template_folder='templates')