Skip to content

Instantly share code, notes, and snippets.

View jxnl's full-sized avatar

Jason Liu jxnl

View GitHub Profile
function [cmpImg] = svdCompress(img,k)
% Obtains SVD
[u,s,v] = svd(img);
% Vectorized sum of k rank one matrices
cmpImg = u(:,1:k)*s(1:k,1:k)*v’(1:k,:);
end;
@jxnl
jxnl / collect_combiner.ipynb
Last active October 3, 2016 15:56
Transformer for collecting values and generating features
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
function [Q,R]=BandQR(A, p)
[n,n]=size(A);
R=A; %Start with R=A
Q=eye(n); %Set Q as the identity matrix
for k=1:n-1
x = zeros(p+1,1);
j=min(n, k+p-1);
from chainer.links import caffe
func = caffe.CaffeFunction("../bvlc_alexnet.caffemodel")
# construct a correctly sized chainer variable
x = chainer.Variable(...)
# outputs is a list of layers to extract and it will return
# each layer seperatly
fc7, = func(inputs={"data":x}, outputs=["fc7"])
@jxnl
jxnl / ROC.r
Last active April 13, 2016 20:05
common snippet for ROC TESTS
library(pROC)
df = read.csv("...")
## 75% of the sample size
set.seed(123)
smp_size <- floor(0.75 * nrow(df))
train_ind <- sample(seq_len(nrow(df)), size = smp_size)
from __future__ import division
from tqdm import *
import chainer
from chainer import functions as F
from chainer import links as L
import numpy as np
@jxnl
jxnl / set.py
Last active March 8, 2016 19:44
generates 16 cards from the deck of SET and returns all possible winning hands.
from itertools import product
from itertools import permutations
from random import sample
cards = filter(
lambda _: all(
[
# look at all unique values of each property and see if there is 1 or 3
len(set([a[i][1] for a in _])) in {1,3} for i in range(4)
]
\usepackage{listings}
\usepackage[numbered,framed]{matlab-prettifier}
\usepackage{color}
\usepackage{geometry}
\geometry{verbose,tmargin=1.0in,bmargin=1.0in,lmargin=0.5in,rmargin=0.5in}
\definecolor{dkgreen}{rgb}{0,0.6,0}
\definecolor{gray}{rgb}{0.5,0.5,0.5}
\definecolor{mauve}{rgb}{0.58,0,0.82}
@jxnl
jxnl / LinearAlgebra.scala
Last active August 29, 2015 14:16
made the mistake of not defining row length in the template....
package learning
object LinearAlgebra {
class Row(r: Double*) extends Seq[Double] {
val row: List[Double] = r.toList
val length = row.length
def * (that: Row): Double = {
require(that.length == length, "Sizes don't align")