Skip to content

Instantly share code, notes, and snippets.

@asw456
asw456 / belkin.py
Created July 15, 2013 21:26
munge data from Belkin Kaggle Challenge
# coding: utf-8
# import scipy.io as io
from scipy import linspace, io
from pylab import *
from cmath import phase
from math import *
# Load the .mat files
testData = io.loadmat('BelkinTestData_1.mat')
taggingData = io.loadmat('TaggingInfo_1.mat')
@asw456
asw456 / convert.py
Created July 19, 2013 04:18 — forked from paulgb/convert.py
'''
Convert Yelp Academic Dataset from JSON to CSV
Requires Pandas (https://pypi.python.org/pypi/pandas)
By Paul Butler, No Rights Reserved
'''
import json
import pandas as pd
@asw456
asw456 / lab4gs.m
Last active December 20, 2015 11:09
scriptLab4
function [convf,k,results,xn] = mygaussseidel(A,b,x,niter,tol)
[nrow,~] = size(A);
convf = 0;
results(1,:) = x';
xn = x;
for k = 1:niter
for i = 1:nrow
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD 150,000 ns 0.15 ms
Read 1 MB sequentially from memory 250,000 ns 0.25 ms
Round trip within same datacenter 500,000 ns 0.5 ms
@asw456
asw456 / lab5function.m
Last active December 20, 2015 18:09
lab5
function [ L,A,B,C,D ] = mydivdiff( x, f )
% INPUTS: x - Nx1 vector of x values at which data for the function is specified
% f - Nx1 vector of corresponding function values
% OUTPUTS: A - (N-1)x(N-1) table of divided differences
n = size(x,1);
L = zeros(n-1);
L(:,1) = (f(2:n)-f(1:n-1))./(x(2:n)-x(1:n-1));
@asw456
asw456 / newton_function.m
Created August 11, 2013 10:09
emth 271 lab 3
function results = mymultinewtfunction(x, func, niter, tol)
for i = 1:niter
n = max(size(x));
%f = [(log(x(1)) - x(2)) , ((x(1)^2+2*x(1)-24)/25 - x(2))];
%J = [1/x(1), -1 ; 2*x(1)/25+2/25 , -1];
f = func(x);
J = zeros(n);
./community --outfile=graph-cmap.bin --textoutfile=graph-cmap.txt --outgraph=comm-graph-el.bin --min-degree=2 --max-degree=72 --max-num-comm=10 --max-comm-size=30 --scoring=mb --matching=greedy --nsteps=10 output-el.bin
./community --textoutfile=graph-cmap.txt --outgraph=comm-graph-el.bin --min-degree=1 --max-degree=72 --max-num-comm=6 --max-comm-size=1000 --scoring=mb --matching=greedy --nsteps=50 output-el.bin
@asw456
asw456 / T3.m
Created September 4, 2013 22:51
stupid matlab
%Calls comptrap, doubles n each time
n=1;
old=0;
a=0;
b=1;
i=0;
A=zeros(20,1);
B=zeros(20,1);
global r
# -*- coding: utf-8 -*-
#!/usr/bin/env python
import sys
class Polyomino(object):
def __init__(self, iterable):
self.squares = tuple(sorted(iterable))
def __repr__(self):
from numpy import *
from scipy.stats import beta
class BetaBandit(object):
def __init__(self, num_options=2, prior=(1.0,1.0)):
self.trials = zeros(shape=(num_options,), dtype=int)
self.successes = zeros(shape=(num_options,), dtype=int)
self.num_options = num_options
self.prior = prior